cleaned things up a bit
This commit is contained in:
@@ -51,11 +51,7 @@ pub const Nucleus = struct {
|
||||
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],
|
||||
},
|
||||
.init("Ω", healthy_loop[(self.style_loop_ctr / 20) % healthy_loop.len]),
|
||||
) catch return WidgetError.UnknownError;
|
||||
self.style_loop_ctr += 1;
|
||||
}
|
||||
|
||||
+14
-40
@@ -40,51 +40,25 @@ pub const Rectangle = struct {
|
||||
const size = frame.size();
|
||||
|
||||
var first = frame.rowable.row(0) catch return WidgetError.UnknownError;
|
||||
first[0] = Cell{
|
||||
.char = ("┌ " ** 2).*,
|
||||
.style = self.style,
|
||||
.width = 3,
|
||||
};
|
||||
@memset(first[1 .. first.len - 1], Cell{
|
||||
.char = ("─ " ** 2).*,
|
||||
.style = self.style,
|
||||
.width = 3,
|
||||
});
|
||||
first[first.len - 1] = Cell{
|
||||
.char = ("┐ " ** 2).*,
|
||||
.style = self.style,
|
||||
.width = 3,
|
||||
};
|
||||
first[0] = .init("┌", self.style);
|
||||
@memset(
|
||||
first[1 .. first.len - 1],
|
||||
.init("─", self.style),
|
||||
);
|
||||
first[first.len - 1] = .init("┐", self.style);
|
||||
|
||||
for (1..size.height - 1) |row_num| {
|
||||
var row = frame.rowable.row(row_num) catch return WidgetError.UnknownError;
|
||||
row[0] = Cell{
|
||||
.char = ("│ " ** 2).*,
|
||||
.style = self.style,
|
||||
.width = 3,
|
||||
};
|
||||
row[row.len - 1] = Cell{
|
||||
.char = ("│ " ** 2).*,
|
||||
.style = self.style,
|
||||
.width = 3,
|
||||
};
|
||||
row[0] = .init("│", self.style);
|
||||
row[row.len - 1] = .init("│", self.style);
|
||||
}
|
||||
|
||||
var last = frame.rowable.row(size.height - 1) catch return WidgetError.UnknownError;
|
||||
last[0] = Cell{
|
||||
.char = ("└ " ** 2).*,
|
||||
.style = self.style,
|
||||
.width = 3,
|
||||
};
|
||||
@memset(last[1 .. last.len - 1], Cell{
|
||||
.char = ("─ " ** 2).*,
|
||||
.style = self.style,
|
||||
.width = 3,
|
||||
});
|
||||
last[last.len - 1] = Cell{
|
||||
.char = ("┘ " ** 2).*,
|
||||
.style = self.style,
|
||||
.width = 3,
|
||||
};
|
||||
last[0] = .init("└", self.style);
|
||||
@memset(
|
||||
last[1 .. last.len - 1],
|
||||
.init("─", self.style),
|
||||
);
|
||||
last[last.len - 1] = .init("┘", self.style);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -12,6 +12,17 @@ pub const Cell = struct {
|
||||
width: usize,
|
||||
style: ?Style,
|
||||
|
||||
pub fn init(comptime char: []const u8, s: ?Style) Cell {
|
||||
var tmp_char: [8]u8 = undefined;
|
||||
@memcpy(tmp_char[0..char.len], char);
|
||||
|
||||
return .{
|
||||
.char = tmp_char,
|
||||
.width = char.len,
|
||||
.style = s,
|
||||
};
|
||||
}
|
||||
|
||||
/// eql returns
|
||||
pub fn eql(self: *const Cell, b: *const Cell) bool {
|
||||
return mem.eql(u8, &self.char, &b.char) and self.width == b.width and (self.style orelse style.Empty).eql(b.style orelse style.Empty);
|
||||
|
||||
Reference in New Issue
Block a user