Address review feedback for bigclock outline

Use braces, TerminalBuffer.Color.DEFAULT, x/y loop names, and
usize offsets via offsetBy instead of i32 screen math.
This commit is contained in:
jR4dh3y 2026-07-23 19:25:05 +05:30
commit 00f979f3f7

View file

@ -164,8 +164,9 @@ fn draw(self: *BigLabel) void {
const x = self.component_pos.x + i * (CHAR_WIDTH + 1);
const y = self.component_pos.y;
if (self.outline_fg) |outline_fg|
if (self.outline_fg) |outline_fg| {
drawDigitOutline(self, c, x, y, outline_fg);
}
alphaBlit(
x,
@ -185,41 +186,46 @@ fn drawDigitOutline(
outline_fg: u32,
) void {
const pattern = toBigNumber(char, self.locale);
const stroke = Cell.init(X, outline_fg, 0x00000000);
const stroke = Cell.init(X, outline_fg, TerminalBuffer.Color.DEFAULT);
for (0..CHAR_HEIGHT) |yy| {
for (0..CHAR_WIDTH) |xx| {
if (pattern[yy * CHAR_WIDTH + xx] == O) continue;
for (0..CHAR_HEIGHT) |y| {
for (0..CHAR_WIDTH) |x| {
if (pattern[y * CHAR_WIDTH + x] == O) continue;
for (OUTLINE_DIRS) |dir| {
const nx = @as(i32, @intCast(xx)) + dir[0];
const ny = @as(i32, @intCast(yy)) + dir[1];
if (offsetBy(x, dir[0])) |nx| {
if (offsetBy(y, dir[1])) |ny| {
if (nx < CHAR_WIDTH and ny < CHAR_HEIGHT and
pattern[ny * CHAR_WIDTH + nx] != O)
{
continue;
}
}
}
if (nx >= 0 and ny >= 0 and
nx < CHAR_WIDTH and ny < CHAR_HEIGHT and
pattern[
@as(usize, @intCast(ny)) * CHAR_WIDTH +
@as(usize, @intCast(nx))
] != O)
const sx = offsetBy(base_x + x, dir[0]) orelse continue;
const sy = offsetBy(base_y + y, dir[1]) orelse continue;
if (sx >= self.buffer.width or
sy >= self.buffer.height)
{
continue;
}
const sx = @as(i32, @intCast(base_x)) + nx;
const sy = @as(i32, @intCast(base_y)) + ny;
if (sx < 0 or sy < 0) continue;
const ux: usize = @intCast(sx);
const uy: usize = @intCast(sy);
if (ux >= self.buffer.width or uy >= self.buffer.height)
continue;
stroke.put(ux, uy) catch {};
stroke.put(sx, sy) catch {};
}
}
}
}
fn offsetBy(pos: usize, delta: i8) ?usize {
if (delta < 0) {
const sub: usize = @intCast(-delta);
if (pos < sub) return null;
return pos - sub;
}
return pos + @as(usize, @intCast(delta));
}
fn update(self: *BigLabel, context: *anyopaque) !void {
if (self.update_fn) |update_fn| {
return @call(