refactor: unify list pointer rendering
This commit is contained in:
parent
c50ab782ec
commit
4d2c7d8a8c
7 changed files with 18 additions and 17 deletions
|
@ -166,8 +166,8 @@ fn handle_render_menu(self: *Self, button: *Button.State(*Menu.State(*Self)), th
|
|||
button.plane.home();
|
||||
}
|
||||
const entry = &self.entries.items[idx];
|
||||
const pointer = if (selected) "⏵" else " ";
|
||||
_ = button.plane.print("{s} ", .{pointer}) catch {};
|
||||
button.plane.set_style(style_label);
|
||||
tui.render_pointer(&button.plane, selected);
|
||||
var buf: [std.fs.max_path_bytes]u8 = undefined;
|
||||
var removed_prefix: usize = 0;
|
||||
const max_len = self.view_cols / path_column_ratio;
|
||||
|
|
|
@ -154,7 +154,7 @@ fn add_menu_command(self: *Self, command_name: []const u8, description: []const
|
|||
try writer.print(" :{s}", .{hint});
|
||||
const label = fis.getWritten();
|
||||
const padding = Widget.Style.from_type(widget_style_type).padding;
|
||||
self.menu_w = @max(self.menu_w, label.len + 1 + padding.left + padding.right);
|
||||
self.menu_w = @max(self.menu_w, label.len + 2 + padding.left + padding.right);
|
||||
}
|
||||
|
||||
var value = std.ArrayList(u8).init(self.allocator);
|
||||
|
@ -237,8 +237,8 @@ fn menu_on_render(self: *Self, button: *Button.State(*Menu.State(*Self)), theme:
|
|||
} else {
|
||||
button.plane.set_style_bg_transparent(style_text);
|
||||
}
|
||||
const pointer = if (selected) "⏵" else " ";
|
||||
_ = button.plane.print("{s}{s}", .{ pointer, description }) catch {};
|
||||
tui.render_pointer(&button.plane, selected);
|
||||
_ = button.plane.print("{s}", .{description}) catch {};
|
||||
if (button.active or button.hover or selected) {
|
||||
button.plane.set_style(style_leader);
|
||||
} else {
|
||||
|
|
|
@ -84,8 +84,7 @@ pub fn Variant(comptime command: []const u8, comptime label_: []const u8, allow_
|
|||
}
|
||||
|
||||
button.plane.set_style(style_hint);
|
||||
const pointer = if (selected) "⏵" else " ";
|
||||
_ = button.plane.print("{s}", .{pointer}) catch {};
|
||||
tui.render_pointer(&button.plane, selected);
|
||||
|
||||
var iter = button.opts.label;
|
||||
var description_: []const u8 = undefined;
|
||||
|
|
|
@ -88,7 +88,7 @@ pub fn deinit(self: *Self) void {
|
|||
}
|
||||
|
||||
inline fn menu_width(self: *Self) usize {
|
||||
return @max(@min(self.longest + 1, max_menu_width()) + 5, inputbox_label.len + 2);
|
||||
return @max(@min(self.longest + 3, max_menu_width()) + 5, inputbox_label.len + 2);
|
||||
}
|
||||
|
||||
inline fn menu_pos_x(self: *Self) usize {
|
||||
|
|
|
@ -133,8 +133,7 @@ pub fn Create(options: type) type {
|
|||
if (!(cbor.matchString(&iter, &hint) catch false))
|
||||
hint = "";
|
||||
button.plane.set_style(style_hint);
|
||||
const pointer = if (selected) "⏵" else " ";
|
||||
_ = button.plane.print("{s}", .{pointer}) catch {};
|
||||
tui.render_pointer(&button.plane, selected);
|
||||
button.plane.set_style(style_label);
|
||||
_ = button.plane.print("{s} ", .{label}) catch {};
|
||||
button.plane.set_style(style_hint);
|
||||
|
@ -143,7 +142,7 @@ pub fn Create(options: type) type {
|
|||
var len = cbor.decodeArrayHeader(&iter) catch return false;
|
||||
while (len > 0) : (len -= 1) {
|
||||
if (cbor.matchValue(&iter, cbor.extract(&index)) catch break) {
|
||||
tui.render_match_cell(&button.plane, 0, index + 1, theme) catch break;
|
||||
tui.render_match_cell(&button.plane, 0, index + 2, theme) catch break;
|
||||
} else break;
|
||||
}
|
||||
return false;
|
||||
|
@ -155,7 +154,7 @@ pub fn Create(options: type) type {
|
|||
|
||||
fn prepare_resize(self: *Self) Widget.Box {
|
||||
const screen = tui.screen();
|
||||
const w = @max(@min(self.longest, max_menu_width) + 2 + 1 + self.longest_hint, options.label.len + 2);
|
||||
const w = @max(@min(self.longest + 3, max_menu_width) + 2 + self.longest_hint, options.label.len + 2);
|
||||
const x = if (screen.w > w) (screen.w - w) / 2 else 0;
|
||||
self.view_rows = get_view_rows(screen);
|
||||
const h = @min(self.items + self.menu.header_count, self.view_rows + self.menu.header_count);
|
||||
|
|
|
@ -85,8 +85,7 @@ pub fn on_render_menu(_: *Type, button: *Type.ButtonState, theme: *const Widget.
|
|||
button.plane.fill(" ");
|
||||
button.plane.home();
|
||||
button.plane.set_style(style_hint);
|
||||
const pointer = if (selected) "⏵" else " ";
|
||||
_ = button.plane.print("{s}", .{pointer}) catch {};
|
||||
tui.render_pointer(&button.plane, selected);
|
||||
button.plane.set_style(style_label);
|
||||
_ = button.plane.print("{s} ", .{entry.label}) catch {};
|
||||
var index: usize = 0;
|
||||
|
|
|
@ -1460,6 +1460,11 @@ pub fn render_match_cell(self: *renderer.Plane, y: usize, x: usize, theme_: *con
|
|||
_ = self.putc(&cell) catch {};
|
||||
}
|
||||
|
||||
pub fn render_pointer(self: *renderer.Plane, selected: bool) void {
|
||||
const pointer = if (selected) "⏵ " else " ";
|
||||
_ = self.print("{s}", .{pointer}) catch {};
|
||||
}
|
||||
|
||||
pub fn render_file_item_cbor(self: *renderer.Plane, file_item_cbor: []const u8, active: bool, selected: bool, hover: bool, theme_: *const Widget.Theme) bool {
|
||||
const style_base = theme_.editor_widget;
|
||||
const style_label = if (active) theme_.editor_cursor else if (hover or selected) theme_.editor_selection else theme_.editor_widget;
|
||||
|
@ -1474,8 +1479,7 @@ pub fn render_file_item_cbor(self: *renderer.Plane, file_item_cbor: []const u8,
|
|||
}
|
||||
|
||||
self.set_style(style_hint);
|
||||
const pointer = if (selected) "⏵" else " ";
|
||||
_ = self.print("{s}", .{pointer}) catch {};
|
||||
render_pointer(self, selected);
|
||||
|
||||
var iter = file_item_cbor;
|
||||
var file_path_: []const u8 = undefined;
|
||||
|
@ -1500,7 +1504,7 @@ pub fn render_file_item_cbor(self: *renderer.Plane, file_item_cbor: []const u8,
|
|||
var len = cbor.decodeArrayHeader(&iter) catch return false;
|
||||
while (len > 0) : (len -= 1) {
|
||||
if (cbor.matchValue(&iter, cbor.extract(&index)) catch break) {
|
||||
render_match_cell(self, 0, index + 4, theme_) catch break;
|
||||
render_match_cell(self, 0, index + 5, theme_) catch break;
|
||||
} else break;
|
||||
}
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue