Access nested components from rust? #5794
Answered
by
FloVanGH
hellozyemlya
asked this question in
Q&A
-
Window:
Component:
Is it possible somehow to access model property of MyTextComponent from instance of window? Something like |
Beta Was this translation helpful? Give feedback.
Answered by
FloVanGH
Aug 8, 2024
Replies: 2 comments 2 replies
-
You need to forward the property to the root, or use a global: https://releases.slint.dev/1.7.1/docs/slint/src/language/syntax/globals |
Beta Was this translation helpful? Give feedback.
1 reply
-
Hi, there are two ways. One is to use a binding on the window the other is to use a global: Window bindingimport { VerticalBox } from "std-widgets.slint";
import {MyTextComponent} from "child.slint";
export component AppWindow inherits Window {
in property text-model <=> myteext.model;
callback request-increase-value();
VerticalBox {
mytext := MyTextComponent {
}
}
} let window = AppWindow::new().unwrap();
window.set_text_model(/* set your data here */);
window.run().unwrap(); globalimport { VerticalBox } from "std-widgets.slint";
import {MyTextComponent} from "child.slint";
export global Adapter {
in property <[{foo: string, col: color}]> text_model;
}
export component AppWindow inherits Window {
callback request-increase-value();
VerticalBox {
mytext := MyTextComponent {
model: Adapter.text_model;
}
}
} let window = AppWindow::new().unwrap();
Adapter::get(&window).set_text_model(/* set your data here */);
window.run().unwrap(); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
hellozyemlya
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
there are two ways. One is to use a binding on the window the other is to use a global:
Window binding
global