refactor: merge expander and spacer status bar widgets

This commit is contained in:
CJ van den Berg 2024-08-26 20:53:07 +02:00
parent 0b42308321
commit fa5da6e6d9
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 20 additions and 56 deletions

View file

@ -2,7 +2,7 @@ const std = @import("std");
const Widget = @import("../Widget.zig");
const Plane = @import("renderer").Plane;
const widgets = std.static_string_map.StaticStringMap(create_fn).initComptime(.{
const widgets = std.static_string_map.StaticStringMap(CreateFunction).initComptime(.{
.{ "mode", @import("modestate.zig").create },
.{ "file", @import("filestate.zig").create },
.{ "log", @import("minilog.zig").create },
@ -11,11 +11,12 @@ const widgets = std.static_string_map.StaticStringMap(create_fn).initComptime(.{
.{ "linenumber", @import("linenumstate.zig").create },
.{ "modifiers", @import("modstate.zig").create },
.{ "keystate", @import("keystate.zig").create },
.{ "expander", @import("expander.zig").create },
.{ "spacer", @import("spacer.zig").create },
.{ "expander", @import("blank.zig").Create(.dynamic) },
.{ "spacer", @import("blank.zig").Create(.{ .static = 1 }) },
.{ "clock", @import("clock.zig").create },
});
pub const CreateError = error{ OutOfMemory, Exit };
const create_fn = *const fn (a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget;
pub const CreateFunction = *const fn (a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget;
pub fn create(name: []const u8, a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!?Widget {
const create_ = widgets.get(name) orelse return null;