slint/docs.rs
1// Copyright © SixtyFPS GmbH <[email protected]>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4#![cfg(doc)]
5/*!
6 This is a pseudo module which only exist for documentation purposes as a way to show
7 the Slint documentation as part of rustdoc.
8
9 - The [`generated_code`] module contains an [commented example](generated_code::SampleComponent)
10 of what is generated from the `.slint` file
11*/
12
13// cSpell: ignore rustdoc
14
15/// This module exists only to explain the API of the code generated from `.slint` design markup. Its described structure
16/// is not really contained in the compiled crate.
17pub mod generated_code {
18
19 use crate::ComponentHandle;
20 use crate::Global;
21 use crate::Weak;
22 use crate::Window;
23
24 /// This an example of the API that is generated for a component in `.slint` design markup. This may help you understand
25 /// what functions you can call and how you can pass data in and out.
26 ///
27 /// This is the source code:
28 ///
29 /// ```slint,no-preview
30 /// export component SampleComponent inherits Window {
31 /// in-out property<int> counter;
32 /// // note that dashes will be replaced by underscores in the generated code
33 /// in-out property<string> user-name;
34 /// callback hello;
35 /// public function do-something(x: int) -> bool { return x > 0; }
36 /// // ... maybe more elements here
37 /// }
38 /// ```
39 #[derive(Clone)]
40 pub struct SampleComponent {
41 _marker: core::marker::PhantomData<*mut ()>,
42 }
43 impl SampleComponent {
44 /// Creates a new instance that is reference counted and pinned in memory.
45 pub fn new() -> Result<Self, crate::PlatformError> {
46 unimplemented!()
47 }
48
49 /// A getter is generated for each property declared at the root of the component.
50 /// In this case, this is the getter that returns the value of the `counter`
51 /// property declared in the `.slint` design markup.
52 pub fn get_counter(&self) -> i32 {
53 unimplemented!()
54 }
55 /// A setter is generated for each property declared at the root of the component,
56 /// In this case, this is the setter that sets the value of the `counter` property
57 /// declared in the `.slint` design markup.
58 pub fn set_counter(&self, value: i32) {}
59 /// Returns the value of the `user_name` property declared in the `.slint` design markup.
60 pub fn get_user_name(&self) -> crate::SharedString {
61 unimplemented!()
62 }
63 /// Assigns a new value to the `user_name` property.
64 pub fn set_user_name(&self, value: crate::SharedString) {}
65
66 /// For each callback declared at the root of the component, a function to synchronously call that
67 /// callback is generated. This is the function that calls the `hello` callback declared
68 /// in the `.slint` design markup.
69 pub fn invoke_hello(&self) {}
70 /// For each callback declared at the root of the component, a function connect to that callback
71 /// is generated. This is the function that registers the function f as callback when the
72 /// callback `hello` is emitted. In order to access
73 /// the component in the callback, you'd typically capture a weak reference obtained using
74 /// [`ComponentHandle::as_weak`]
75 /// and then upgrade it to a strong reference when the callback is run:
76 /// ```ignore
77 /// let sample = SampleComponent::new().unwrap();
78 /// let sample_weak = sample.as_weak();
79 /// sample.as_ref().on_hello(move || {
80 /// let sample = sample_weak.unwrap();
81 /// sample.as_ref().set_counter(42);
82 /// });
83 /// ```
84 pub fn on_hello(&self, f: impl Fn() + 'static) {}
85
86 /// For each public function declared at the root of the component, a function to synchronously call
87 /// that function is generated. This is the function that calls the `do-something` function
88 /// declared in the `.slint` design markup.
89 pub fn invoke_do_something(&self, d: i32) -> bool {
90 unimplemented!()
91 }
92 }
93
94 impl ComponentHandle for SampleComponent {
95 #[doc(hidden)]
96 type Inner = SampleComponent;
97
98 /// Returns a new weak pointer.
99 fn as_weak(&self) -> Weak<Self> {
100 unimplemented!()
101 }
102
103 /// Returns a clone of this handle that's a strong reference.
104 fn clone_strong(&self) -> Self {
105 unimplemented!();
106 }
107
108 #[doc(hidden)]
109 fn from_inner(
110 _: vtable::VRc<crate::private_unstable_api::re_exports::ItemTreeVTable, Self::Inner>,
111 ) -> Self {
112 unimplemented!();
113 }
114
115 /// Convenience function for [`crate::Window::show()`]. This shows the window on the screen
116 /// and maintains an extra strong reference while the window is visible. To react
117 /// to events from the windowing system, such as draw requests or mouse/touch input, it is
118 /// still necessary to spin the event loop, using [`crate::run_event_loop`].
119 fn show(&self) -> Result<(), crate::PlatformError> {
120 unimplemented!();
121 }
122
123 /// Convenience function for [`crate::Window::hide()`]. Hides the window, so that it is not
124 /// visible anymore. The additional strong reference on the associated component, that was
125 /// created when show() was called, is dropped.
126 fn hide(&self) -> Result<(), crate::PlatformError> {
127 unimplemented!();
128 }
129
130 /// Returns the Window associated with this component. The window API can be used
131 /// to control different aspects of the integration into the windowing system,
132 /// such as the position on the screen.
133 fn window(&self) -> &Window {
134 unimplemented!()
135 }
136
137 /// This is a convenience function that first calls [`Self::show`], followed by [`crate::run_event_loop()`]
138 /// and [`Self::hide`].
139 fn run(&self) -> Result<(), crate::PlatformError> {
140 unimplemented!();
141 }
142
143 /// This function provides access to instances of global singletons exported in `.slint`.
144 fn global<'a, T: Global<'a, Self>>(&'a self) -> T {
145 unimplemented!()
146 }
147 }
148}
149
150pub mod mcu {
151 #![doc = include_str!("mcu.md")]
152 #[cfg(feature = "renderer-software")]
153 use crate::platform::software_renderer::*;
154 use crate::platform::*;
155 mod slint {
156 pub use crate::*;
157 }
158}
159
160#[i_slint_core_macros::slint_doc]
161pub mod cargo_features {
162 //! # Feature flags and backend selection.
163 //! Use the following feature flags in your Cargo.toml to enable additional features.
164 //!
165 #![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
166 //!
167 //! More information about the backend and renderers is available in the
168 //")]
169 use crate::*;
170}
171
172pub mod type_mappings {
173 #![doc = include_str!("type-mappings.md")]
174 use crate::*;
175}