iced_winit::program

Trait Program

Source
pub trait Program
where Self: Sized, Self::Theme: DefaultStyle,
{ type Message: Debug + Send; type Theme; type Executor: Executor; type Renderer: Renderer + Renderer; type Flags; // Required methods fn new(flags: Self::Flags) -> (Self, Task<Self::Message>); fn title(&self, window: Id) -> String; fn update(&mut self, message: Self::Message) -> Task<Self::Message>; fn view( &self, window: Id, ) -> Element<'_, Self::Message, Self::Theme, Self::Renderer>; fn theme(&self, window: Id) -> Self::Theme; // Provided methods fn style(&self, theme: &Self::Theme) -> Appearance { ... } fn subscription(&self) -> Subscription<Self::Message> { ... } fn scale_factor(&self, window: Id) -> f64 { ... } }
Available on crate feature program only.
Expand description

An interactive, native, cross-platform, multi-windowed application.

This trait is the main entrypoint of multi-window Iced. Once implemented, you can run your GUI application by simply calling run. It will run in its own window.

A Program can execute asynchronous actions by returning a [Task] in some of its methods.

When using a Program with the debug feature enabled, a debug view can be toggled by pressing F12.

Required Associated Types§

Source

type Message: Debug + Send

The type of messages your Program will produce.

Source

type Theme

The theme used to draw the Program.

Source

type Executor: Executor

The Executor that will run commands and subscriptions.

The default executor can be a good starting point!

Source

type Renderer: Renderer + Renderer

The graphics backend to use to draw the Program.

Source

type Flags

The data needed to initialize your Program.

Required Methods§

Source

fn new(flags: Self::Flags) -> (Self, Task<Self::Message>)

Initializes the Program with the flags provided to run as part of the Settings.

Here is where you should return the initial state of your app.

Additionally, you can return a [Task] if you need to perform some async action in the background on startup. This is useful if you want to load state from a file, perform an initial HTTP request, etc.

Source

fn title(&self, window: Id) -> String

Returns the current title of the Program.

This title can be dynamic! The runtime will automatically update the title of your application when necessary.

Source

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

Handles a message and updates the state of the Program.

This is where you define your update logic. All the messages, produced by either user interactions or commands, will be handled by this method.

Any [Task] returned will be executed immediately in the background by the runtime.

Source

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

Returns the widgets to display in the Program for the window.

These widgets can produce messages based on user interaction.

Source

fn theme(&self, window: Id) -> Self::Theme

Returns the current Theme of the Program.

Provided Methods§

Source

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

Returns the Style variation of the Theme.

Source

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

Returns the event Subscription for the current state of the application.

The messages produced by the Subscription will be handled by update.

A Subscription will be kept alive as long as you keep returning it!

By default, it returns an empty subscription.

Source

fn scale_factor(&self, window: Id) -> f64

Returns the scale factor of the window of the Program.

It can be used to dynamically control the size of the UI at runtime (i.e. zooming).

For instance, a scale factor of 2.0 will make widgets twice as big, while a scale factor of 0.5 will shrink them to half their size.

By default, it returns 1.0.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§