Merged
Conversation
4 tasks
|
? Where can I find the migration guide? |
|
For those who needs a quick migration guide for this API update, I'll briefly introduce how to turn your code to fit into 0.13. It's quite straightforward (than I thought). If I'm missing something or saying something wrong, please let me know. I hope that it will help other people who are interested in migration!
-impl Application for App {
- type Executor = iced::executor::Default;
- type Flags = ();
- type Message = Message;
- type Theme = Theme;
-
- fn new(_flags: Self::Flags) -> (Self, Command<Message>) {
+impl App {
+ fn new(_flags: ()) -> (Self, Task<Message>) {
fn main() -> iced::Result {
- App::run(Settings::default())
+ iced::application(App::title, App::update, App::view)
+ .run_with(|| App::new(()))
}
fn main() -> iced::Result {
iced::application(App::title, App::update, App::view)
+ .subscription(App::subscription)
+ .theme(App::Theme)
.run_with(|| App::new(()))
}
fn main() -> iced::Result {
- App::run(Settings {
- default_font: FONT,
- ..Default::default()
- })
+ iced::application(App::title, App::update, App::view)
+ .subscription(App::subscription)
+ .theme(App::theme)
+ .default_font(FONT) // < it's me!
+ .run_with(|| App::new(()))
}Note that window options are also flattened into a nice method call. fn main() -> iced::Result {
- App::run(Settings {
- window: window::Settings {
- exit_on_close_request: false,
- ..window::Settings::default()
- },
- ..Default::default()
- })
+ iced::application(App::title, App::update, App::view)
+ .subscription(App::subscription)
+ .exit_on_close_request(false)
+ .run_with(|| App::new(()))
}It should be quite obvious from the doc for the Optional refactoring
fn main() -> iced::Result {
iced::application(App::title, App::update, App::view)
- .run_with(|| App::new(()))
+ .run()
}
-impl App {
- fn new(_flags: ()) -> (Self, Task<Message>) {
+impl Default for App {
+ fn default() -> Self {
fn main() -> iced::Result {
- iced::application(App::title, App::update, App::view)
+ iced::application("Awesome app", App::update, App::view)
.run()
}
impl App {
- fn title(&self) -> String {
- "Awesome app".into()
- }
fn main() -> iced::Result {
- iced::application("Awesome app", App::update, App::view)
- .run()
+ iced::run("Awesome app", App::update, App::view)
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a new
ProgramAPI as a more convenient—although less powerful—alternative to theSandboxandApplicationtraits.The main motivation is lowering the learning curve and entry barrier of the library. Specifically,
Applicationhas a lot of moving parts (e.g.Flags,Executor,Theme,subscription, etc.)The
runFunctionThere is a new
runfunction in the root module that can be used to easily run basic applications, like the classic counter:The
ProgramAPIThe
ProgramAPI can be used to create and run iced applications step by step—without coupling your logic to a trait or a specific type.For instance, here is the new
mainfunction of theclockexample: