cosmic::iced

Trait Program

source
pub trait Program: Sized {
    type State;
    type Message: Send + Debug + 'static;
    type Theme: Default + DefaultStyle;
    type Renderer: Renderer;
    type Executor: Executor;

    // Required methods
    fn update(
        &self,
        state: &mut Self::State,
        message: Self::Message,
    ) -> Task<Self::Message>;
    fn view<'a>(
        &self,
        state: &'a Self::State,
        window: Id,
    ) -> Element<'a, Self::Message, Self::Theme, Self::Renderer>;

    // Provided methods
    fn title(&self, _state: &Self::State, _window: Id) -> String { ... }
    fn subscription(&self, _state: &Self::State) -> Subscription<Self::Message> { ... }
    fn theme(&self, _state: &Self::State, _window: Id) -> Self::Theme { ... }
    fn style(&self, _state: &Self::State, theme: &Self::Theme) -> Appearance { ... }
    fn scale_factor(&self, _state: &Self::State, _window: Id) -> f64 { ... }
    fn run(
        self,
        settings: Settings,
        window_settings: Option<Settings>,
    ) -> Result<(), Error>
       where Self: 'static,
             Self::State: Default { ... }
    fn run_with<I>(
        self,
        settings: Settings,
        window_settings: Option<Settings>,
        initialize: I,
    ) -> Result<(), Error>
       where Self: 'static,
             I: FnOnce() -> (Self::State, Task<Self::Message>) + 'static { ... }
}
Expand description

The internal definition of a Program.

You should not need to implement this trait directly. Instead, use the methods available in the Program struct.

Required Associated Types§

source

type State

The state of the program.

source

type Message: Send + Debug + 'static

The message of the program.

source

type Theme: Default + DefaultStyle

The theme of the program.

source

type Renderer: Renderer

The renderer of the program.

source

type Executor: Executor

The executor of the program.

Required Methods§

source

fn update( &self, state: &mut Self::State, message: Self::Message, ) -> Task<Self::Message>

source

fn view<'a>( &self, state: &'a Self::State, window: Id, ) -> Element<'a, Self::Message, Self::Theme, Self::Renderer>

Provided Methods§

source

fn title(&self, _state: &Self::State, _window: Id) -> String

source

fn subscription(&self, _state: &Self::State) -> Subscription<Self::Message>

source

fn theme(&self, _state: &Self::State, _window: Id) -> Self::Theme

source

fn style(&self, _state: &Self::State, theme: &Self::Theme) -> Appearance

source

fn scale_factor(&self, _state: &Self::State, _window: Id) -> f64

source

fn run( self, settings: Settings, window_settings: Option<Settings>, ) -> Result<(), Error>
where Self: 'static, Self::State: Default,

Runs the Program.

The state of the Program must implement Default. If your state does not implement Default, use run_with instead.

source

fn run_with<I>( self, settings: Settings, window_settings: Option<Settings>, initialize: I, ) -> Result<(), Error>
where Self: 'static, I: FnOnce() -> (Self::State, Task<Self::Message>) + 'static,

Runs the Program with the given settings, and a closure that creates the initial state.

Object Safety§

This trait is not object safe.

Implementors§