feat: select widget styles based on widget type

This commit is contained in:
CJ van den Berg 2025-08-13 12:58:05 +02:00
parent fbc49c3dab
commit bcfd17a0e2
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
7 changed files with 81 additions and 37 deletions

View file

@ -36,6 +36,7 @@ selected: ?usize = null,
box: Widget.Box = .{},
const path_column_ratio = 4;
const widget_style_type: Widget.Style.Type = .panel;
const Entry = struct {
path: []const u8,
@ -57,6 +58,7 @@ pub fn create(allocator: Allocator, parent: Plane) !Widget {
.entries = std.ArrayList(Entry).init(allocator),
.menu = try Menu.create(*Self, allocator, tui.plane(), .{
.ctx = self,
.style = widget_style_type,
.on_render = handle_render_menu,
.on_scroll = EventHandler.bind(self, Self.handle_scroll),
.on_click4 = mouse_click_button4,
@ -85,11 +87,12 @@ fn scrollbar_style(sb: *scrollbar_v, theme: *const Widget.Theme) Widget.Theme.St
}
pub fn handle_resize(self: *Self, pos: Widget.Box) void {
const padding = Widget.Style.from_type(widget_style_type).padding;
self.plane.move_yx(@intCast(pos.y), @intCast(pos.x)) catch return;
self.plane.resize_simple(@intCast(pos.h), @intCast(pos.w)) catch return;
self.box = pos;
self.menu.container.resize(self.box);
const client_box = self.menu.container.to_client_box(pos);
const client_box = self.menu.container.to_client_box(pos, padding);
self.view_rows = client_box.h;
self.view_cols = client_box.w;
self.update_scrollbar();