pub struct SampleComponent { /* private fields */ }
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:
export component SampleComponent inherits Window {
in-out property<int> counter;
// note that dashes will be replaced by underscores in the generated code
in-out property<string> user-name;
callback hello;
public function do-something(x: int) -> bool { return x > 0; }
// ... maybe more elements here
}
Implementations§
Source§impl SampleComponent
impl SampleComponent
Sourcepub fn new() -> Result<Self, PlatformError>
pub fn new() -> Result<Self, PlatformError>
Creates a new instance that is reference counted and pinned in memory.
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 synchronously 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().unwrap();
let sample_weak = sample.as_weak();
sample.as_ref().on_hello(move || {
let sample = sample_weak.unwrap();
sample.as_ref().set_counter(42);
});
Sourcepub fn invoke_do_something(&self, d: i32) -> bool
pub fn invoke_do_something(&self, d: i32) -> bool
For each public function declared at the root of the component, a function to synchronously call
that function is generated. This is the function that calls the do-something
function
declared in the .slint
design markup.
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) -> Result<(), PlatformError>
fn show(&self) -> Result<(), PlatformError>
Convenience function for crate::Window::show()
. This shows the window on the screen
and maintains an extra strong reference while the window is visible. 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) -> Result<(), PlatformError>
fn hide(&self) -> Result<(), PlatformError>
Convenience function for crate::Window::hide()
. Hides the window, so that it is not
visible anymore. The additional strong reference on the associated component, that was
created when show() was called, is dropped.
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) -> Result<(), PlatformError>
fn run(&self) -> Result<(), PlatformError>
This is a convenience function that first calls Self::show
, followed by crate::run_event_loop()
and Self::hide
.
Auto Trait Implementations§
impl Freeze for SampleComponent
impl RefUnwindSafe for SampleComponent
impl !Send for SampleComponent
impl !Sync for SampleComponent
impl Unpin for SampleComponent
impl UnwindSafe for SampleComponent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more