mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-03 18:29:09 +00:00
Rust docs: make the main page shorter by moving sections in their modules
This commit is contained in:
parent
2b7aa6ba2d
commit
f7a44d7dfc
4 changed files with 90 additions and 74 deletions
|
@ -143,3 +143,19 @@ pub mod mcu {
|
|||
pub use crate::*;
|
||||
}
|
||||
}
|
||||
|
||||
pub mod cargo_features {
|
||||
//! # Feature flags and backend selection.
|
||||
//! Use the following feature flags in your Cargo.toml to enable additional features.
|
||||
//!
|
||||
#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
|
||||
//!
|
||||
//! More information about the backends is available in the
|
||||
#, "/docs/slint/src/advanced/backends.html)")]
|
||||
use crate::*;
|
||||
}
|
||||
|
||||
pub mod type_mappings {
|
||||
#![doc = include_str!("type-mappings.md")]
|
||||
use crate::*;
|
||||
}
|
||||
|
|
|
@ -9,15 +9,16 @@
|
|||
This crate is the main entry point for embedding user interfaces designed with
|
||||
[Slint](https://slint.rs/) in Rust programs.
|
||||
*/
|
||||
#, "/docs/tutorial/rust)")]
|
||||
#, "/docs/tutorial/rust)")]
|
||||
/*! If you are already familiar with Slint, the following topics provide related information.
|
||||
|
||||
## Related topics
|
||||
## Topics
|
||||
|
||||
*/
|
||||
#, "/docs/slint)")]
|
||||
#, "/docs/slint/src/advanced/backends.html)")]
|
||||
/*! * [Slint on Microcontrollers](docs::mcu)
|
||||
#, "/docs/slint)")]
|
||||
/*! - [Type mappings between .slint and Rust](docs::type_mappings)
|
||||
- [Feature flags and backend selection](docs::cargo_features)
|
||||
- [Slint on Microcontrollers](docs::mcu)
|
||||
|
||||
## How to use this crate:
|
||||
|
||||
|
@ -164,72 +165,6 @@ thread to avoid blocking animations. Use the [`invoke_from_event_loop`] function
|
|||
|
||||
To run a function with a delay or with an interval use a [`Timer`].
|
||||
|
||||
## Type Mappings
|
||||
|
||||
The types used for properties in `.slint` design markup each translate to specific types in Rust.
|
||||
The follow table summarizes the entire mapping:
|
||||
|
||||
| `.slint` Type | Rust Type | Note |
|
||||
| --- | --- | --- |
|
||||
| `angle` | `f32` | The value in degrees |
|
||||
| `array` | [`ModelRc`] | Arrays are represented as models, so that their contents can change dynamically. |
|
||||
| `bool` | `bool` | |
|
||||
| `brush` | [`Brush`] | |
|
||||
| `color` | [`Color`] | |
|
||||
| `duration` | `i64` | At run-time, durations are always represented as signed 64-bit integers with millisecond precision. |
|
||||
| `float` | `f32` | |
|
||||
| `image` | [`Image`] | |
|
||||
| `int` | `i32` | |
|
||||
| `length` | `f32` | At run-time, logical lengths are automatically translated to physical pixels using the device pixel ratio. |
|
||||
| `physical_length` | `f32` | The unit are physical pixels. |
|
||||
| `Point` | [`LogicalPosition`] | A struct with `x` and `y` fields, representing logical coordinates. |
|
||||
| `relative-font-size` | `f32` | Relative font size factor that is multiplied with the `Window.default-font-size` and can be converted to a `length`. |
|
||||
| `string` | [`SharedString`] | A reference-counted string type that can be easily converted to a str reference. |
|
||||
| anonymous object | anonymous tuple | The fields are in alphabetical order. |
|
||||
| enumeration | `enum` of the same name | The values are converted to CamelCase |
|
||||
| structure | `struct` of the same name | |
|
||||
|
||||
For user defined structures in the .slint, an extra struct is generated.
|
||||
For example, if the `.slint` contains
|
||||
```slint,no-preview
|
||||
export struct MyStruct {
|
||||
foo: int,
|
||||
bar: string,
|
||||
names: [string],
|
||||
}
|
||||
```
|
||||
|
||||
The following struct would be generated:
|
||||
|
||||
```rust
|
||||
#[derive(Default, Clone, Debug, PartialEq)]
|
||||
struct MyStruct {
|
||||
foo : i32,
|
||||
bar: slint::SharedString,
|
||||
names: slint::ModelRc<slint::SharedString>,
|
||||
}
|
||||
```
|
||||
|
||||
The `.slint` file allows you to utilize Rust attributes and features for defining structures using the `@rust-attr()` directive.
|
||||
This enables you to customize the generated code by applying additional traits, derivations, or annotations.
|
||||
Consider the following structure defined in the `.slint` file with Rust attributes:
|
||||
```slint,ignore
|
||||
@rust-attr(derive(serde::Serialize, serde::Deserialize))
|
||||
struct MyStruct {
|
||||
foo : i32,
|
||||
}
|
||||
```
|
||||
|
||||
Based on this structure, the following Rust code would be generated:
|
||||
|
||||
```rust
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Default, Clone, Debug, PartialEq)]
|
||||
struct MyStruct {
|
||||
foo : i32,
|
||||
}
|
||||
```
|
||||
|
||||
## Exported Global singletons
|
||||
|
||||
*/
|
||||
|
@ -249,8 +184,7 @@ The global can be accessed with the [`ComponentHandle::global()`] function, or w
|
|||
|
||||
See the [documentation of the `Global` trait](Global) for an example.
|
||||
*/
|
||||
//! ## Feature flags
|
||||
#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
|
||||
|
||||
#![warn(missing_docs)]
|
||||
#![deny(unsafe_code)]
|
||||
#![doc(html_logo_url = "https://slint.dev/logo/slint-logo-square-light.svg")]
|
||||
|
|
66
api/rs/slint/type-mappings.md
Normal file
66
api/rs/slint/type-mappings.md
Normal file
|
@ -0,0 +1,66 @@
|
|||
<!-- Copyright © SixtyFPS GmbH <info@slint.dev> ; SPDX-License-Identifier: MIT -->
|
||||
# Type Mappings
|
||||
|
||||
The types used for properties in `.slint` design markup each translate to specific types in Rust.
|
||||
The follow table summarizes the entire mapping:
|
||||
|
||||
| `.slint` Type | Rust Type | Note |
|
||||
| --- | --- | --- |
|
||||
| `angle` | `f32` | The value in degrees |
|
||||
| `array` | [`ModelRc`] | Arrays are represented as models, so that their contents can change dynamically. |
|
||||
| `bool` | `bool` | |
|
||||
| `brush` | [`Brush`] | |
|
||||
| `color` | [`Color`] | |
|
||||
| `duration` | `i64` | At run-time, durations are always represented as signed 64-bit integers with millisecond precision. |
|
||||
| `float` | `f32` | |
|
||||
| `image` | [`Image`] | |
|
||||
| `int` | `i32` | |
|
||||
| `length` | `f32` | At run-time, logical lengths are automatically translated to physical pixels using the device pixel ratio. |
|
||||
| `physical_length` | `f32` | The unit are physical pixels. |
|
||||
| `Point` | [`LogicalPosition`] | A struct with `x` and `y` fields, representing logical coordinates. |
|
||||
| `relative-font-size` | `f32` | Relative font size factor that is multiplied with the `Window.default-font-size` and can be converted to a `length`. |
|
||||
| `string` | [`SharedString`] | A reference-counted string type that can be easily converted to a str reference. |
|
||||
| anonymous object | anonymous tuple | The fields are in alphabetical order. |
|
||||
| enumeration | `enum` of the same name | The values are converted to CamelCase |
|
||||
| structure | `struct` of the same name | |
|
||||
|
||||
For user defined structures in the .slint, an extra struct is generated.
|
||||
For example, if the `.slint` contains
|
||||
```slint,ignore
|
||||
export struct MyStruct {
|
||||
foo: int,
|
||||
bar: string,
|
||||
names: [string],
|
||||
}
|
||||
```
|
||||
|
||||
The following struct would be generated:
|
||||
|
||||
```rust
|
||||
#[derive(Default, Clone, Debug, PartialEq)]
|
||||
struct MyStruct {
|
||||
foo : i32,
|
||||
bar: slint::SharedString,
|
||||
names: slint::ModelRc<slint::SharedString>,
|
||||
}
|
||||
```
|
||||
|
||||
The `.slint` file allows you to utilize Rust attributes and features for defining structures using the `@rust-attr()` directive.
|
||||
This enables you to customize the generated code by applying additional traits, derivations, or annotations.
|
||||
Consider the following structure defined in the `.slint` file with Rust attributes:
|
||||
```slint,ignore
|
||||
@rust-attr(derive(serde::Serialize, serde::Deserialize))
|
||||
struct MyStruct {
|
||||
foo : i32,
|
||||
}
|
||||
```
|
||||
|
||||
Based on this structure, the following Rust code would be generated:
|
||||
|
||||
```rust
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Default, Clone, Debug, PartialEq)]
|
||||
struct MyStruct {
|
||||
foo : i32,
|
||||
}
|
||||
```
|
|
@ -51,7 +51,7 @@ callback. These will be shell escaped.
|
|||
Example: Imagine we have a myfile.slint looking like this:
|
||||
|
||||
```slint
|
||||
MyApp := Window {
|
||||
export component MyApp inherits Window {
|
||||
callback open-url(string);
|
||||
//...
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue