Skip to content

Commit 45d6342

Browse files
committed
fix left click on buttons
1 parent 759273b commit 45d6342

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

examples/context_menu_demo.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ fn main_view(mut window gui.Window) gui.View {
8282
// ---------------------------------------------------------
8383
on_click: fn (_ voidptr, mut e gui.Event, mut w gui.Window) {
8484
mut app := w.state[ContextMenuApp]()
85-
println(u8(e.mouse_button))
8685
if e.mouse_button == .right {
8786
app.show_context_menu = true
8887
w.set_id_focus(id_focus_context_menu)

view_button.v

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn button(cfg ButtonCfg) View {
7272
sizing: cfg.sizing
7373
tooltip: cfg.tooltip
7474
cfg: &cfg
75-
on_click: cfg.on_click
75+
on_click: cfg.left_click()
7676
on_char: cfg.on_char_button
7777
amend_layout: cfg.amend_layout
7878
on_hover: cfg.on_hover
@@ -92,6 +92,17 @@ pub fn button(cfg ButtonCfg) View {
9292
)
9393
}
9494

95+
fn (cfg &ButtonCfg) left_click() fn (&ButtonCfg, mut Event, mut Window) {
96+
if cfg.on_click == unsafe { nil } {
97+
return cfg.on_click
98+
}
99+
return fn [cfg] (_ &ButtonCfg, mut e Event, mut w Window) {
100+
if e.mouse_button == .left {
101+
cfg.on_click(cfg, mut e, mut w)
102+
}
103+
}
104+
}
105+
95106
fn (cfg &ButtonCfg) on_char_button(_ &ButtonCfg, mut e Event, mut w Window) {
96107
if e.char_code == ` ` && cfg.on_click != unsafe { nil } {
97108
cfg.on_click(cfg, mut e, mut w)

0 commit comments

Comments
 (0)