fix: propagate configured frame rate to widgets

This commit is contained in:
CJ van den Berg 2024-10-20 21:33:01 +02:00
parent 87addc97de
commit 03cdcd260e
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 3 additions and 4 deletions

View file

@ -323,8 +323,7 @@ pub const Editor = struct {
fn init(self: *Self, allocator: Allocator, n: Plane) void { fn init(self: *Self, allocator: Allocator, n: Plane) void {
const logger = log.logger("editor"); const logger = log.logger("editor");
var frame_rate = tp.env.get().num("frame-rate"); const frame_rate = tp.env.get().num("frame-rate");
if (frame_rate == 0) frame_rate = 60;
const indent_size = tui.current().config.indent_size; const indent_size = tui.current().config.indent_size;
const tab_width = tui.current().config.tab_width; const tab_width = tui.current().config.tab_width;
self.* = Self{ self.* = Self{

View file

@ -32,8 +32,7 @@ const idle_msg = "🐶";
pub const width = idle_msg.len + 20; pub const width = idle_msg.len + 20;
pub fn create(allocator: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { pub fn create(allocator: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
var frame_rate = tp.env.get().num("frame-rate"); const frame_rate = tp.env.get().num("frame-rate");
if (frame_rate == 0) frame_rate = 60;
const self: *Self = try allocator.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent), .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),

View file

@ -89,6 +89,7 @@ fn init(allocator: Allocator) !*Self {
const frame_rate: usize = @intCast(tp.env.get().num("frame-rate")); const frame_rate: usize = @intCast(tp.env.get().num("frame-rate"));
if (frame_rate != 0) if (frame_rate != 0)
conf.frame_rate = frame_rate; conf.frame_rate = frame_rate;
tp.env.get().num_set("frame-rate", @intCast(conf.frame_rate));
const frame_time = std.time.us_per_s / conf.frame_rate; const frame_time = std.time.us_per_s / conf.frame_rate;
const frame_clock = try tp.metronome.init(frame_time); const frame_clock = try tp.metronome.init(frame_time);