Skip to content

Commit 0b1f439

Browse files
committed
refactor: replace ButtonCfg references with Layout in click handlers, update related functions, and optimize event handling logic in views
1 parent bdaeb46 commit 0b1f439

27 files changed

+107
-112
lines changed

doc/04-Rows-Columns.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pub fn button(cfg ButtonCfg) View {
3535
min_height: cfg.min_height
3636
max_height: cfg.max_height
3737
sizing: cfg.sizing
38-
cfg: &cfg
3938
on_click: cfg.on_click
4039
on_char: cfg.on_char_button
4140
amend_layout: cfg.amend_layout

doc/08-Container-View.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ Events and hooks:
9292

9393
Tips:
9494

95-
- Use `cfg: &cfg` in your composed views to let handlers access your
96-
outer config struct.
9795
- To hide the container from layout spacing but keep it drawing, use
9896
`over_draw` on the view side (primarily internal; `invisible` also
9997
removes spacing by returning a minimal placeholder).

event_handlers.v

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn char_handler(layout &Layout, mut e Event, mut w Window) {
2525
}
2626
}
2727
if layout.shape.on_char != unsafe { nil } {
28-
layout.shape.on_char(layout.shape, mut e, mut w)
28+
layout.shape.on_char(layout, mut e, mut w)
2929
if e.is_handled {
3030
return
3131
}
@@ -57,7 +57,7 @@ fn keydown_handler(layout &Layout, mut e Event, mut w Window) {
5757
}
5858
}
5959
if layout.shape.on_keydown != unsafe { nil } {
60-
layout.shape.on_keydown(layout.shape, mut e, mut w)
60+
layout.shape.on_keydown(layout, mut e, mut w)
6161
if e.is_handled {
6262
return
6363
}
@@ -125,7 +125,7 @@ fn mouse_down_handler(layout &Layout, in_handler bool, mut e Event, mut w Window
125125
if layout.shape.on_click != unsafe { nil } {
126126
// make click handler mouse coordinates relative to layout.shape
127127
mut ev := event_relative_to(layout.shape, e)
128-
layout.shape.on_click(layout.shape, mut ev, mut w)
128+
layout.shape.on_click(layout, mut ev, mut w)
129129
if ev.is_handled {
130130
e.is_handled = true
131131
return
@@ -190,7 +190,7 @@ fn mouse_up_handler(layout &Layout, mut e Event, mut w Window) {
190190
if layout.shape.on_mouse_up != unsafe { nil } {
191191
// make up handler mouse coordinates relative to layout.shape
192192
mut ev := event_relative_to(layout.shape, e)
193-
layout.shape.on_mouse_up(layout.shape, mut ev, mut w)
193+
layout.shape.on_mouse_up(layout, mut ev, mut w)
194194
if ev.is_handled {
195195
e.is_handled = true
196196
return

examples/buttons.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ fn button_row(label string, button gui.View) gui.View {
120120
content: [
121121
gui.row(
122122
padding: gui.padding_none
123-
content: [gui.text(text: label, mode: .wrap)]
123+
content: [gui.text(text: label, mode: .single_line)]
124124
),
125125
gui.row(sizing: gui.fill_fit),
126126
button,
127127
]
128128
)
129129
}
130130

131-
fn click_handler(_ &gui.ButtonCfg, mut _ gui.Event, mut w gui.Window) {
131+
fn click_handler(_ &gui.Layout, mut _ gui.Event, mut w gui.Window) {
132132
mut app := w.state[ButtonsApp]()
133133
app.clicks += 1
134134
w.set_id_focus(1)

examples/calc.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ fn get_row(ops []string) []gui.View {
112112
return content
113113
}
114114

115-
fn btn_click(btn &gui.ButtonCfg, mut e gui.Event, mut w gui.Window) {
115+
fn btn_click(ly &gui.Layout, mut e gui.Event, mut w gui.Window) {
116116
mut app := w.state[CalcApp]()
117-
app.do_op(btn.id)
117+
app.do_op(ly.shape.id)
118118
e.is_handled = true
119119
}
120120

examples/date_picker_options.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ fn years_dates_group(app DatePickerApp) gui.View {
486486
content: [
487487
gui.text(text: 'Reset'),
488488
]
489-
on_click: fn (_ &gui.ButtonCfg, mut e gui.Event, mut w gui.Window) {
489+
on_click: fn (_ &gui.Layout, mut e gui.Event, mut w gui.Window) {
490490
w.date_picker_reset('example')
491491
mut app := w.state[DatePickerApp]()
492492
app.date_picker_dates = [

examples/dialogs.v

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn message_type() gui.View {
5555
id_focus: 1
5656
sizing: gui.fill_fit
5757
content: [gui.text(text: '.dialog_type == .message')]
58-
on_click: fn (_ &gui.ButtonCfg, mut _ gui.Event, mut w gui.Window) {
58+
on_click: fn (_ &gui.Layout, mut _ gui.Event, mut w gui.Window) {
5959
w.dialog(
6060
align_buttons: .end
6161
dialog_type: .message
@@ -77,7 +77,7 @@ fn confirm_type() gui.View {
7777
id_focus: 2
7878
sizing: gui.fill_fit
7979
content: [gui.text(text: '.dialog_type == .confirm')]
80-
on_click: fn (_ &gui.ButtonCfg, mut _ gui.Event, mut w gui.Window) {
80+
on_click: fn (_ &gui.Layout, mut _ gui.Event, mut w gui.Window) {
8181
w.dialog(
8282
dialog_type: .confirm
8383
title: 'Destory All Data?'
@@ -98,7 +98,7 @@ fn prompt_type() gui.View {
9898
id_focus: 3
9999
sizing: gui.fill_fit
100100
content: [gui.text(text: '.dialog_type == .prompt')]
101-
on_click: fn (_ &gui.ButtonCfg, mut _ gui.Event, mut w gui.Window) {
101+
on_click: fn (_ &gui.Layout, mut _ gui.Event, mut w gui.Window) {
102102
w.dialog(
103103
dialog_type: .prompt
104104
title: 'Monty Python Quiz'
@@ -119,7 +119,7 @@ fn custom_type() gui.View {
119119
id_focus: 4
120120
sizing: gui.fill_fit
121121
content: [gui.text(text: '.dialog_type == .custom')]
122-
on_click: fn (_ &gui.ButtonCfg, mut _ gui.Event, mut w gui.Window) {
122+
on_click: fn (_ &gui.Layout, mut _ gui.Event, mut w gui.Window) {
123123
w.dialog(
124124
dialog_type: .custom
125125
custom_content: [
@@ -131,7 +131,7 @@ fn custom_type() gui.View {
131131
gui.button(
132132
id_focus: gui.dialog_base_id_focus
133133
content: [gui.text(text: 'Close Me')]
134-
on_click: fn (_ &gui.ButtonCfg, mut _ gui.Event, mut w gui.Window) {
134+
on_click: fn (_ &gui.Layout, mut _ gui.Event, mut w gui.Window) {
135135
w.dialog_dismiss()
136136
}
137137
),

examples/form_demo.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn main_view(mut window gui.Window) gui.View {
7373
id_focus: id_focus_zip
7474
sizing: gui.fixed_fit
7575
width: 100
76-
on_text_changed: fn (_ &gui.InputCfg, s string, mut w gui.Window) {
76+
on_text_changed: fn (_ &gui.Shape, s string, mut w gui.Window) {
7777
mut app := w.state[FormDemoApp]()
7878
app.zip = s
7979
}
@@ -109,7 +109,7 @@ fn label_input_row(label string, value string, id_focus u32, changed fn (string)
109109
id_focus: id_focus
110110
sizing: gui.fixed_fit
111111
width: field_width
112-
on_text_changed: fn [changed] (_ &gui.InputCfg, s string, mut w gui.Window) {
112+
on_text_changed: fn [changed] (_ &gui.Shape, s string, mut w gui.Window) {
113113
changed(s)
114114
}
115115
),

examples/get_started.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn main_view(window &gui.Window) gui.View {
5555
gui.button(
5656
id_focus: 1
5757
content: [gui.text(text: '${app.clicks} Clicks')]
58-
on_click: fn (_ &gui.ButtonCfg, mut _ gui.Event, mut w gui.Window) {
58+
on_click: fn (_ &gui.Layout, mut _ gui.Event, mut w gui.Window) {
5959
mut app := w.state[GetStartedApp]()
6060
app.clicks += 1
6161
}

examples/icon_font_demo.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn search_box(text string) gui.View {
8787
padding_border: gui.padding_one
8888
color_border: gui.theme().color_border
8989
placeholder: 'Search'
90-
on_text_changed: fn (_ &gui.InputCfg, s string, mut w gui.Window) {
90+
on_text_changed: fn (_ &gui.Shape, s string, mut w gui.Window) {
9191
mut app := w.state[IconFontApp]()
9292
app.search = s
9393
app.icons.clear()

0 commit comments

Comments
 (0)