Skip to main content

ForeignController

Trait ForeignController 

Source
pub trait ForeignController:
    Send
    + Sync
    + Debug {
    // Required methods
    fn get_type(&self, key: &str) -> DataType;
    fn change_val(&mut self, key: &str, val: DataType);
    fn as_any(&self) -> &dyn Any;
}
πŸ‘ŽDeprecated since 1.0.2: Use IpcController instead, which works directly on the window. It will be remoed in release 1.0.3.
Expand description

This a boilerplate trait for connection with CLI, it will be replaced by a procedural macro in the future. In the mean time, this function is implemented on a struct you would define in your .slint file. Then state of widgets should be stored as single property of that data type rather than on individual values.

Β§Example

// Wrong Method is you want to handle on-close and is-expanded locally.
export component MyWindow inherits Window {
  in-out property <bool> on-close: false;
  in-out property <bool> is-expanded: true;
  Rectangle {
     // Other widgets will come here.
  }
}

// Correct method
export component MyWindow inherits Window {
  in-out property <MyWinState> state: {on-close: false, is-expanded: true};
  Rectangle {
     // Other widgets will come here.
  }
}
export struct MyWinState {
  on-close: bool,
  is-expanded: true,
}

Required MethodsΒ§

Source

fn get_type(&self, key: &str) -> DataType

πŸ‘ŽDeprecated since 1.0.2: Use IpcController instead, which works directly on the window. It will be remoed in release 1.0.3.

On calling spell-cli -l layer_name look var_name, the cli calls get_type method of the trait with var_name as input.

Source

fn change_val(&mut self, key: &str, val: DataType)

πŸ‘ŽDeprecated since 1.0.2: Use IpcController instead, which works directly on the window. It will be remoed in release 1.0.3.

It is called on spell-cli -l layer_name update key value. as_any is for syncing the changes internally for now and need not be implemented by the end user.

Source

fn as_any(&self) -> &dyn Any

πŸ‘ŽDeprecated since 1.0.2: Use IpcController instead, which works directly on the window. It will be remoed in release 1.0.3.

It is a type needed internally, it’s implementation should return self to avoid undefined behaviour.

ImplementorsΒ§