fix: menu and open_recent resize handling

This commit is contained in:
CJ van den Berg 2024-06-14 20:41:01 +02:00
parent 771c1dd980
commit acd65d0157
4 changed files with 9 additions and 15 deletions

View file

@ -36,7 +36,7 @@ pub fn Options(context: type) type {
pub fn on_resize_default(_: context, state: *State(Context), box_: Widget.Box) void {
var box = box_;
box.h = state.menu.widgets.items.len;
state.menu.handle_resize(box);
state.menu.resize(box);
}
};
}
@ -133,7 +133,7 @@ pub fn State(ctx_type: type) type {
}
pub fn resize(self: *Self, box: Widget.Box) void {
self.menu.handle_resize(box);
self.menu.resize(box);
}
pub fn update(self: *Self) void {

View file

@ -179,15 +179,15 @@ fn refresh_layout(self: *Self) void {
return if (self.box) |box| self.handle_resize(box);
}
pub fn resize(self: *Self, pos: Widget.Box) void {
return self.on_resize(self.ctx, self, pos);
pub fn handle_resize(self: *Self, pos: Widget.Box) void {
self.on_resize(self.ctx, self, pos);
}
fn on_resize_default(_: ?*anyopaque, self: *Self, pos: Widget.Box) void {
self.handle_resize(pos);
self.resize(pos);
}
pub fn handle_resize(self: *Self, pos_: Widget.Box) void {
pub fn resize(self: *Self, pos_: Widget.Box) void {
self.box = pos_;
var pos = pos_;
const total = self.get_size_a(&pos).*;

View file

@ -101,7 +101,7 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool {
}
pub fn handle_resize(self: *Self, pos: Box) void {
self.widgets.resize(pos);
self.widgets.handle_resize(pos);
self.floating_views.resize(pos);
}

View file

@ -103,14 +103,8 @@ fn render_cell(plane: *Plane, y: usize, x: usize, style: Widget.Theme.Style) !vo
_ = plane.putc(&cell) catch {};
}
fn on_resize_menu(self: *Self, state: *Menu.State(*Self), box: Widget.Box) void {
const w = @min(box.w, @min(self.longest, max_menu_width) + 2);
self.menu.resize(.{
.y = 0,
.x = box.w - w / 2,
.h = state.menu.widgets.items.len,
.w = w,
});
fn on_resize_menu(self: *Self, _: *Menu.State(*Self), _: Widget.Box) void {
self.menu.resize(.{ .y = 0, .x = 25, .w = @min(self.longest, max_menu_width) + 2 });
}
fn menu_action_open_file(menu: **Menu.State(*Self), button: *Button.State(*Menu.State(*Self))) void {