Trait iced::pure::Application
source · [−]pub trait Application: Sized {
type Executor: Executor;
type Message: Debug + Send;
type Flags;
fn new(flags: Self::Flags) -> (Self, Command<Self::Message>);
fn title(&self) -> String;
fn update(&mut self, message: Self::Message) -> Command<Self::Message>;
fn view(&self) -> Element<'_, Self::Message>;
fn subscription(&self) -> Subscription<Self::Message> { ... }
fn mode(&self) -> Mode { ... }
fn background_color(&self) -> Color { ... }
fn scale_factor(&self) -> f64 { ... }
fn should_exit(&self) -> bool { ... }
fn run(settings: Settings<Self::Flags>) -> Result
where
Self: 'static,
{ ... }
}
pure
only.Expand description
A pure version of Application
.
Unlike the impure version, the view
method of this trait takes an
immutable reference to self
and returns a pure Element
.
Required Associated Types
The Executor
that will run commands and subscriptions.
The default executor can be a good starting point!
The type of messages your Application
will produce.
The data needed to initialize your Application
.
Required Methods
Initializes the Application
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 Command
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.
Returns the current title of the Application
.
This title can be dynamic! The runtime will automatically update the title of your application when necessary.
Handles a message and updates the state of the Application
.
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 Command
returned will be executed immediately in the background.
Returns the widgets to display in the Application
.
These widgets can produce messages based on user interaction.
Provided Methods
fn subscription(&self) -> Subscription<Self::Message>
fn subscription(&self) -> Subscription<Self::Message>
Returns the event Subscription
for the current state of the
application.
A Subscription
will be kept alive as long as you keep returning it,
and the messages produced will be handled by
update
.
By default, this method returns an empty Subscription
.
Returns the current Application
mode.
The runtime will automatically transition your application if a new mode is returned.
Currently, the mode only has an effect in native platforms.
By default, an application will run in windowed mode.
fn background_color(&self) -> Color
fn background_color(&self) -> Color
Returns the background color of the Application
.
By default, it returns Color::WHITE
.
fn scale_factor(&self) -> f64
fn scale_factor(&self) -> f64
Returns the scale factor of the Application
.
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
.
fn should_exit(&self) -> bool
fn should_exit(&self) -> bool
Returns whether the Application
should be terminated.
By default, it returns false
.
Runs the Application
.
On native platforms, this method will take control of the current thread
until the Application
exits.
On the web platform, this method will NOT return unless there is an
Error
during startup.