Struct slint::docs::generated_code::SampleComponent
source ยท pub struct SampleComponent {}
Expand description
This an example of the API that is generated for a component in .slint
design markup. This may help you understand
what functions you can call and how you can pass data in and out.
This is the source code:
SampleComponent := Window {
property<int> counter;
// note that dashes will be replaced by underscores in the generated code
property<string> user-name;
callback hello();
// ... maybe more elements here
}
Implementationsยง
sourceยงimpl SampleComponent
impl SampleComponent
sourcepub fn get_counter(&self) -> i32
pub fn get_counter(&self) -> i32
A getter is generated for each property declared at the root of the component.
In this case, this is the getter that returns the value of the counter
property declared in the .slint
design markup.
sourcepub fn set_counter(&self, value: i32)
pub fn set_counter(&self, value: i32)
A setter is generated for each property declared at the root of the component,
In this case, this is the setter that sets the value of the counter
property
declared in the .slint
design markup.
sourcepub fn get_user_name(&self) -> SharedString
pub fn get_user_name(&self) -> SharedString
Returns the value of the user_name
property declared in the .slint
design markup.
sourcepub fn set_user_name(&self, value: SharedString)
pub fn set_user_name(&self, value: SharedString)
Assigns a new value to the user_name
property.
sourcepub fn invoke_hello(&self)
pub fn invoke_hello(&self)
For each callback declared at the root of the component, a function to call that
callback is generated. This is the function that calls the hello
callback declared
in the .slint
design markup.
sourcepub fn on_hello(&self, f: impl Fn() + 'static)
pub fn on_hello(&self, f: impl Fn() + 'static)
For each callback declared at the root of the component, a function connect to that callback
is generated. This is the function that registers the function f as callback when the
callback hello
is emitted. In order to access
the component in the callback, youโd typically capture a weak reference obtained using
ComponentHandle::as_weak
and then upgrade it to a strong reference when the callback is run:
let sample = SampleComponent::new();
let sample_weak = sample.as_weak();
sample.as_ref().on_hello(move || {
let sample = sample_weak.unwrap();
sample.as_ref().set_counter(42);
});
Trait Implementationsยง
sourceยงimpl Clone for SampleComponent
impl Clone for SampleComponent
sourceยงfn clone(&self) -> SampleComponent
fn clone(&self) -> SampleComponent
1.0.0 ยท sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceยงimpl ComponentHandle for SampleComponent
impl ComponentHandle for SampleComponent
sourceยงfn clone_strong(&self) -> Self
fn clone_strong(&self) -> Self
Returns a clone of this handle thatโs a strong reference.
sourceยงfn show(&self)
fn show(&self)
Marks the window of this component to be shown on the screen. This registers
the window with the windowing system. In order to react to events from the windowing system,
such as draw requests or mouse/touch input, it is still necessary to spin the event loop,
using crate::run_event_loop
.
sourceยงfn hide(&self)
fn hide(&self)
Marks the window of this component to be hidden on the screen. This de-registers the window from the windowing system and it will not receive any further events.
sourceยงfn window(&self) -> &Window
fn window(&self) -> &Window
Returns the Window associated with this component. The window API can be used to control different aspects of the integration into the windowing system, such as the position on the screen.
sourceยงfn run(&self)
fn run(&self)
This is a convenience function that first calls Self::show
, followed by crate::run_event_loop()
and Self::hide
.