diff --git a/src/renderer/vaxis/Cell.zig b/src/renderer/vaxis/Cell.zig index e6b4e12..b35d58b 100644 --- a/src/renderer/vaxis/Cell.zig +++ b/src/renderer/vaxis/Cell.zig @@ -53,3 +53,16 @@ pub fn columns(self: *const Cell) usize { // return if (self.cell.char.width == 0) self.window.gwidth(self.cell.char.grapheme) else self.cell.char.width; // FIXME? return self.cell.char.width; } + +pub fn dim(self: *Cell, alpha: u8) void { + self.cell.style.fg = apply_alpha_value(self.cell.style.fg, alpha); + self.cell.style.bg = apply_alpha_value(self.cell.style.bg, alpha); +} + +fn apply_alpha_value(c: vaxis.Cell.Color, a: u8) vaxis.Cell.Color { + var rgb = c.rgb; + rgb[0] = @intCast((@as(u32, @intCast(rgb[0])) * a) / 256); + rgb[1] = @intCast((@as(u32, @intCast(rgb[1])) * a) / 256); + rgb[2] = @intCast((@as(u32, @intCast(rgb[2])) * a) / 256); + return .{ .rgb = rgb }; +} diff --git a/src/tui/ModalBackground.zig b/src/tui/ModalBackground.zig index d698593..5e63e16 100644 --- a/src/tui/ModalBackground.zig +++ b/src/tui/ModalBackground.zig @@ -17,7 +17,7 @@ pub fn Options(context: type) type { on_click3: *const fn (ctx: context, self: *State(Context)) void = do_nothing, on_click4: *const fn (ctx: context, self: *State(Context)) void = do_nothing, on_click5: *const fn (ctx: context, self: *State(Context)) void = do_nothing, - on_render: *const fn (ctx: context, self: *State(Context), theme: *const Widget.Theme) bool = on_render_default, + on_render: *const fn (ctx: context, self: *State(Context), theme: *const Widget.Theme) bool = on_render_dim, on_layout: *const fn (ctx: context) Widget.Layout = on_layout_default, on_resize: *const fn (ctx: context, state: *State(Context), box: Widget.Box) void = on_resize_default, @@ -32,6 +32,14 @@ pub fn Options(context: type) type { return false; } + pub fn on_render_dim(_: context, self: *State(Context), _: *const Widget.Theme) bool { + const height = self.plane.dim_y(); + const width = self.plane.dim_x(); + for (0..height) |y| for (0..width) |x| + dim_cell(&self.plane, y, x) catch {}; + return false; + } + pub fn on_layout_default(_: context) Widget.Layout { return .dynamic; } @@ -85,7 +93,7 @@ pub fn State(ctx_type: type) type { self.call_click_handler(btn); return true; } else if (try m.match(.{ "H", tp.extract(&self.hover) })) { - tui.current().rdr.request_mouse_cursor_pointer(self.hover); + tui.current().rdr.request_mouse_cursor_default(self.hover); return true; } return false; @@ -104,3 +112,11 @@ pub fn State(ctx_type: type) type { } }; } + +fn dim_cell(plane: *Plane, y: usize, x: usize) !void { + plane.cursor_move_yx(@intCast(y), @intCast(x)) catch return; + var cell = plane.cell_init(); + _ = plane.at_cursor_cell(&cell) catch return; + cell.dim(256 - 32); + _ = plane.putc(&cell) catch {}; +}