Skip to content

Commit e201a2e

Browse files
committed
refactor: add on_hover handling to button and split panel, rename hover function in button configuration
1 parent e3bcf7e commit e201a2e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

examples/split_panel.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ fn main_view(window &gui.Window) gui.View {
5858
sizing: gui.fit_fill
5959
padding: gui.padding_none
6060
on_click: split_click
61+
on_hover: fn (_ &gui.Layout, mut _ gui.Event, mut w gui.Window) {
62+
w.set_mouse_cursor_ew()
63+
}
6164
),
6265
gui.column(
6366
fill: true

view_button.v

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub:
1919
sizing Sizing
2020
content []View
2121
on_click fn (&Layout, mut Event, mut Window) = unsafe { nil }
22+
on_hover fn (&Layout, mut Event, mut Window) = unsafe { nil }
2223
width f32
2324
height f32
2425
min_width f32
@@ -74,7 +75,14 @@ pub fn button(cfg ButtonCfg) View {
7475
on_click: cfg.on_button_click()
7576
on_char: cfg.on_char_button
7677
amend_layout: cfg.amend_layout
77-
on_hover: cfg.on_hover
78+
on_hover: if cfg.on_hover != unsafe { nil } {
79+
fn [cfg] (mut layout Layout, mut e Event, mut w Window) {
80+
cfg.on_button_hover(mut layout, mut e, mut w)
81+
cfg.on_hover(layout, mut e, mut w)
82+
}
83+
} else {
84+
cfg.on_button_hover
85+
}
7886
content: [
7987
row(
8088
name: 'button interior'
@@ -120,7 +128,7 @@ fn (cfg &ButtonCfg) amend_layout(mut layout Layout, mut w Window) {
120128
}
121129
}
122130

123-
fn (cfg &ButtonCfg) on_hover(mut layout Layout, mut e Event, mut w Window) {
131+
fn (cfg &ButtonCfg) on_button_hover(mut layout Layout, mut e Event, mut w Window) {
124132
if layout.shape.on_click == unsafe { nil } {
125133
return
126134
}

0 commit comments

Comments
 (0)