From 37bbb17da628f9c4e47e3c6b2590fcf3cc6201bb Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sun, 12 Apr 2026 22:22:53 +0200 Subject: [PATCH] feat: add palette_placement config option --- src/config.zig | 9 +++++++++ src/tui/mode/overlay/open_recent.zig | 30 ++++++++++++++++++++++++++-- src/tui/mode/overlay/palette.zig | 24 +++++++++++++++++++++- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/config.zig b/src/config.zig index a6a62967..26a8ce73 100644 --- a/src/config.zig +++ b/src/config.zig @@ -85,6 +85,8 @@ hint_window_style: WidgetStyle = .thick_boxed, info_box_style: WidgetStyle = .bar_left_spacious, info_box_width_limit: usize = 80, +palette_placement: PalettePlacement = .top_center, + centered_view: bool = false, centered_view_width: usize = 145, centered_view_min_screen_width: usize = 145, @@ -248,3 +250,10 @@ pub const AgeFormat = enum { short, long, }; + +pub const PalettePlacement = enum { + top_center, + top_left, + top_right, + center, +}; diff --git a/src/tui/mode/overlay/open_recent.zig b/src/tui/mode/overlay/open_recent.zig index c419917e..df1ad82c 100644 --- a/src/tui/mode/overlay/open_recent.zig +++ b/src/tui/mode/overlay/open_recent.zig @@ -187,10 +187,36 @@ fn prepare_resize_menu(self: *Self, _: *MenuType, _: Widget.Box) Widget.Box { } fn prepare_resize(self: *Self) Widget.Box { + const screen = tui.screen(); + const padding = tui.get_widget_style(widget_type).padding; const w = self.menu_width(); - const x = self.menu_pos_x(); const h = self.menu.menu.widgets.items.len; - return .{ .y = 0, .x = x, .w = w, .h = h }; + return switch (tui.config().palette_placement) { + .top_center => .{ + .y = 0, + .x = self.menu_pos_x(), + .w = w, + .h = h, + }, + .top_left => .{ + .y = 0, + .x = 0, + .w = w, + .h = h, + }, + .top_right => .{ + .y = 0, + .x = if (screen.w > (w - padding.right)) (screen.w - w - padding.right) else 0, + .w = w, + .h = h, + }, + .center => .{ + .y = if (screen.h > h) (screen.h - h) / 2 else 0, + .x = self.menu_pos_x(), + .w = w, + .h = h, + }, + }; } fn do_resize(self: *Self) void { diff --git a/src/tui/mode/overlay/palette.zig b/src/tui/mode/overlay/palette.zig index 74764a5d..57ad8b5c 100644 --- a/src/tui/mode/overlay/palette.zig +++ b/src/tui/mode/overlay/palette.zig @@ -26,7 +26,17 @@ pub const Placement = enum { top_center, top_left, top_right, + center, primary_cursor, + + fn from_config(conf: @import("config").PalettePlacement) Placement { + return switch (conf) { + .top_center => .top_center, + .top_left => .top_left, + .top_right => .top_right, + .center => .center, + }; + } }; pub const ActivateMode = enum { @@ -110,7 +120,10 @@ pub fn Create(options: type) type { .mode = try keybind.mode("overlay/palette", allocator, .{ .insert_command = "overlay_insert_bytes", }), - .placement = if (@hasDecl(options, "placement")) options.placement else .top_center, + .placement = if (@hasDecl(options, "placement")) + options.placement + else + Placement.from_config(tui.config().palette_placement), }; try self.commands.init(self); self.mode.event_handler = EventHandler.to_owned(self); @@ -204,6 +217,7 @@ pub fn Create(options: type) type { .top_center => self.prepare_resize_top_center(screen, w), .top_left => self.prepare_resize_top_left(screen, w), .top_right => self.prepare_resize_top_right(screen, w, padding), + .center => self.prepare_resize_center(screen, w), .primary_cursor => self.prepare_resize_primary_cursor(screen, w, padding), }; } @@ -248,6 +262,14 @@ pub fn Create(options: type) type { return self.prepare_resize_at_y_x(screen, w, cursor.row + 1 + padding.top, cursor.col); } + fn prepare_resize_center(self: *Self, screen: Widget.Box, w: usize) Widget.Box { + const x = if (screen.w > w) (screen.w - w) / 2 else 0; + const h = @min(self.items + self.menu.header_count, self.view_rows + self.menu.header_count); + const y = if (screen.h > h) (screen.h - h) / 2 else 0; + self.view_rows = get_view_rows(screen) -| y; + return .{ .y = y, .x = x, .w = w, .h = h }; + } + fn after_resize_menu(self: *Self, _: *Menu.State(*Self), _: Widget.Box) void { return self.after_resize(); }