feat: auto hide bars with empty widget layouts

This commit is contained in:
CJ van den Berg 2025-08-03 16:17:05 +02:00
parent ce204d650a
commit dfcc825e4b
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -12,6 +12,7 @@ pub fn create(allocator: std.mem.Allocator, parent: Plane, config: []const u8, s
var w = try WidgetList.createH(allocator, parent, "statusbar", .{ .static = 1 });
if (style == .grip) w.after_render = render_grip;
w.ctx = w;
w.on_layout = on_layout;
var it = std.mem.splitScalar(u8, config, ' ');
while (it.next()) |widget_name| {
try w.add(status_widget.create(widget_name, allocator, w.plane, event_handler) catch |e| switch (e) {
@ -22,6 +23,13 @@ pub fn create(allocator: std.mem.Allocator, parent: Plane, config: []const u8, s
return w.widget();
}
fn on_layout(_: ?*anyopaque, w: *WidgetList) Widget.Layout {
return if (w.layout_empty)
.{ .static = 0 }
else
.{ .static = 1 };
}
fn render_grip(ctx: ?*anyopaque, theme: *const Widget.Theme) void {
const w: *WidgetList = @ptrCast(@alignCast(ctx.?));
if (w.hover()) {