@@ -12,9 +12,16 @@ const Button = @import("../Button.zig");
1212const tui = @import ("../tui.zig" );
1313const CreateError = @import ("widget.zig" ).CreateError ;
1414
15- pub fn create (allocator : Allocator , parent : Plane , event_handler : ? EventHandler , _ : ? []const u8 ) CreateError ! Widget {
16- return Button .create_widget (void , allocator , parent , .{
17- .ctx = {},
15+ const Style = enum {
16+ plain ,
17+ fancy ,
18+ };
19+ const default_style = .fancy ;
20+
21+ pub fn create (allocator : Allocator , parent : Plane , event_handler : ? EventHandler , arg : ? []const u8 ) CreateError ! Widget {
22+ const style_ = if (arg ) | str_style | std .meta .stringToEnum (Style , str_style ) orelse default_style else default_style ;
23+ return Button .create_widget (Style , allocator , parent , .{
24+ .ctx = style_ ,
1825 .label = tui .get_mode (),
1926 .on_click = on_click ,
2027 .on_click2 = toggle_panel ,
@@ -25,7 +32,7 @@ pub fn create(allocator: Allocator, parent: Plane, event_handler: ?EventHandler,
2532 });
2633}
2734
28- pub fn layout (_ : * void , btn : * Button .State (void )) Widget.Layout {
35+ pub fn layout (_ : * Style , btn : * Button .State (Style )) Widget.Layout {
2936 const name = btn .plane .egc_chunk_width (tui .get_mode (), 0 , 1 );
3037 const logo = if (is_mini_mode () or is_overlay_mode ()) 1 else btn .plane .egc_chunk_width (left ++ symbol ++ right , 0 , 1 );
3138 const padding : usize = 2 ;
@@ -41,9 +48,12 @@ fn is_overlay_mode() bool {
4148 return tui .input_mode_outer () != null ;
4249}
4350
44- pub fn render (_ : * void , self : * Button .State (void ), theme : * const Widget .Theme ) bool {
51+ pub fn render (ctx : * Style , self : * Button .State (Style ), theme : * const Widget .Theme ) bool {
4552 const style_base = theme .statusbar ;
46- const style_label = if (self .active ) theme .editor_cursor else if (self .hover or is_mini_mode ()) theme .statusbar_hover else style_base ;
53+ const style_label = switch (ctx .* ) {
54+ .fancy = > if (self .active ) theme .editor_cursor else if (self .hover ) theme .editor_selection else theme .statusbar_hover ,
55+ .plain = > if (self .active ) theme .editor_cursor else if (self .hover or is_mini_mode ()) theme .statusbar_hover else style_base ,
56+ };
4757 self .plane .set_base_style (theme .editor );
4858 self .plane .erase ();
4959 self .plane .home ();
@@ -68,7 +78,7 @@ pub fn render(_: *void, self: *Button.State(void), theme: *const Widget.Theme) b
6878 return false ;
6979}
7080
71- fn render_separator (self : * Button .State (void ), theme : * const Widget .Theme ) void {
81+ fn render_separator (self : * Button .State (Style ), theme : * const Widget .Theme ) void {
7282 self .plane .reverse_style ();
7383 self .plane .set_base_style (.{ .bg = theme .editor .bg });
7484 if (theme .statusbar .bg ) | bg | self .plane .set_style (.{ .bg = bg });
@@ -79,7 +89,7 @@ const left = " ";
7989const symbol = "" ;
8090const right = " " ;
8191
82- fn render_logo (self : * Button .State (void ), theme : * const Widget .Theme , style_label : Widget .Theme .Style ) void {
92+ fn render_logo (self : * Button .State (Style ), theme : * const Widget .Theme , style_label : Widget .Theme .Style ) void {
8393 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 ;
8494 if (left .len > 0 ) {
8595 self .plane .set_style (style_braces );
@@ -93,7 +103,7 @@ fn render_logo(self: *Button.State(void), theme: *const Widget.Theme, style_labe
93103 }
94104}
95105
96- fn on_click (_ : * void , _ : * Button .State (void )) void {
106+ fn on_click (_ : * Style , _ : * Button .State (Style )) void {
97107 if (is_mini_mode ()) {
98108 command .executeName ("exit_mini_mode" , .{}) catch {};
99109 } else if (is_overlay_mode ()) {
@@ -103,6 +113,6 @@ fn on_click(_: *void, _: *Button.State(void)) void {
103113 }
104114}
105115
106- fn toggle_panel (_ : * void , _ : * Button .State (void )) void {
116+ fn toggle_panel (_ : * Style , _ : * Button .State (Style )) void {
107117 command .executeName ("toggle_panel" , .{}) catch {};
108118}
0 commit comments