refactor: button, menu and widget stack apis
This commit is contained in:
parent
dcd9e119da
commit
2f9a0e2eb0
9 changed files with 348 additions and 130 deletions
|
@ -14,7 +14,8 @@ const ed = @import("../editor.zig");
|
|||
const tui = @import("../tui.zig");
|
||||
|
||||
pub fn create(a: Allocator, parent: nc.Plane) !Widget {
|
||||
return Button.create({}, a, parent, .{
|
||||
return Button.create(void, a, parent, .{
|
||||
.ctx = {},
|
||||
.label = tui.get_mode(),
|
||||
.on_click = on_click,
|
||||
.on_layout = layout,
|
||||
|
@ -22,7 +23,7 @@ pub fn create(a: Allocator, parent: nc.Plane) !Widget {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn layout(_: *void, _: *Button.State(void)) Widget.Layout {
|
||||
pub fn layout(_: void, _: *Button.State(void)) Widget.Layout {
|
||||
const name = tui.get_mode();
|
||||
const width = Buffer.egc_chunk_width(name, 0);
|
||||
const padding: usize = if (is_mini_mode()) 3 else 2;
|
||||
|
@ -33,7 +34,7 @@ fn is_mini_mode() bool {
|
|||
return if (tui.current().mini_mode) |_| true else false;
|
||||
}
|
||||
|
||||
pub fn render(state: *void, self: *Button.State(void), theme: *const Widget.Theme) bool {
|
||||
pub fn render(_: void, self: *Button.State(void), theme: *const Widget.Theme) bool {
|
||||
tui.set_base_style(&self.plane, " ", if (self.active) theme.editor_cursor else if (self.hover) theme.editor_selection else theme.statusbar_hover);
|
||||
self.plane.on_styles(nc.style.bold);
|
||||
self.plane.erase();
|
||||
|
@ -41,16 +42,16 @@ pub fn render(state: *void, self: *Button.State(void), theme: *const Widget.Them
|
|||
var buf: [31:0]u8 = undefined;
|
||||
_ = self.plane.putstr(std.fmt.bufPrintZ(&buf, " {s} ", .{tui.get_mode()}) catch return false) catch {};
|
||||
if (is_mini_mode())
|
||||
render_separator(state, self, theme);
|
||||
render_separator(self, theme);
|
||||
return false;
|
||||
}
|
||||
|
||||
fn render_separator(_: *void, self: *Button.State(void), theme: *const Widget.Theme) void {
|
||||
fn render_separator(self: *Button.State(void), theme: *const Widget.Theme) void {
|
||||
if (theme.statusbar_hover.bg) |bg| self.plane.set_fg_rgb(bg) catch {};
|
||||
if (theme.statusbar.bg) |bg| self.plane.set_bg_rgb(bg) catch {};
|
||||
_ = self.plane.putstr("") catch {};
|
||||
}
|
||||
|
||||
fn on_click(_: *void, _: *Button.State(void)) void {
|
||||
fn on_click(_: void, _: *Button.State(void)) void {
|
||||
command.executeName("toggle_input_mode", .{}) catch {};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue