Crate sixtyfps_interpreter[][src]

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 assynchronious if ComponentCompiler::set_file_loader is set and its future is actually asynchronious. 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::new();
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::new();
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

testing

This module constains a few function use by tests

Structs

Color

(Re-export from corelib.)

ComponentCompiler

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

ComponentDefinition is a representation of a compiled component from .60 markup.

ComponentInstance

This represent an instance of a dynamic component

Diagnostic

This structure represent a diagnostic emited while compiling .60 code.

SharedString

(Re-export from corelib.)

SharedVector

(Re-export from corelib.)

Struct

This type represents a runtime instance of structure in .60.

WeakComponentInstance

A Weak references to a dynamic SixtyFPS components.

Enums

Brush

(Re-export from corelib.)

CallCallbackError

Error returned by ComponentInstance::invoke_callback

DiagnosticLevel

Diagnostics level (error or warning)

GetPropertyError

Error returned by ComponentInstance::get_property

SetCallbackError

Error returned by ComponentInstance::set_callback

SetPropertyError

Error returned by ComponentInstance::set_property

Value

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.

ValueType

This enum represents the different public variants of the Value enum, without the contained values.

Functions

print_diagnostics

Print the diagnostics to stderr

run_event_loop

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.