Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Utility functions #19

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ fn app_logic(data: &mut AppData) -> impl View<AppData> {
}

pub fn main() {
let app = App::new(AppData::default(), app_logic);
AppLauncher::new(app).run();
App::new(AppData::default(), app_logic).run()
}
3 changes: 1 addition & 2 deletions examples/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ fn app_logic(_: &mut ()) -> impl View<()> {
}

fn main() {
let app = App::new((), app_logic);
AppLauncher::new(app).run();
App::new((), app_logic).run()
}
15 changes: 15 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use tokio::runtime::Runtime;
use crate::event::{AsyncWake, EventResult};
use crate::id::IdPath;
use crate::widget::{CxState, EventCx, LayoutCx, PaintCx, Pod, UpdateCx, WidgetState};
use crate::AppLauncher;
use crate::{
event::Event,
id::Id,
Expand Down Expand Up @@ -271,6 +272,20 @@ where
false
}
}

/// Runs the app inside a window.
///
/// This is a thin convinience wrapper around [AppLauncher](xilem::AppLauncher)
pub fn run_with_title(self, title: impl Into<String>) {
AppLauncher::new(self).title(title).run()
}

/// Runs the app inside a window.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation here should mention that this is a convenience around AppLauncher, and point the user in the direction of that struct when they need to do something more complex.

Same for run_with_title.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I think this would make the code more engaging and rewarding to discover for oneself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is addressed in the latest commit

///
/// This is a thin convinience wrapper around [AppLauncher](xilem::AppLauncher)
pub fn run(self) {
AppLauncher::new(self).run()
}
}

impl<T, V: View<T>> App<T, V> {
Expand Down
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use xilem::{button, App, AppLauncher, View};
use xilem::{button, App, View};

fn app_logic(_data: &mut ()) -> impl View<()> {
button("click me", |_| println!("clicked"))
Expand All @@ -15,6 +15,5 @@ fn main() {
window_handle.show();
app.run(None);
*/
let app = App::new((), app_logic);
AppLauncher::new(app).run()
App::new((), app_logic).run()
}