Building a reusable PopupWindow/Dialog #8192
-
I am trying to build a popup component which I can reuse to display different kind of (text) information, depending on the context it was triggered from. Therefor I built this component: import { StandardButton, Palette } from "std-widgets.slint";
export component InfoDialog inherits PopupWindow {
in property <string> info_text: "";
close-policy: no-auto-close;
Rectangle {
background: Palette.background;
border-color: Palette.border;
border-width: 1px;
}
info_popup_layout := Dialog {
height: 100%;
width: 100%;
info_popup_text := Text {
text: root.info_text;
wrap: word-wrap;
font-size: 18px;
}
StandardButton {
kind: ok;
clicked => {
root.close();
}
}
}
} This is how I try to incorporate the component into my
And this is my rust side of things, where I react to the callbacks triggered on the buttons: use slint::ComponentHandle;
slint::include_modules!();
fn main() {
let ui = MainWindow::new().unwrap();
let ui_weak = ui.as_weak();
ui.on_event_one({
let ui = ui_weak.upgrade().unwrap();
move || {
ui.invoke_show_info_popup("Lorem Ipsum".into());
}
});
let ui_weak = ui.as_weak();
ui.on_event_two({
let ui = ui_weak.upgrade().unwrap();
move || {
ui.invoke_show_info_popup("Ipsum Lorem".into());
}
});
ui.run().unwrap();
} So what I am trying to do is to find a way to pass a different string to my Popup-component. The problem is that as soon as I include the following line into my
First of all I am not really sure, what this error message is trying to tell me. Also what would be a canoncial way to implement a component like that. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I guess it's because Here's slintpad with a working version of what you're trying to do. |
Beta Was this translation helpful? Give feedback.
I guess it's because
PopupWindow
doesn't allow for access of properties of elements within it from outside, and you try to accessinfo_text
from yourMainWindow
component.Here's slintpad with a working version of what you're trying to do.