slint
slint copied to clipboard
Encapsulate widgets with rust logic
Hey, I've read the documentation and examples, but couldn't quite figure out what the proper approach for more complex applications looks like. Let's say, that I have some application with multiple screens using Rust. From what I understand, if I want to add some logic using rust, I have to do it via callbacks on the window? Is there no way to create a widget using the slint language, add some logic using rust and then use that Widget, with the rust logic, within another slint language widget/window?
Having a single point to add the rust logic feels extremely inconvenient to me. I would have imagined something like this: (pseudocode):
pub fn MyLoginScreen() {
slint::slint! {
import { Button } from "std-widgets.slint";
export LoginScreen := Rectangle {
callback login_clicked <=> btnLogin.clicked;
HorizontalLayout {
alignment: center;
VerticalLayout {
alignment: center;
btnLogin := Button {
text: "Login";
}
}
}
}
}
let login = LoginScreen::new();
login.on_login_clicked(|| eprintln!("LOGIN"));
}
pub fn main() {
slint::slint! {
export App := Window {
callback quit();
login := MyLoginScreen { }
}
}
let app = App::new();
app.run();
}
Is adding the logic via callbacks to the window and then forwarding these to the screens the only way?