feat: fade out modal background

This commit is contained in:
CJ van den Berg 2024-10-20 00:23:54 +02:00
parent 5a1e6e3e44
commit f8084bd9ab
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -12,6 +12,9 @@ pub fn Options(context: type) type {
return struct {
ctx: Context,
dim: u8 = 255,
dim_target: u8 = 128,
on_click: *const fn (ctx: context, self: *State(Context)) void = on_click_exit_overlay_mode,
on_click2: *const fn (ctx: context, self: *State(Context)) void = do_nothing,
on_click3: *const fn (ctx: context, self: *State(Context)) void = do_nothing,
@ -21,6 +24,7 @@ pub fn Options(context: type) type {
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,
pub const Context = context;
pub fn do_nothing(_: context, _: *State(Context)) void {}
@ -36,7 +40,11 @@ pub fn Options(context: type) type {
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 {};
dim_cell(&self.plane, y, x, self.opts.dim) catch {};
if (self.opts.dim > self.opts.dim_target) {
self.opts.dim -= 1;
return true;
}
return false;
}
@ -113,10 +121,10 @@ pub fn State(ctx_type: type) type {
};
}
fn dim_cell(plane: *Plane, y: usize, x: usize) !void {
fn dim_cell(plane: *Plane, y: usize, x: usize, dim_target: u8) !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);
cell.dim(dim_target);
_ = plane.putc(&cell) catch {};
}