refactor: scroll keybinding hints
This commit is contained in:
parent
3012fdcd90
commit
dad8deac7a
1 changed files with 14 additions and 3 deletions
|
|
@ -55,7 +55,12 @@ fn render(bindings: []const keybind.Binding, theme: *const Widget.Theme, mode: R
|
||||||
const scr = tui.screen();
|
const scr = tui.screen();
|
||||||
const max_screen_height = scr.h -| widget_style.padding.top -| widget_style.padding.bottom -| 1;
|
const max_screen_height = scr.h -| widget_style.padding.top -| widget_style.padding.bottom -| 1;
|
||||||
const max_items = @min(bindings.len, max_screen_height);
|
const max_items = @min(bindings.len, max_screen_height);
|
||||||
|
const page_size = max_screen_height;
|
||||||
|
var top = show_page * page_size;
|
||||||
|
if (top >= bindings.len) {
|
||||||
|
top = 0;
|
||||||
|
show_page = 0;
|
||||||
|
}
|
||||||
var box: Widget.Box = .{
|
var box: Widget.Box = .{
|
||||||
.h = max_items,
|
.h = max_items,
|
||||||
.w = max_len,
|
.w = max_len,
|
||||||
|
|
@ -67,6 +72,12 @@ fn render(bindings: []const keybind.Binding, theme: *const Widget.Theme, mode: R
|
||||||
const top_layer_ = tui.top_layer(deco_box.to_layer()) orelse return;
|
const top_layer_ = tui.top_layer(deco_box.to_layer()) orelse return;
|
||||||
widget_style.render_decoration(deco_box, widget_type, top_layer_, theme);
|
widget_style.render_decoration(deco_box, widget_type, top_layer_, theme);
|
||||||
|
|
||||||
|
if (bindings.len > max_items) {
|
||||||
|
top_layer_.cursor_move_yx(@intCast(top_layer_.window.height -| 1), @intCast(4)) catch return;
|
||||||
|
_ = top_layer_.print("[{d}/{d}](C-A-? for more)", .{ top, bindings.len }) catch {};
|
||||||
|
top_layer_.cursor_move_yx(@intCast(top_layer_.window.height -| 1), @intCast(max_len - 5)) catch return;
|
||||||
|
}
|
||||||
|
|
||||||
// workaround vaxis.Layer issue
|
// workaround vaxis.Layer issue
|
||||||
const top_layer_window = top_layer_.window;
|
const top_layer_window = top_layer_.window;
|
||||||
defer {
|
defer {
|
||||||
|
|
@ -93,7 +104,7 @@ fn render(bindings: []const keybind.Binding, theme: *const Widget.Theme, mode: R
|
||||||
plane.home();
|
plane.home();
|
||||||
plane.set_style(style_hint);
|
plane.set_style(style_hint);
|
||||||
|
|
||||||
for (bindings, 0..) |binding, y| {
|
for (bindings[top..], 0..) |binding, y| {
|
||||||
if (y >= max_items) break;
|
if (y >= max_items) break;
|
||||||
var keybind_buf: [256]u8 = undefined;
|
var keybind_buf: [256]u8 = undefined;
|
||||||
const keybind_txt = blk: {
|
const keybind_txt = blk: {
|
||||||
|
|
@ -107,7 +118,7 @@ fn render(bindings: []const keybind.Binding, theme: *const Widget.Theme, mode: R
|
||||||
|
|
||||||
plane.set_style(style_label);
|
plane.set_style(style_label);
|
||||||
|
|
||||||
for (bindings, 0..) |binding, y| {
|
for (bindings[top..], 0..) |binding, y| {
|
||||||
if (y >= max_items) break;
|
if (y >= max_items) break;
|
||||||
const padding = max_prefix_len + 2;
|
const padding = max_prefix_len + 2;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue