63 lines
1.7 KiB
Zig
63 lines
1.7 KiB
Zig
const std = @import("std");
|
|
const grome = @import("../root.zig");
|
|
const style = grome.view.style;
|
|
|
|
const Point = grome.container.Point;
|
|
const Block = grome.container.Block;
|
|
const SubMatrix = grome.container.SubMatrix;
|
|
const Widget = grome.view.Widget;
|
|
const WidgetError = grome.view.WidgetError;
|
|
const Cell = grome.view.Cell;
|
|
const Style = grome.view.style.Style;
|
|
|
|
pub const Nucleus = struct {
|
|
location: Point,
|
|
style_loop_ctr: usize,
|
|
widget: Widget,
|
|
|
|
const healthy_loop = [_]Style{
|
|
style.rgb(95, 133, 99),
|
|
style.rgb(95, 129, 78),
|
|
style.rgb(94, 121, 66),
|
|
style.rgb(93, 115, 45),
|
|
style.rgb(93, 110, 34),
|
|
style.rgb(93, 115, 45),
|
|
style.rgb(94, 121, 66),
|
|
style.rgb(95, 129, 78),
|
|
style.rgb(95, 133, 99),
|
|
};
|
|
|
|
pub fn init(loc: Point) Nucleus {
|
|
return .{
|
|
.location = loc,
|
|
.style_loop_ctr = 0,
|
|
.widget = .{
|
|
.geometryFn = Nucleus.geometry,
|
|
.renderFn = Nucleus.render,
|
|
},
|
|
};
|
|
}
|
|
|
|
pub fn geometry(widget: *Widget) Block {
|
|
const self: *@This() = @fieldParentPtr("widget", widget);
|
|
|
|
return Block{
|
|
.loc = self.location,
|
|
.size = .{ .height = 1, .width = 1 },
|
|
};
|
|
}
|
|
|
|
pub fn render(widget: *Widget, frame: *SubMatrix(Cell)) WidgetError!void {
|
|
const self: *@This() = @fieldParentPtr("widget", widget);
|
|
frame.set(
|
|
.{ .x = 0, .y = 0 },
|
|
.{
|
|
.char = ("Ω" ** 4).*,
|
|
.width = 2,
|
|
.style = healthy_loop[(self.style_loop_ctr / 5) % healthy_loop.len],
|
|
},
|
|
) catch return WidgetError.UnknownError;
|
|
self.style_loop_ctr += 1;
|
|
}
|
|
};
|