fix: hover and select menu styles on home screen

This commit is contained in:
CJ van den Berg 2024-05-18 17:02:45 +02:00
parent 855c11292e
commit c32e2005b9
2 changed files with 14 additions and 5 deletions

View file

@ -286,7 +286,7 @@ pub inline fn set_base_style(self: *Plane, _: [*c]const u8, style_: Style) void
pub fn set_base_style_transparent(self: *Plane, _: [*:0]const u8, style_: Style) void { pub fn set_base_style_transparent(self: *Plane, _: [*:0]const u8, style_: Style) void {
self.style_base.fg = if (style_.fg) |color| vaxis.Cell.Color.rgbFromUint(@intCast(color)) else .default; self.style_base.fg = if (style_.fg) |color| vaxis.Cell.Color.rgbFromUint(@intCast(color)) else .default;
self.style.bg = .default; self.style_base.bg = if (style_.bg) |color| vaxis.Cell.Color.rgbFromUint(@intCast(color)) else .default;
if (style_.fs) |fs| set_font_style(&self.style, fs); if (style_.fs) |fs| set_font_style(&self.style, fs);
self.set_style(style_); self.set_style(style_);
self.transparent = true; self.transparent = true;
@ -294,7 +294,7 @@ pub fn set_base_style_transparent(self: *Plane, _: [*:0]const u8, style_: Style)
pub fn set_base_style_bg_transparent(self: *Plane, _: [*:0]const u8, style_: Style) void { pub fn set_base_style_bg_transparent(self: *Plane, _: [*:0]const u8, style_: Style) void {
self.style_base.fg = if (style_.fg) |color| vaxis.Cell.Color.rgbFromUint(@intCast(color)) else .default; self.style_base.fg = if (style_.fg) |color| vaxis.Cell.Color.rgbFromUint(@intCast(color)) else .default;
self.style.bg = .default; self.style_base.bg = if (style_.bg) |color| vaxis.Cell.Color.rgbFromUint(@intCast(color)) else .default;
if (style_.fs) |fs| set_font_style(&self.style, fs); if (style_.fs) |fs| set_font_style(&self.style, fs);
self.set_style(style_); self.set_style(style_);
self.transparent = true; self.transparent = true;
@ -309,7 +309,7 @@ pub inline fn set_style(self: *Plane, style_: Style) void {
pub inline fn set_style_bg_transparent(self: *Plane, style_: Style) void { pub inline fn set_style_bg_transparent(self: *Plane, style_: Style) void {
if (style_.fg) |color| self.style.fg = vaxis.Cell.Color.rgbFromUint(@intCast(color)); if (style_.fg) |color| self.style.fg = vaxis.Cell.Color.rgbFromUint(@intCast(color));
self.style.bg = .default; if (style_.bg) |color| self.style.bg = vaxis.Cell.Color.rgbFromUint(@intCast(color));
if (style_.fs) |fs| set_font_style(&self.style, fs); if (style_.fs) |fs| set_font_style(&self.style, fs);
self.transparent = true; self.transparent = true;
} }

View file

@ -78,6 +78,7 @@ fn menu_on_render(_: *Self, button: *Button.State(*Menu.State(*Self)), theme: *c
const style_base = if (button.active) theme.editor_cursor else if (button.hover or selected) theme.editor_selection else theme.editor; const style_base = if (button.active) theme.editor_cursor else if (button.hover or selected) theme.editor_selection else theme.editor;
if (button.active or button.hover or selected) { if (button.active or button.hover or selected) {
button.plane.set_base_style(" ", style_base); button.plane.set_base_style(" ", style_base);
button.plane.erase();
} else { } else {
button.plane.set_base_style_bg_transparent(" ", style_base); button.plane.set_base_style_bg_transparent(" ", style_base);
} }
@ -85,10 +86,18 @@ fn menu_on_render(_: *Self, button: *Button.State(*Menu.State(*Self)), theme: *c
const style_text = if (tui.find_scope_style(theme, "keyword")) |sty| sty.style else theme.editor; const style_text = if (tui.find_scope_style(theme, "keyword")) |sty| sty.style else theme.editor;
const style_keybind = if (tui.find_scope_style(theme, "entity.name")) |sty| sty.style else theme.editor; const style_keybind = if (tui.find_scope_style(theme, "entity.name")) |sty| sty.style else theme.editor;
const sep = std.mem.indexOfScalar(u8, button.opts.label, ':') orelse button.opts.label.len; const sep = std.mem.indexOfScalar(u8, button.opts.label, ':') orelse button.opts.label.len;
if (button.active or button.hover or selected) {
button.plane.set_style(style_text);
} else {
button.plane.set_style_bg_transparent(style_text); button.plane.set_style_bg_transparent(style_text);
}
const pointer = if (selected) "" else " "; const pointer = if (selected) "" else " ";
_ = button.plane.print("{s}{s}", .{ pointer, button.opts.label[0..sep] }) catch {}; _ = button.plane.print("{s}{s}", .{ pointer, button.opts.label[0..sep] }) catch {};
if (button.active or button.hover or selected) {
button.plane.set_style(style_keybind);
} else {
button.plane.set_style_bg_transparent(style_keybind); button.plane.set_style_bg_transparent(style_keybind);
}
_ = button.plane.print("{s}", .{button.opts.label[sep + 1 ..]}) catch {}; _ = button.plane.print("{s}", .{button.opts.label[sep + 1 ..]}) catch {};
return false; return false;
} }