feat: tie ModalBackground fade time to animation_max_lag config option
This commit is contained in:
parent
03cdcd260e
commit
6d9dd2a899
1 changed files with 10 additions and 4 deletions
|
@ -24,7 +24,6 @@ pub fn Options(context: type) type {
|
||||||
on_layout: *const fn (ctx: context) Widget.Layout = on_layout_default,
|
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,
|
on_resize: *const fn (ctx: context, state: *State(Context), box: Widget.Box) void = on_resize_default,
|
||||||
|
|
||||||
|
|
||||||
pub const Context = context;
|
pub const Context = context;
|
||||||
pub fn do_nothing(_: context, _: *State(Context)) void {}
|
pub fn do_nothing(_: context, _: *State(Context)) void {}
|
||||||
|
|
||||||
|
@ -37,12 +36,15 @@ pub fn Options(context: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_render_dim(_: context, self: *State(Context), _: *const Widget.Theme) bool {
|
pub fn on_render_dim(_: context, self: *State(Context), _: *const Widget.Theme) bool {
|
||||||
|
const frame_time_ms = @divTrunc(1000, self.frame_rate);
|
||||||
|
const fade_steps = self.fade_time_ms / frame_time_ms;
|
||||||
|
const step_size: u8 = @intCast((255 - self.opts.dim_target) / fade_steps);
|
||||||
const height = self.plane.dim_y();
|
const height = self.plane.dim_y();
|
||||||
const width = self.plane.dim_x();
|
const width = self.plane.dim_x();
|
||||||
for (0..height) |y| for (0..width) |x|
|
for (0..height) |y| for (0..width) |x|
|
||||||
dim_cell(&self.plane, y, x, self.opts.dim) catch {};
|
dim_cell(&self.plane, y, x, self.opts.dim) catch {};
|
||||||
if (self.opts.dim > self.opts.dim_target) {
|
if (self.opts.dim > self.opts.dim_target) {
|
||||||
self.opts.dim -= 1;
|
self.opts.dim -= step_size;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -62,6 +64,8 @@ pub fn create(ctx_type: type, allocator: std.mem.Allocator, parent: Widget, opts
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.plane = parent.plane.*,
|
.plane = parent.plane.*,
|
||||||
.opts = opts,
|
.opts = opts,
|
||||||
|
.fade_time_ms = tui.current().config.animation_max_lag,
|
||||||
|
.frame_rate = @intCast(tp.env.get().num("frame-rate")),
|
||||||
};
|
};
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +75,8 @@ pub fn State(ctx_type: type) type {
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
plane: Plane,
|
plane: Plane,
|
||||||
opts: options_type,
|
opts: options_type,
|
||||||
|
fade_time_ms: usize,
|
||||||
|
frame_rate: usize,
|
||||||
hover: bool = false,
|
hover: bool = false,
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
Loading…
Add table
Reference in a new issue