From 623d9a06e436b42b37c021c2a41c792cbe5642c9 Mon Sep 17 00:00:00 2001 From: Paul Montag Date: Mon, 20 Apr 2026 23:12:44 -0500 Subject: [PATCH] cleaned things up a bit --- src/game/nucleus.zig | 6 +---- src/game/rect.zig | 54 ++++++++++++-------------------------------- src/view/cell.zig | 11 +++++++++ 3 files changed, 26 insertions(+), 45 deletions(-) diff --git a/src/game/nucleus.zig b/src/game/nucleus.zig index c6c9f52..0c85664 100644 --- a/src/game/nucleus.zig +++ b/src/game/nucleus.zig @@ -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; } diff --git a/src/game/rect.zig b/src/game/rect.zig index 2961cf8..4fbb1b6 100644 --- a/src/game/rect.zig +++ b/src/game/rect.zig @@ -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); } }; diff --git a/src/view/cell.zig b/src/view/cell.zig index f84eeb6..34fe296 100644 --- a/src/view/cell.zig +++ b/src/view/cell.zig @@ -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);