Give name to the builtin element's callback argument

This commit is contained in:
Olivier Goffart 2024-11-20 17:38:38 +01:00
parent f225f79d49
commit 6e91b9bc91
3 changed files with 33 additions and 9 deletions

View file

@ -126,16 +126,16 @@ export component TouchArea {
callback clicked;
callback double-clicked;
callback moved;
callback pointer-event(PointerEvent);
callback scroll-event(PointerScrollEvent) -> EventResult;
callback pointer-event(event: PointerEvent);
callback scroll-event(event: PointerScrollEvent) -> EventResult;
//-default_size_binding:expands_to_parent_geometry
}
export component FocusScope {
in property <bool> enabled: true;
out property <bool> has-focus;
callback key_pressed(KeyEvent) -> EventResult;
callback key_released(KeyEvent) -> EventResult;
callback key_pressed(event: KeyEvent) -> EventResult;
callback key_released(event: KeyEvent) -> EventResult;
callback focus_changed_event();
//-default_size_binding:expands_to_parent_geometry
//-accepts_focus
@ -189,8 +189,8 @@ component MenuBar {
//-disallow_global_types_as_child_elements
in property <[MenuEntry]> entries;
callback activated(MenuEntry);
callback sub-menu(MenuEntry) -> [MenuEntry];
callback activated(entry: MenuEntry);
callback sub-menu(entry: MenuEntry) -> [MenuEntry];
// Currently experimental
//-is_internal
@ -200,8 +200,8 @@ component MenuBar {
export component ContextMenu {
function show() {}
//in property <[MenuEntry]> entries;
callback activated(MenuEntry);
callback sub-menu(MenuEntry) -> [MenuEntry];
callback activated(entry: MenuEntry);
callback sub-menu(entry: MenuEntry) -> [MenuEntry];
//-default_size_binding:expands_to_parent_geometry
// Currently experimental
@ -262,7 +262,7 @@ export component TextInput {
callback accepted;
callback rejected;
callback edited;
callback cursor_position_changed(Point);
callback cursor_position_changed(position: Point);
in property <bool> enabled: true;
in property <bool> single-line: true;
in property <bool> read-only: false;

View file

@ -1552,5 +1552,23 @@ mod tests {
res.iter().find(|ci| ci.label == "accessible-action-set-value").unwrap().insert_text,
Some("accessible-action-set-value => {$1}".into())
);
let source = r#"
import { StandardTableView } from "std-widgets.slint";
component MyTouchArea inherits TouchArea {}
component Foo {
MyTouchArea {
🔺
}
}
"#;
let res = get_completions(source).unwrap();
assert_eq!(
res.iter().find(|ci| ci.label == "pointer-event").unwrap().insert_text,
Some("pointer-event(event) => {$1}".into())
);
assert_eq!(
res.iter().find(|ci| ci.label == "clicked").unwrap().insert_text,
Some("clicked => {$1}".into())
);
}
}

View file

@ -142,6 +142,7 @@ export component Test {
root.fn_loc();
}
property <Eee> e: Eee.E2;
pointer-event(aaa) => {}
}
Rectangle {
background: red;
@ -215,6 +216,11 @@ export component Test {
// Fixme: this uses LogicalPoint instead of Point because of implementation details
"```slint\ncallback row-pointer-event(row-index: int, event: PointerEvent, mouse-position: LogicalPosition)\n```",
);
assert_tooltip(
get_tooltip(&mut dc, find_tk("pointer-event", 5.into())),
"```slint\ncallback pointer-event(event: PointerEvent)\n```",
);
// functions
assert_tooltip(
get_tooltip(&mut dc, find_tk("fn_glob(local-prop)", 1.into())),
"```slint\npure function fn-glob(abc: int)\n```",