Crate sixtyfps_interpreter[−][src]
Expand description
SixtyFPS interpreter library
With this crate, you can load a .60 file at runtime and show its UI.
You only need to use this crate if you do not want to use pre-compiled .60
code, which is the normal way to use SixtyFPS, using the sixtyfps
crate
The entry point for this crate is the ComponentCompiler
type, which you can
use to create ComponentDefinition
with the ComponentCompiler::build_from_source
or ComponentCompiler::build_from_path
functions.
Note about async
functions
Compiling a component is async
but in practice, this is only asynchronous if ComponentCompiler::set_file_loader
is set and its future is actually asynchronous. If that is not used, then it is fine to use a very simple
executor, such as the one provided by the spin_on
crate
Examples
This example loads a .60
dynamically from a path and show errors if any:
use sixtyfps_interpreter::{ComponentDefinition, ComponentCompiler}; let mut compiler = ComponentCompiler::default(); let definition = spin_on::spin_on(compiler.build_from_path("hello.60")); sixtyfps_interpreter::print_diagnostics(&compiler.diagnostics()); if let Some(definition) = definition { let instance = definition.create(); instance.run(); }
This example load a .60
from a string and set some properties:
use sixtyfps_interpreter::{ComponentDefinition, ComponentCompiler, Value, SharedString}; let code = r#" MyWin := Window { property <string> my_name; Text { text: "Hello, " + my_name; } } "#; let mut compiler = ComponentCompiler::default(); let definition = spin_on::spin_on(compiler.build_from_source(code.into(), Default::default())); assert!(compiler.diagnostics().is_empty()); let instance = definition.unwrap().create(); instance.set_property("my_name", Value::from(SharedString::from("World"))).unwrap(); instance.run();
Features
display-diagnostics: enable the print_diagnostics
function to show diagnostic in the console output
Modules
This module contains a few function use by tests
Structs
(Re-export from corelib.)
ComponentCompiler is the entry point to the SixtyFPS interpreter that can be used to load .60 files or compile them on-the-fly from a string.
ComponentDefinition is a representation of a compiled component from .60 markup.
This represent an instance of a dynamic component
This structure represent a diagnostic emitted while compiling .60 code.
(Re-export from corelib.)
(Re-export from corelib.)
This type represents a runtime instance of structure in .60
.
A Weak references to a dynamic SixtyFPS components.
This type represents a window towards the windowing system, that’s used to render the scene of a component. It provides API to control windowing system specific aspects such as the position on the screen.
Enums
(Re-export from corelib.)
Error returned by ComponentInstance::invoke_callback
Diagnostics level (error or warning)
Error returned by ComponentInstance::get_property
Error returned by ComponentInstance::set_callback
Error returned by ComponentInstance::set_property
This is a dynamically typed value used in the SixtyFPS interpreter.
It can hold a value of different types, and you should use the
From
or TryInto
traits to access the value.
This enum represents the different public variants of the Value
enum, without
the contained values.
Functions
Print the diagnostics to stderr
Enters the main event loop. This is necessary in order to receive events from the windowing system in order to render to the screen and react to user input.