Compare commits
No commits in common. "a5af34e13f826f614153fbd110d202c569df7f30" and "0c98460ca8b87a2d8771df581cbdb2590feb225b" have entirely different histories.
a5af34e13f
...
0c98460ca8
1 changed files with 10 additions and 20 deletions
|
|
@ -12,16 +12,9 @@ const Button = @import("../Button.zig");
|
||||||
const tui = @import("../tui.zig");
|
const tui = @import("../tui.zig");
|
||||||
const CreateError = @import("widget.zig").CreateError;
|
const CreateError = @import("widget.zig").CreateError;
|
||||||
|
|
||||||
const Style = enum {
|
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?EventHandler, _: ?[]const u8) CreateError!Widget {
|
||||||
plain,
|
return Button.create_widget(void, allocator, parent, .{
|
||||||
fancy,
|
.ctx = {},
|
||||||
};
|
|
||||||
const default_style = .fancy;
|
|
||||||
|
|
||||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?EventHandler, arg: ?[]const u8) CreateError!Widget {
|
|
||||||
const style_ = if (arg) |str_style| std.meta.stringToEnum(Style, str_style) orelse default_style else default_style;
|
|
||||||
return Button.create_widget(Style, allocator, parent, .{
|
|
||||||
.ctx = style_,
|
|
||||||
.label = tui.get_mode(),
|
.label = tui.get_mode(),
|
||||||
.on_click = on_click,
|
.on_click = on_click,
|
||||||
.on_click2 = toggle_panel,
|
.on_click2 = toggle_panel,
|
||||||
|
|
@ -32,7 +25,7 @@ pub fn create(allocator: Allocator, parent: Plane, event_handler: ?EventHandler,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn layout(_: *Style, btn: *Button.State(Style)) Widget.Layout {
|
pub fn layout(_: *void, btn: *Button.State(void)) Widget.Layout {
|
||||||
const name = btn.plane.egc_chunk_width(tui.get_mode(), 0, 1);
|
const name = btn.plane.egc_chunk_width(tui.get_mode(), 0, 1);
|
||||||
const logo = if (is_mini_mode() or is_overlay_mode()) 1 else btn.plane.egc_chunk_width(left ++ symbol ++ right, 0, 1);
|
const logo = if (is_mini_mode() or is_overlay_mode()) 1 else btn.plane.egc_chunk_width(left ++ symbol ++ right, 0, 1);
|
||||||
const padding: usize = 2;
|
const padding: usize = 2;
|
||||||
|
|
@ -48,12 +41,9 @@ fn is_overlay_mode() bool {
|
||||||
return tui.input_mode_outer() != null;
|
return tui.input_mode_outer() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(ctx: *Style, self: *Button.State(Style), theme: *const Widget.Theme) bool {
|
pub fn render(_: *void, self: *Button.State(void), theme: *const Widget.Theme) bool {
|
||||||
const style_base = theme.statusbar;
|
const style_base = theme.statusbar;
|
||||||
const style_label = switch (ctx.*) {
|
const style_label = if (self.active) theme.editor_cursor else if (self.hover) theme.editor_selection else theme.statusbar_hover;
|
||||||
.fancy => if (self.active) theme.editor_cursor else if (self.hover) theme.editor_selection else theme.statusbar_hover,
|
|
||||||
.plain => if (self.active) theme.editor_cursor else if (self.hover or is_mini_mode()) theme.statusbar_hover else style_base,
|
|
||||||
};
|
|
||||||
self.plane.set_base_style(theme.editor);
|
self.plane.set_base_style(theme.editor);
|
||||||
self.plane.erase();
|
self.plane.erase();
|
||||||
self.plane.home();
|
self.plane.home();
|
||||||
|
|
@ -78,7 +68,7 @@ pub fn render(ctx: *Style, self: *Button.State(Style), theme: *const Widget.Them
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_separator(self: *Button.State(Style), theme: *const Widget.Theme) void {
|
fn render_separator(self: *Button.State(void), theme: *const Widget.Theme) void {
|
||||||
self.plane.reverse_style();
|
self.plane.reverse_style();
|
||||||
self.plane.set_base_style(.{ .bg = theme.editor.bg });
|
self.plane.set_base_style(.{ .bg = theme.editor.bg });
|
||||||
if (theme.statusbar.bg) |bg| self.plane.set_style(.{ .bg = bg });
|
if (theme.statusbar.bg) |bg| self.plane.set_style(.{ .bg = bg });
|
||||||
|
|
@ -89,7 +79,7 @@ const left = " ";
|
||||||
const symbol = "";
|
const symbol = "";
|
||||||
const right = " ";
|
const right = " ";
|
||||||
|
|
||||||
fn render_logo(self: *Button.State(Style), theme: *const Widget.Theme, style_label: Widget.Theme.Style) void {
|
fn render_logo(self: *Button.State(void), theme: *const Widget.Theme, style_label: Widget.Theme.Style) void {
|
||||||
const style_braces: Widget.Theme.Style = if (tui.find_scope_style(theme, "punctuation")) |sty| .{ .fg = sty.style.fg, .bg = style_label.bg, .fs = style_label.fs } else style_label;
|
const style_braces: Widget.Theme.Style = if (tui.find_scope_style(theme, "punctuation")) |sty| .{ .fg = sty.style.fg, .bg = style_label.bg, .fs = style_label.fs } else style_label;
|
||||||
if (left.len > 0) {
|
if (left.len > 0) {
|
||||||
self.plane.set_style(style_braces);
|
self.plane.set_style(style_braces);
|
||||||
|
|
@ -103,7 +93,7 @@ fn render_logo(self: *Button.State(Style), theme: *const Widget.Theme, style_lab
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_click(_: *Style, _: *Button.State(Style)) void {
|
fn on_click(_: *void, _: *Button.State(void)) void {
|
||||||
if (is_mini_mode()) {
|
if (is_mini_mode()) {
|
||||||
command.executeName("exit_mini_mode", .{}) catch {};
|
command.executeName("exit_mini_mode", .{}) catch {};
|
||||||
} else if (is_overlay_mode()) {
|
} else if (is_overlay_mode()) {
|
||||||
|
|
@ -113,6 +103,6 @@ fn on_click(_: *Style, _: *Button.State(Style)) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_panel(_: *Style, _: *Button.State(Style)) void {
|
fn toggle_panel(_: *void, _: *Button.State(void)) void {
|
||||||
command.executeName("toggle_panel", .{}) catch {};
|
command.executeName("toggle_panel", .{}) catch {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue