Skip to content

Commit 929e71e

Browse files
committed
Widgets: add callback arg names to some callback
The ones that have a comment already. Tests that the name is consistent accross the styles.
1 parent 51e4d45 commit 929e71e

20 files changed

+123
-86
lines changed

internal/compiler/tests/consistent_styles.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use i_slint_compiler::expression_tree::Expression;
77
use i_slint_compiler::langtype::{Function, Type};
88
use i_slint_compiler::object_tree::PropertyVisibility;
9+
use i_slint_compiler::parser::syntax_nodes;
910
use i_slint_compiler::typeloader::TypeLoader;
1011
use i_slint_compiler::typeregister::TypeRegister;
1112
use smol_str::{SmolStr, ToSmolStr};
@@ -19,11 +20,17 @@ struct PropertyInfo {
1920
ty: Type,
2021
vis: PropertyVisibility,
2122
pure: bool,
23+
/// For a function or callback: the names of the arguments
24+
arg_names: Vec<SmolStr>,
2225
}
2326

2427
impl Display for PropertyInfo {
2528
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26-
write!(f, "{}/{}{:?}", self.ty, if self.pure { "pure-" } else { "" }, self.vis)
29+
write!(f, "{}/{}{:?}", self.ty, if self.pure { "pure-" } else { "" }, self.vis)?;
30+
if !self.arg_names.is_empty() {
31+
write!(f, "{:?}", self.arg_names)?
32+
}
33+
Ok(())
2734
}
2835
}
2936

@@ -55,6 +62,29 @@ fn load_component(component: &Rc<i_slint_compiler::object_tree::Component>) -> C
5562
ty: v.property_type.clone(),
5663
vis: v.visibility,
5764
pure: v.pure.unwrap_or(false),
65+
arg_names: v
66+
.node
67+
.as_ref()
68+
.map(|n| {
69+
if let Some(n) =
70+
syntax_nodes::CallbackDeclaration::new(n.clone())
71+
{
72+
n.CallbackDeclarationParameter()
73+
.map(|p| {
74+
p.DeclaredIdentifier()
75+
.map(|p| p.text().to_smolstr())
76+
.unwrap_or_default()
77+
})
78+
.collect()
79+
} else if let Some(n) = syntax_nodes::Function::new(n.clone()) {
80+
n.ArgumentDeclaration()
81+
.map(|p| p.DeclaredIdentifier().to_smolstr())
82+
.collect()
83+
} else {
84+
vec![]
85+
}
86+
})
87+
.unwrap_or_default(),
5888
},
5989
)
6090
}),
@@ -89,6 +119,7 @@ fn load_component(component: &Rc<i_slint_compiler::object_tree::Component>) -> C
89119
ty: v.ty.clone(),
90120
vis: v.property_visibility,
91121
pure: false,
122+
arg_names: vec![],
92123
},
93124
)
94125
}),
@@ -104,6 +135,7 @@ fn load_component(component: &Rc<i_slint_compiler::object_tree::Component>) -> C
104135
})),
105136
vis: PropertyVisibility::Public,
106137
pure: false,
138+
arg_names: vec![],
107139
},
108140
);
109141
result.properties.insert(
@@ -115,6 +147,7 @@ fn load_component(component: &Rc<i_slint_compiler::object_tree::Component>) -> C
115147
})),
116148
vis: PropertyVisibility::Public,
117149
pure: false,
150+
arg_names: vec![],
118151
},
119152
);
120153
}

internal/compiler/widgets/common/combobox-base.slint

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export component ComboBoxBase {
1010
in-out property <int> current-index: 0;
1111
in-out property <string> current-value: root.model[root.current-index];
1212

13-
callback selected(/* current-value */ string);
13+
callback selected(current-value: string);
1414
callback show-popup();
1515

1616
public function select(index: int) {
@@ -33,7 +33,7 @@ export component ComboBoxBase {
3333
public function move-selection-down() {
3434
root.select(Math.min(root.current-index + 1, root.model.length - 1));
3535
}
36-
36+
3737
function reset-current() {
3838
root.current-index = 0;
3939
}

internal/compiler/widgets/common/datepicker_base.slint

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export component Calendar {
138138
in property <int> display-month;
139139
in property <int> display-year;
140140

141-
callback select-date(/* date */ Date);
141+
callback select-date(date: Date);
142142

143143
// header
144144
for day[index] in root.header-model : CalendarHeaderDelegate {
@@ -201,7 +201,7 @@ component YearSelection {
201201
in property <int> selected-year;
202202
in property <int> today-year;
203203

204-
callback select-year(/* year */ int);
204+
callback select-year(year: int);
205205

206206
property <length> row-height: root.height / root.visible-row-count;
207207
property <int> row-count: root.model.length / root.column-count;
@@ -311,7 +311,7 @@ export component DatePickerBase {
311311

312312
content-layer := VerticalLayout {
313313
spacing: root.style.vertical-spacing;
314-
314+
315315
Text {
316316
text: root.title;
317317
horizontal-alignment: left;
@@ -351,7 +351,7 @@ export component DatePickerBase {
351351

352352
if root.selection-mode : HorizontalLayout {
353353
spacing: root.style.horizontal-spacing;
354-
354+
355355
VerticalLayout {
356356
horizontal-stretch: 0;
357357
alignment: center;
@@ -387,9 +387,9 @@ export component DatePickerBase {
387387
}
388388
}
389389

390-
if root.selection-mode : VerticalLayout {
390+
if root.selection-mode : VerticalLayout {
391391
spacing: root.style.vertical-spacing;
392-
392+
393393
if !root.year-selection : Calendar {
394394
min-width: root.calendar-min-width;
395395
min-height: root.calendar-min-height;

internal/compiler/widgets/common/lineedit-base.slint

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export component LineEditBase inherits Rectangle {
1717
in property <color> selection-foreground-color <=> text-input.selection-foreground-color;
1818
in property <length> margin;
1919

20-
callback accepted(/* text */ string);
21-
callback rejected(/* text */ string);
22-
callback edited(/* text */ string);
20+
callback accepted(text: string);
21+
callback rejected(text: string);
22+
callback edited(text: string);
2323

2424
public function set-selection-offsets(start: int, end: int) {
2525
text-input.set-selection-offsets(start, end);

internal/compiler/widgets/common/listview.slint

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ component StandardListViewBase inherits ListView {
1212
in property <[StandardListViewItem]> model;
1313
in-out property <int> current-item: -1;
1414

15-
callback current-item-changed(/* current-item */ int);
16-
callback item-pointer-event(/* item-index */ int, /* event */ PointerEvent, /* absolute mouse position */ Point);
15+
callback current-item-changed(current-item: int);
16+
callback item-pointer-event(item-index: int, event: PointerEvent, absolute-mouse-position: Point);
1717

1818
public function set-current-item(index: int) {
1919
if index < 0 || index >= model.length || index == root.current-item {

internal/compiler/widgets/common/slider-base.slint

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export component SliderBase {
1919
out property <bool> handle-pressed;
2020
in-out property <float> value: minimum;
2121

22-
callback changed(/* value */ float);
23-
callback released(/* value */ float);
22+
callback changed(value: float);
23+
callback released(value: float);
2424

2525
private property <length> ref-size: !root.vertical ? root.handle-width : root.handle-height;
2626

@@ -49,10 +49,10 @@ export component SliderBase {
4949
if (!root.handle-has-hover) {
5050
root.set-value((!root.vertical ? root.size-to-value(touch-area.mouse-x, root.width) :
5151
root.size-to-value(touch-area.mouse-y, root.height)) + root.minimum);
52-
}
53-
52+
}
53+
5454
self.pressed-value = value;
55-
root.handle-pressed = true;
55+
root.handle-pressed = true;
5656
}
5757

5858
moved => {

internal/compiler/widgets/common/spinbox-base.slint

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export component SpinBoxBase {
1515
out property <bool> has-focus <=> text-input.has-focus;
1616
in-out property <int> value: minimum;
1717

18-
callback edited(/* value */ int);
18+
callback edited(value: int);
1919

2020
public function update-value(value: int) {
2121
if root.value == value || (value >= root.minimum && value <= root.maximum) {
@@ -43,7 +43,7 @@ export component SpinBoxBase {
4343
function set-text-to-value() {
4444
text-input.text = root.value;
4545
}
46-
46+
4747
TouchArea {
4848
enabled: root.enabled;
4949

internal/compiler/widgets/common/textedit-base.slint

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export component TextEditBase inherits Rectangle {
2828
in property <string> placeholder-text;
2929
in property <brush> placeholder-color;
3030

31-
callback edited(/* text */ string);
32-
callback rejected(/* text */ string);
31+
callback edited(text: string);
32+
callback rejected(text: string);
3333

3434
public function set-selection-offsets(start: int, end: int) {
3535
text-input.set-selection-offsets(start, end);

internal/compiler/widgets/common/time-picker-base.slint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export component Clock {
5454
in-out property <int> current-item;
5555
in property <int> current-value;
5656

57-
callback current-item-changed(/* index */ int);
57+
callback current-item-changed(index: int);
5858

5959
property <length> radius: max(root.width, root.height) / 2;
6060
property <length> picker-ditameter: 48px;

internal/compiler/widgets/cosmic/datepicker.slint

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@ import { MenuBorder } from "./components.slint";
88
import { StandardButton } from "../common/standardbutton.slint";
99

1010
import { Date, DatePickerBase } from "../common/datepicker_base.slint";
11-
export { Date }
11+
export { Date }
1212

1313
export component DatePickerPopup inherits PopupWindow {
1414
in property <string> title: "Select date";
1515
in property <Date> date <=> base.date;
1616

1717
callback canceled();
18-
callback accepted(/* current-date */ Date);
18+
callback accepted(current-date: Date);
1919

2020
width: 360px;
2121
height: 524px;
2222
close-policy: PopupClosePolicy.no-auto-close;
23-
24-
background-layer := MenuBorder {
23+
24+
background-layer := MenuBorder {
2525
width: dialog.width;
2626
height: dialog.height;
2727
}
2828

29-
dialog := Dialog {
29+
dialog := Dialog {
3030
padding: 8px;
31-
31+
3232
base := DatePickerBase {
3333
title: root.title;
3434
style: {
@@ -63,7 +63,7 @@ export component DatePickerPopup inherits PopupWindow {
6363
title-style: {
6464
font-size: CosmicFontSettings.body.font-size,
6565
font-weight: CosmicFontSettings.body.font-weight,
66-
foreground: CosmicPalette.foreground,
66+
foreground: CosmicPalette.foreground,
6767
},
6868
previous-icon: Icons.arrow-back,
6969
next-icon: Icons.arrow-forward,
@@ -79,7 +79,7 @@ export component DatePickerPopup inherits PopupWindow {
7979
}
8080
};
8181
}
82-
82+
8383
StandardButton {
8484
kind: cancel;
8585

0 commit comments

Comments
 (0)