Widgets: add callback arg names to some callback

The ones that have a comment already.

Tests that the name is consistent accross the styles.
This commit is contained in:
Olivier Goffart 2024-11-03 21:16:30 +01:00
parent 51e4d4562a
commit 929e71e6b0
20 changed files with 123 additions and 86 deletions

View file

@ -6,6 +6,7 @@
use i_slint_compiler::expression_tree::Expression;
use i_slint_compiler::langtype::{Function, Type};
use i_slint_compiler::object_tree::PropertyVisibility;
use i_slint_compiler::parser::syntax_nodes;
use i_slint_compiler::typeloader::TypeLoader;
use i_slint_compiler::typeregister::TypeRegister;
use smol_str::{SmolStr, ToSmolStr};
@ -19,11 +20,17 @@ struct PropertyInfo {
ty: Type,
vis: PropertyVisibility,
pure: bool,
/// For a function or callback: the names of the arguments
arg_names: Vec<SmolStr>,
}
impl Display for PropertyInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}/{}{:?}", self.ty, if self.pure { "pure-" } else { "" }, self.vis)
write!(f, "{}/{}{:?}", self.ty, if self.pure { "pure-" } else { "" }, self.vis)?;
if !self.arg_names.is_empty() {
write!(f, "{:?}", self.arg_names)?
}
Ok(())
}
}
@ -55,6 +62,29 @@ fn load_component(component: &Rc<i_slint_compiler::object_tree::Component>) -> C
ty: v.property_type.clone(),
vis: v.visibility,
pure: v.pure.unwrap_or(false),
arg_names: v
.node
.as_ref()
.map(|n| {
if let Some(n) =
syntax_nodes::CallbackDeclaration::new(n.clone())
{
n.CallbackDeclarationParameter()
.map(|p| {
p.DeclaredIdentifier()
.map(|p| p.text().to_smolstr())
.unwrap_or_default()
})
.collect()
} else if let Some(n) = syntax_nodes::Function::new(n.clone()) {
n.ArgumentDeclaration()
.map(|p| p.DeclaredIdentifier().to_smolstr())
.collect()
} else {
vec![]
}
})
.unwrap_or_default(),
},
)
}),
@ -89,6 +119,7 @@ fn load_component(component: &Rc<i_slint_compiler::object_tree::Component>) -> C
ty: v.ty.clone(),
vis: v.property_visibility,
pure: false,
arg_names: vec![],
},
)
}),
@ -104,6 +135,7 @@ fn load_component(component: &Rc<i_slint_compiler::object_tree::Component>) -> C
})),
vis: PropertyVisibility::Public,
pure: false,
arg_names: vec![],
},
);
result.properties.insert(
@ -115,6 +147,7 @@ fn load_component(component: &Rc<i_slint_compiler::object_tree::Component>) -> C
})),
vis: PropertyVisibility::Public,
pure: false,
arg_names: vec![],
},
);
}

View file

@ -10,7 +10,7 @@ export component ComboBoxBase {
in-out property <int> current-index: 0;
in-out property <string> current-value: root.model[root.current-index];
callback selected(/* current-value */ string);
callback selected(current-value: string);
callback show-popup();
public function select(index: int) {
@ -33,7 +33,7 @@ export component ComboBoxBase {
public function move-selection-down() {
root.select(Math.min(root.current-index + 1, root.model.length - 1));
}
function reset-current() {
root.current-index = 0;
}

View file

@ -138,7 +138,7 @@ export component Calendar {
in property <int> display-month;
in property <int> display-year;
callback select-date(/* date */ Date);
callback select-date(date: Date);
// header
for day[index] in root.header-model : CalendarHeaderDelegate {
@ -201,7 +201,7 @@ component YearSelection {
in property <int> selected-year;
in property <int> today-year;
callback select-year(/* year */ int);
callback select-year(year: int);
property <length> row-height: root.height / root.visible-row-count;
property <int> row-count: root.model.length / root.column-count;
@ -311,7 +311,7 @@ export component DatePickerBase {
content-layer := VerticalLayout {
spacing: root.style.vertical-spacing;
Text {
text: root.title;
horizontal-alignment: left;
@ -351,7 +351,7 @@ export component DatePickerBase {
if root.selection-mode : HorizontalLayout {
spacing: root.style.horizontal-spacing;
VerticalLayout {
horizontal-stretch: 0;
alignment: center;
@ -387,9 +387,9 @@ export component DatePickerBase {
}
}
if root.selection-mode : VerticalLayout {
if root.selection-mode : VerticalLayout {
spacing: root.style.vertical-spacing;
if !root.year-selection : Calendar {
min-width: root.calendar-min-width;
min-height: root.calendar-min-height;

View file

@ -17,9 +17,9 @@ export component LineEditBase inherits Rectangle {
in property <color> selection-foreground-color <=> text-input.selection-foreground-color;
in property <length> margin;
callback accepted(/* text */ string);
callback rejected(/* text */ string);
callback edited(/* text */ string);
callback accepted(text: string);
callback rejected(text: string);
callback edited(text: string);
public function set-selection-offsets(start: int, end: int) {
text-input.set-selection-offsets(start, end);

View file

@ -12,8 +12,8 @@ component StandardListViewBase inherits ListView {
in property <[StandardListViewItem]> model;
in-out property <int> current-item: -1;
callback current-item-changed(/* current-item */ int);
callback item-pointer-event(/* item-index */ int, /* event */ PointerEvent, /* absolute mouse position */ Point);
callback current-item-changed(current-item: int);
callback item-pointer-event(item-index: int, event: PointerEvent, absolute-mouse-position: Point);
public function set-current-item(index: int) {
if index < 0 || index >= model.length || index == root.current-item {

View file

@ -19,8 +19,8 @@ export component SliderBase {
out property <bool> handle-pressed;
in-out property <float> value: minimum;
callback changed(/* value */ float);
callback released(/* value */ float);
callback changed(value: float);
callback released(value: float);
private property <length> ref-size: !root.vertical ? root.handle-width : root.handle-height;
@ -49,10 +49,10 @@ export component SliderBase {
if (!root.handle-has-hover) {
root.set-value((!root.vertical ? root.size-to-value(touch-area.mouse-x, root.width) :
root.size-to-value(touch-area.mouse-y, root.height)) + root.minimum);
}
}
self.pressed-value = value;
root.handle-pressed = true;
root.handle-pressed = true;
}
moved => {

View file

@ -15,7 +15,7 @@ export component SpinBoxBase {
out property <bool> has-focus <=> text-input.has-focus;
in-out property <int> value: minimum;
callback edited(/* value */ int);
callback edited(value: int);
public function update-value(value: int) {
if root.value == value || (value >= root.minimum && value <= root.maximum) {
@ -43,7 +43,7 @@ export component SpinBoxBase {
function set-text-to-value() {
text-input.text = root.value;
}
TouchArea {
enabled: root.enabled;

View file

@ -28,8 +28,8 @@ export component TextEditBase inherits Rectangle {
in property <string> placeholder-text;
in property <brush> placeholder-color;
callback edited(/* text */ string);
callback rejected(/* text */ string);
callback edited(text: string);
callback rejected(text: string);
public function set-selection-offsets(start: int, end: int) {
text-input.set-selection-offsets(start, end);

View file

@ -54,7 +54,7 @@ export component Clock {
in-out property <int> current-item;
in property <int> current-value;
callback current-item-changed(/* index */ int);
callback current-item-changed(index: int);
property <length> radius: max(root.width, root.height) / 2;
property <length> picker-ditameter: 48px;

View file

@ -8,27 +8,27 @@ import { MenuBorder } from "./components.slint";
import { StandardButton } from "../common/standardbutton.slint";
import { Date, DatePickerBase } from "../common/datepicker_base.slint";
export { Date }
export { Date }
export component DatePickerPopup inherits PopupWindow {
in property <string> title: "Select date";
in property <Date> date <=> base.date;
callback canceled();
callback accepted(/* current-date */ Date);
callback accepted(current-date: Date);
width: 360px;
height: 524px;
close-policy: PopupClosePolicy.no-auto-close;
background-layer := MenuBorder {
background-layer := MenuBorder {
width: dialog.width;
height: dialog.height;
}
dialog := Dialog {
dialog := Dialog {
padding: 8px;
base := DatePickerBase {
title: root.title;
style: {
@ -63,7 +63,7 @@ export component DatePickerPopup inherits PopupWindow {
title-style: {
font-size: CosmicFontSettings.body.font-size,
font-weight: CosmicFontSettings.body.font-weight,
foreground: CosmicPalette.foreground,
foreground: CosmicPalette.foreground,
},
previous-icon: Icons.arrow-back,
next-icon: Icons.arrow-forward,
@ -79,7 +79,7 @@ export component DatePickerPopup inherits PopupWindow {
}
};
}
StandardButton {
kind: cancel;

View file

@ -94,7 +94,8 @@ component TableViewRow inherits Rectangle {
in property <bool> even;
callback clicked <=> touch-area.clicked;
callback pointer-event(/* event */ PointerEvent, /* absolute mouse position */ Point);
callback pointer-event(event: PointerEvent, absolute-mouse-position: Point);
min-width: layout.min-width;
min-height: max(24px, layout.min-height);
@ -128,10 +129,10 @@ export component StandardTableView {
in-out property <[TableColumn]> columns;
in-out property <int> current-row: -1;
callback sort-ascending(/* column-index */ int);
callback sort-descending(/* column-index */ int);
callback row-pointer-event(/* row-index */ int, /* event */ PointerEvent, /* absolute mouse position */ Point);
callback current-row-changed(/* current-row */ int);
callback sort-ascending(column-index: int);
callback sort-descending(column-index: int);
callback row-pointer-event(row-index: int, event: PointerEvent, mouse-position: Point);
callback current-row-changed(current-row: int);
public function set-current-row(index: int) {
if (index < 0 || index >= rows.length) {

View file

@ -8,25 +8,25 @@ import { MenuBorder } from "./components.slint";
import { StandardButton } from "../common/standardbutton.slint";
import { Date, DatePickerBase } from "../common/datepicker_base.slint";
export { Date }
export { Date }
export component DatePickerPopup inherits PopupWindow {
in property <string> title: "Select date";
in property <Date> date <=> base.date;
callback canceled();
callback accepted(/* current-date */ Date);
callback accepted(current-date: Date);
width: 360px;
height: 524px;
close-policy: PopupClosePolicy.no-auto-close;
background-layer := MenuBorder {
background-layer := MenuBorder {
width: dialog.width;
height: dialog.height;
}
dialog := Dialog {
dialog := Dialog {
padding: 8px;
base := DatePickerBase {
@ -58,12 +58,12 @@ export component DatePickerPopup inherits PopupWindow {
current-day-style: {
foreground: CupertinoPalette.foreground,
font-size: CupertinoFontSettings.title.font-size,
font-weight: CupertinoFontSettings.title.font-weight,
font-weight: CupertinoFontSettings.title.font-weight,
},
title-style: {
font-size: CupertinoFontSettings.body.font-size,
font-weight: CupertinoFontSettings.body.font-weight,
foreground: CupertinoPalette.foreground,
foreground: CupertinoPalette.foreground,
},
previous-icon: Icons.arrow-back,
next-icon: Icons.arrow-forward,
@ -78,8 +78,8 @@ export component DatePickerPopup inherits PopupWindow {
font-weight: CupertinoFontSettings.body.font-weight
}
};
}
}
StandardButton {
kind: cancel;

View file

@ -9,7 +9,7 @@ component TableViewColumn inherits Rectangle {
in property <bool> last;
callback clicked <=> i-touch-area.clicked;
callback adjust-size(/* size **/ length);
callback adjust-size(size: length);
background: transparent;
@ -90,7 +90,7 @@ component TableViewRow inherits Rectangle {
in property <bool> even;
callback clicked <=> i-touch-area.clicked;
callback pointer-event(/* event */ PointerEvent, /* absolute mouse position */ Point);
callback pointer-event(event: PointerEvent, absolute-mouse-position: Point);
min-width: i-layout.min-width;
min-height: max(20px, i-layout.min-height);
@ -126,10 +126,10 @@ export component StandardTableView {
in-out property <[TableColumn]> columns;
in-out property <int> current-row: -1;
callback sort-ascending(int /* column-index */);
callback sort-descending(int /* column-index */);
callback row-pointer-event(int /* row-index */, PointerEvent /* event */, Point /* absolute mouse position */);
callback current-row-changed(int /* current-row */);
callback sort-ascending(column-index: int);
callback sort-descending(column-index: int);
callback row-pointer-event(row-index: int, event: PointerEvent, mouse-position: Point);
callback current-row-changed(current-row: int);
public function set-current-row(index: int) {
if (index < 0 || index >= rows.length) {

View file

@ -77,8 +77,8 @@ export component TextEdit {
in-out property <length> viewport-height <=> scroll-view.viewport-height;
in property <string> placeholder-text;
callback edited(/* text */ string);
callback rejected(/* text */ string);
callback edited <=> text-input.edited-with-text;
callback rejected <=> text-input.rejected-with-text;
accessible-role: AccessibleRole.text-input;
accessible-enabled: root.enabled;
@ -155,12 +155,15 @@ export component TextEdit {
single-line: false;
wrap: word-wrap;
// The other style use an alias to the TextEditBase, and for consistency we also need to use an alias
callback edited-with-text(text: string);
edited => {
root.edited(self.text);
edited-with-text(self.text);
}
callback rejected-with-text(text: string);
rejected => {
root.rejected(self.text);
rejected-with-text(self.text);
}
cursor-position-changed(cpos) => {

View file

@ -8,27 +8,27 @@ import { MenuBorder } from "./components.slint";
import { StandardButton } from "../common/standardbutton.slint";
import { Date, DatePickerBase } from "../common/datepicker_base.slint";
export { Date }
export { Date }
export component DatePickerPopup inherits PopupWindow {
in property <string> title: "Select date";
in property <Date> date <=> base.date;
callback canceled();
callback accepted(/* current-date */ Date);
callback accepted(current-date: Date);
width: 368px;
height: 524px;
close-policy: PopupClosePolicy.no-auto-close;
background-layer := MenuBorder {
background-layer := MenuBorder {
width: dialog.width;
height: dialog.height;
}
dialog := Dialog {
dialog := Dialog {
padding: 8px;
base := DatePickerBase {
title: root.title;
style: {
@ -58,12 +58,12 @@ export component DatePickerPopup inherits PopupWindow {
current-day-style: {
font-size: FluentFontSettings.title.font-size,
font-weight: FluentFontSettings.title.font-weight,
foreground: FluentPalette.foreground,
foreground: FluentPalette.foreground,
},
title-style: {
font-size: FluentFontSettings.body.font-size,
font-weight: FluentFontSettings.body.font-weight,
foreground: FluentPalette.foreground,
foreground: FluentPalette.foreground,
},
previous-icon: Icons.arrow-back,
next-icon: Icons.arrow-forward,
@ -79,7 +79,7 @@ export component DatePickerPopup inherits PopupWindow {
}
};
}
StandardButton {
kind: cancel;

View file

@ -97,7 +97,7 @@ component TableViewRow inherits Rectangle {
in property <bool> even;
callback clicked <=> i-touch-area.clicked;
callback pointer-event(/* event */ PointerEvent, /* absolute mouse position */ Point);
callback pointer-event(event: PointerEvent, absolute-mouse-position: Point);
min-width: i-layout.min-width;
min-height: max(34px, i-layout.min-height);
@ -149,10 +149,10 @@ export component StandardTableView {
in-out property <[TableColumn]> columns;
in-out property <int> current-row: -1;
callback sort-ascending(/* column-index */ int);
callback sort-descending(/* column-index */ int);
callback row-pointer-event(/* row-index */ int, /* event */ PointerEvent, /* absolute mouse position */ Point);
callback current-row-changed(/* current-row */ int);
callback sort-ascending(column-index: int);
callback sort-descending(column-index: int);
callback row-pointer-event(row-index: int, event: PointerEvent, mouse-position: Point);
callback current-row-changed(current-row: int);
public function set-current-row(index: int) {
if (index < 0 || index >= rows.length) {

View file

@ -6,14 +6,14 @@ import { TextButton } from "./button.slint";
import { MaterialPalette, MaterialFontSettings, Icons } from "styling.slint";
import { Date, DatePickerBase } from "../common/datepicker_base.slint";
export { Date }
export { Date }
export component DatePickerPopup inherits PopupWindow {
in property <string> title: "Select date";
in property <Date> date <=> base.date;
callback canceled();
callback accepted(/* current-date */ Date);
callback accepted(current-date: Date);
width: 360px;
height: 524px;
@ -26,9 +26,9 @@ export component DatePickerPopup inherits PopupWindow {
border-radius: 28px;
}
dialog := Dialog {
dialog := Dialog {
padding: 8px;
base := DatePickerBase {
title: root.title;
style: {
@ -58,12 +58,12 @@ export component DatePickerPopup inherits PopupWindow {
current-day-style: {
font-size: MaterialFontSettings.headline-large.font-size,
font-weight: MaterialFontSettings.headline-large.font-weight,
foreground: MaterialPalette.foreground,
foreground: MaterialPalette.foreground,
},
title-style: {
font-size: MaterialFontSettings.label-medium.font-size,
font-weight: MaterialFontSettings.label-medium.font-weight,
foreground: MaterialPalette.foreground,
foreground: MaterialPalette.foreground,
},
previous-icon: Icons.arrow-back,
next-icon: Icons.arrow-forward,
@ -76,10 +76,10 @@ export component DatePickerPopup inherits PopupWindow {
icon-size: 10px,
font-size: MaterialFontSettings.label-large.font-size,
font-weight: MaterialFontSettings.label-large.font-weight
}
}
};
}
TextButton {
text: @tr("Cancel");
dialog-button-role: reject;

View file

@ -121,10 +121,10 @@ export component StandardTableView {
in-out property <[TableColumn]> columns;
in-out property <int> current-row: -1;
callback sort-ascending(/* column-index */ int);
callback sort-descending(/* column-index */ int);
callback row-pointer-event(/* row-index */ int, /* event */ PointerEvent, /* absolute mouse position */ Point);
callback current-row-changed(/* current-row */ int);
callback sort-ascending(column-index: int);
callback sort-descending(column-index: int);
callback row-pointer-event(row-index: int, event: PointerEvent, mouse-position: Point);
callback current-row-changed(current-row: int);
public function set-current-row(index: int) {
if(index < 0 || index >= rows.length) {

View file

@ -17,7 +17,7 @@ export component DatePickerPopup inherits PopupWindow {
property <brush> state-secondary: Palette.color-scheme == ColorScheme.dark ? #000000 : #ffffff;
callback canceled();
callback accepted(/* current-date */ Date);
callback accepted(current-date: Date);
width: 360px;
height: 524px;

View file

@ -7,10 +7,10 @@ export component StandardTableView {
private property <length> item-height: scroll-view.viewport-height / rows.length;
private property <length> current-item-y: scroll-view.viewport-y + current-row * item-height;
callback sort-ascending(int);
callback sort-descending(int);
callback row-pointer-event(int /* row-index */, PointerEvent /* event */, Point /* absolute mouse position */);
callback current-row-changed(int /* current-row */);
callback sort-ascending(column-index: int);
callback sort-descending(column-index: int);
callback row-pointer-event(row-index: int, event: PointerEvent, mouse-position: Point);
callback current-row-changed(current-row: int);
accessible-role: table;
out property <int> current-sort-column: -1;