[−][src]Crate sixtyfps
SixtyFPS
This crate is the main entry point for embedding user interfaces designed with SixtyFPS UI in Rust programs.
Included in this documentation is also the language reference.
How to use:
The user interfaces are described in the .60
design markup language. There are two ways
of including the design in Rust:
- The
.60
code is inline in a macro. - The
.60
code in external files compiled withbuild.rs
This markup code is translated to Rust code and each component is turned into a Rust struct with functions to instantiated, show or access properties. This documentation includes an example of how the API looks like.
The .60 code in a macro
This method combines your Rust code with the .60
design markup in one file, using a macro:
sixtyfps::sixtyfps!{ HelloWorld := Window { Text { text: "hello world"; color: green; } } } fn main() { HelloWorld::new().run() }
The .60 file in external files compiled with build.rs
This method allows you to a separate .60
file on the file system, which works well if
your design becomes bigger and you split it up across multiple files. You need to use a
so-called build script
to trigger the compilation of the .60
file.
In your Cargo.toml:
[package]
...
build = "build.rs"
[dependencies]
sixtyfps = "0.0.2"
...
[build-dependencies]
sixtyfps-build = "0.0.2"
In the build.rs
file:
fn main() { sixtyfps_build::compile("ui/hello.60").unwrap(); }
Then in your main file
sixtyfps::include_modules!(); fn main() { HelloWorld::new().run() }
Generated components
As of now, only the last component of a .60 source is generated. It is planed to generate all exported components.
The component is generated and re-exported at the location of the include_modules!
or sixtyfps!
macro.
it consist of a struct of the same name of the component.
For example, if you have export MyComponent := Window { /*...*/ }
in the .60 file, it will create a struct MyComponent{ /*...*/ }
.
This documentation contains a documented generated component: docs::generated_code::SampleComponent
.
The following associated function are added to the component:
fn new() -> Pin<Rc<Self>>
: to instantiate the component.fn run(self: Pin<Rc<Self>>)
: to show and start the event loop.fn as_weak(self: Pin<Rc<Self>>)
: Convenience to create a weak reference pointer.
For each top-level property
- A setter
fn set_<property_name>(&self, value: <PropertyType>)
- A getter
fn get_<property_name>(self: Pin<&Self>) -> <PropertyType>
For each top-level signal
fn emit_<signal_name>(self: Pin<&Self>)
: to emit the signalfn on_<signal_name>(self: Pin<&Self>, callback: impl Fn(<SignalArgs>) + 'static)
: to set the signal handler.
Type Mappings
The types used for properties in .60
design markup each translate to specific types in Rust.
The follow table summarizes the entire mapping:
.60 Type | Rust Type | Note |
---|---|---|
int | i32 | |
float | f32 | |
string | SharedString | A reference-counted string type that can be easily converted to a str reference. |
color | Color | |
length | f32 | The unit are physical pixels. |
logical_length | f32 | At run-time, logical lengths are automatically translated to physical pixels using the device pixel ratio. |
duration | i64 | At run-time, durations are always represented as signed 64-bit integers with milisecond precision. |
structure | struct of the same name |
For user defined structures in the .60, an extra struct is generated.
For example, if the .60
contains
export MyStruct := {
property <int> foo;
property <string> bar;
}
The following struct would be generated:
#[derive(Default, Clone, Debug, PartialEq)] struct MyStruct { foo : i32, bar: sixtyfps::SharedString, }
Modules
docs | This is a pseudo module which only exist for documentation purposes as a way to show the SixtyFPS documentation as part of rustdoc. |
testing | This module contains functions useful for unit tests |
Macros
include_modules | Include the code generated with the sixtyfps-build crate from the build script. After calling |
sixtyfps | This macro allows you to use the |
Structs
ARGBColor | ARGBColor stores the red, green, blue and alpha components of a color
with the precision of the generic parameter T. For example if T is f32,
the values are normalized between 0 and 1. If T is u8, they values range
is 0 to 255.
This is merely a helper class for use with |
Color | Color represents a color in the SixtyFPS run-time, represented using 8-bit channels for red, green, blue and the alpha (opacity). It can be conveniently constructed and destructured using the to_ and from_ (a)rgb helper functions: |
ModelNotify | Dispatch notification from a |
ModelPeer | Represent a handle to a view that listen to change to a model. See |
SharedArray | SharedArray holds a reference-counted read-only copy of |
SharedString | A string type used by the SixtyFPS run-time. |
StandardListViewItem | Represend an item in a StandardListView |
VecModel | A model backed by an SharedArray |
Traits
Model | A Model is providing Data for the Repeater or ListView elements of the |
Type Definitions
ModelHandle | Properties of type array in the .60 language are represented as an Option of an Rc of somthing implemented the Model trait |