Skip to content

Commit f391759

Browse files
Take root widget directly in WindowDesc::new (#1559)
* Take widget directly in WindowDesc::new * Update CHANGELOG.md * Update documentation
1 parent 4c865b9 commit f391759

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+50
-50
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ You can find its changes [documented below](#070---2021-01-01).
2121
### Changed
2222

2323
- Warn on unhandled Commands ([#1533] by [@Maan2003])
24+
- `WindowDesc::new` takes the root widget directly instead of a closure ([#1559] by [@lassipulkkinen])
2425

2526
### Deprecated
2627

@@ -411,6 +412,7 @@ Last release without a changelog :(
411412
[@Maan2003]: https://github.com/Maan2003
412413
[@derekdreery]: https://github.com/derekdreery
413414
[@MaximilianKoestler]: https://github.com/MaximilianKoestler
415+
[@lassipulkkinen]: https://github.com/lassipulkkinen
414416

415417
[#599]: https://github.com/linebender/druid/pull/599
416418
[#611]: https://github.com/linebender/druid/pull/611
@@ -608,6 +610,7 @@ Last release without a changelog :(
608610
[#1533]: https://github.com/linebender/druid/pull/1533
609611
[#1534]: https://github.com/linebender/druid/pull/1534
610612
[#1254]: https://github.com/linebender/druid/pull/1254
613+
[#1559]: https://github.com/linebender/druid/pull/1559
611614

612615
[Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master
613616
[0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use druid::widget::{Button, Flex, Label};
3939
use druid::{AppLauncher, LocalizedString, PlatformError, Widget, WidgetExt, WindowDesc};
4040

4141
fn main() -> Result<(), PlatformError> {
42-
let main_window = WindowDesc::new(ui_builder);
42+
let main_window = WindowDesc::new(ui_builder());
4343
let data = 0_u32;
4444
AppLauncher::with_window(main_window)
4545
.use_simple_logger()

druid/examples/anim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl Widget<()> for AnimWidget {
8181
}
8282

8383
pub fn main() {
84-
let window = WindowDesc::new(|| AnimWidget { t: 0.0 }).title(
84+
let window = WindowDesc::new(AnimWidget { t: 0.0 }).title(
8585
LocalizedString::new("anim-demo-window-title")
8686
.with_placeholder("You spin me right round..."),
8787
);

druid/examples/async_event.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use druid::{AppLauncher, Color, Selector, Target, WidgetExt, WindowDesc};
3131
const SET_COLOR: Selector<Color> = Selector::new("event-example.set-color");
3232

3333
pub fn main() {
34-
let window = WindowDesc::new(make_ui).title("External Event Demo");
34+
let window = WindowDesc::new(make_ui()).title("External Event Demo");
3535

3636
let launcher = AppLauncher::with_window(window);
3737

druid/examples/blocking_function.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ impl AppDelegate<AppState> for Delegate {
100100
}
101101

102102
fn main() {
103-
let main_window = WindowDesc::new(ui_builder).title(LocalizedString::new("Blocking functions"));
103+
let main_window =
104+
WindowDesc::new(ui_builder()).title(LocalizedString::new("Blocking functions"));
104105
AppLauncher::with_window(main_window)
105106
.delegate(Delegate {})
106107
.launch(AppState::default())

druid/examples/calc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ fn build_calc() -> impl Widget<CalcState> {
243243
}
244244

245245
pub fn main() {
246-
let window = WindowDesc::new(build_calc)
246+
let window = WindowDesc::new(build_calc())
247247
.window_size((223., 300.))
248248
.resizable(false)
249249
.title(

druid/examples/cursor.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ impl AppState {
106106
}
107107

108108
pub fn main() {
109-
let main_window = WindowDesc::new(ui_builder).title(LocalizedString::new("Blocking functions"));
109+
let main_window =
110+
WindowDesc::new(ui_builder()).title(LocalizedString::new("Blocking functions"));
110111
let cursor_image = ImageBuf::from_data(include_bytes!("./assets/PicWithAlpha.png")).unwrap();
111112
// The (0,0) refers to where the "hotspot" is located, so where the mouse actually points.
112113
// (0,0) is the top left, and (cursor_image.width(), cursor_image.width()) the bottom right.

druid/examples/custom_widget.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl Widget<String> for CustomWidget {
151151
}
152152

153153
pub fn main() {
154-
let window = WindowDesc::new(|| CustomWidget {}).title(LocalizedString::new("Fancy Colors"));
154+
let window = WindowDesc::new(CustomWidget {}).title(LocalizedString::new("Fancy Colors"));
155155
AppLauncher::with_window(window)
156156
.use_simple_logger()
157157
.launch("Druid + Piet".to_string())

druid/examples/either.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn ui_builder() -> impl Widget<AppState> {
4545
}
4646

4747
pub fn main() {
48-
let main_window = WindowDesc::new(ui_builder).title("Switcheroo");
48+
let main_window = WindowDesc::new(ui_builder()).title("Switcheroo");
4949
AppLauncher::with_window(main_window)
5050
.use_simple_logger()
5151
.launch(AppState::default())

druid/examples/event_viewer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ fn make_list_item() -> impl Widget<LoggedEvent> {
322322

323323
pub fn main() {
324324
//describe the main window
325-
let main_window = WindowDesc::new(build_root_widget)
325+
let main_window = WindowDesc::new(build_root_widget())
326326
.title("Event Viewer")
327327
.window_size((760.0, 680.0));
328328

druid/examples/flex.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ fn make_ui() -> impl Widget<AppState> {
317317
}
318318

319319
pub fn main() {
320-
let main_window = WindowDesc::new(make_ui)
320+
let main_window = WindowDesc::new(make_ui())
321321
.window_size((720., 600.))
322322
.with_min_size((620., 300.))
323323
.title("Flex Container Options");

druid/examples/game_of_life.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ fn make_widget() -> impl Widget<AppData> {
416416
}
417417

418418
pub fn main() {
419-
let window = WindowDesc::new(make_widget)
419+
let window = WindowDesc::new(make_widget())
420420
.window_size(Size {
421421
width: 800.0,
422422
height: 800.0,

druid/examples/hello.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct HelloState {
2929

3030
pub fn main() {
3131
// describe the main window
32-
let main_window = WindowDesc::new(build_root_widget)
32+
let main_window = WindowDesc::new(build_root_widget())
3333
.title("Hello World!")
3434
.window_size((400.0, 400.0));
3535

druid/examples/hello_web/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn main() {
3939
//
4040
// Window title is set in index.html and window size is ignored on the web,
4141
// so can we leave those off.
42-
let main_window = WindowDesc::new(build_root_widget);
42+
let main_window = WindowDesc::new(build_root_widget());
4343

4444
// create the initial app state
4545
let initial_state = HelloState {

druid/examples/identity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct OurData {
4040
}
4141

4242
pub fn main() {
43-
let window = WindowDesc::new(make_ui).title("identity example");
43+
let window = WindowDesc::new(make_ui()).title("identity example");
4444
let data = OurData {
4545
counter_one: 0,
4646
counter_two: 0,

druid/examples/image.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fn make_ui() -> impl Widget<AppState> {
204204
}
205205

206206
pub fn main() {
207-
let main_window = WindowDesc::new(make_ui)
207+
let main_window = WindowDesc::new(make_ui())
208208
.window_size((650., 450.))
209209
.title("Flex Container Options");
210210

druid/examples/invalidation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use druid::{AppLauncher, Color, Data, Lens, LocalizedString, Point, WidgetExt, W
2424
use instant::Instant;
2525

2626
pub fn main() {
27-
let window = WindowDesc::new(build_widget).title(
27+
let window = WindowDesc::new(build_widget()).title(
2828
LocalizedString::new("invalidate-demo-window-title").with_placeholder("Invalidate demo"),
2929
);
3030
let state = AppState {

druid/examples/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn build_app() -> impl Widget<u32> {
6666
}
6767

6868
pub fn main() {
69-
let window = WindowDesc::new(build_app).title("Very flexible");
69+
let window = WindowDesc::new(build_app()).title("Very flexible");
7070

7171
AppLauncher::with_window(window)
7272
.use_simple_logger()

druid/examples/lens.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use druid::widget::{CrossAxisAlignment, Flex, Label, TextBox};
1919
use druid::{AppLauncher, Data, Env, Lens, LocalizedString, Widget, WidgetExt, WindowDesc};
2020

2121
pub fn main() {
22-
let main_window = WindowDesc::new(ui_builder)
22+
let main_window = WindowDesc::new(ui_builder())
2323
.title(LocalizedString::new("lens-demo-window-title").with_placeholder("Lens Demo"));
2424
let data = MyComplexState {
2525
term: "hello".into(),

druid/examples/list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct AppData {
3030
}
3131

3232
pub fn main() {
33-
let main_window = WindowDesc::new(ui_builder)
33+
let main_window = WindowDesc::new(ui_builder())
3434
.title(LocalizedString::new("list-demo-window-title").with_placeholder("List Demo"));
3535
// Set our initial data
3636
let left = vector![1, 2];

druid/examples/markdown_preview.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<W: Widget<AppState>> Controller<AppState, W> for RichTextRebuilder {
6464

6565
pub fn main() {
6666
// describe the main window
67-
let main_window = WindowDesc::new(build_root_widget)
67+
let main_window = WindowDesc::new(build_root_widget())
6868
.title(WINDOW_TITLE)
6969
.menu(make_menu())
7070
.window_size((700.0, 600.0));

druid/examples/multiwin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct State {
3939
}
4040

4141
pub fn main() {
42-
let main_window = WindowDesc::new(ui_builder)
42+
let main_window = WindowDesc::new(ui_builder())
4343
.menu(make_menu(&State::default()))
4444
.title(
4545
LocalizedString::new("multiwin-demo-window-title").with_placeholder("Many windows!"),
@@ -157,7 +157,7 @@ impl AppDelegate<State> for Delegate {
157157
) -> Handled {
158158
match cmd {
159159
_ if cmd.is(sys_cmds::NEW_FILE) => {
160-
let new_win = WindowDesc::new(ui_builder)
160+
let new_win = WindowDesc::new(ui_builder())
161161
.menu(make_menu(data))
162162
.window_size((data.selected as f64 * 100.0 + 300.0, 500.0));
163163
ctx.new_window(new_win);

druid/examples/open_save.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use druid::{
2323
struct Delegate;
2424

2525
pub fn main() {
26-
let main_window = WindowDesc::new(ui_builder)
26+
let main_window = WindowDesc::new(ui_builder())
2727
.title(LocalizedString::new("open-save-demo").with_placeholder("Opening/Saving Demo"));
2828
let data = "Type here.".to_owned();
2929
AppLauncher::with_window(main_window)

druid/examples/panels.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn build_app() -> impl Widget<()> {
9292
}
9393

9494
pub fn main() -> Result<(), PlatformError> {
95-
let main_window = WindowDesc::new(build_app)
95+
let main_window = WindowDesc::new(build_app())
9696
.title(LocalizedString::new("panels-demo-window-title").with_placeholder("Fancy Boxes!"));
9797
AppLauncher::with_window(main_window)
9898
.use_simple_logger()

druid/examples/scroll.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use druid::widget::{Flex, Padding, Scroll};
2222
use druid::{AppLauncher, Data, Insets, LocalizedString, Rect, WindowDesc};
2323

2424
pub fn main() {
25-
let window = WindowDesc::new(build_widget)
25+
let window = WindowDesc::new(build_widget())
2626
.title(LocalizedString::new("scroll-demo-window-title").with_placeholder("Scroll demo"));
2727
AppLauncher::with_window(window)
2828
.use_simple_logger()

druid/examples/scroll_colors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn build_app() -> impl Widget<u32> {
4242
}
4343

4444
pub fn main() {
45-
let main_window = WindowDesc::new(build_app).title(
45+
let main_window = WindowDesc::new(build_app()).title(
4646
LocalizedString::new("scroll-colors-demo-window-title").with_placeholder("Rainbows!"),
4747
);
4848
let data = 0_u32;

druid/examples/split_demo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn build_app() -> impl Widget<u32> {
7777
}
7878

7979
pub fn main() {
80-
let window = WindowDesc::new(build_app)
80+
let window = WindowDesc::new(build_app())
8181
.title(LocalizedString::new("split-demo-window-title").with_placeholder("Split Demo"));
8282
AppLauncher::with_window(window)
8383
.use_simple_logger()

druid/examples/styled_text.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl Display for AppData {
4848
}
4949

5050
pub fn main() -> Result<(), PlatformError> {
51-
let main_window = WindowDesc::new(ui_builder).title(
51+
let main_window = WindowDesc::new(ui_builder()).title(
5252
LocalizedString::new("styled-text-demo-window-title").with_placeholder("Type Styler"),
5353
);
5454
let data = AppData {

druid/examples/sub_window.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct HelloState {
4545

4646
pub fn main() {
4747
// describe the main window
48-
let main_window = WindowDesc::new(build_root_widget)
48+
let main_window = WindowDesc::new(build_root_widget())
4949
.title(WINDOW_TITLE)
5050
.window_size((400.0, 400.0));
5151

druid/examples/svg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use druid::{
2222
};
2323

2424
pub fn main() {
25-
let main_window = WindowDesc::new(ui_builder)
25+
let main_window = WindowDesc::new(ui_builder())
2626
.title(LocalizedString::new("svg-demo-window-title").with_placeholder("Rawr!"));
2727
let data = 0_u32;
2828
AppLauncher::with_window(main_window)

druid/examples/switches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn build_widget() -> impl Widget<DemoState> {
6767
}
6868

6969
pub fn main() {
70-
let window = WindowDesc::new(build_widget)
70+
let window = WindowDesc::new(build_widget())
7171
.title(LocalizedString::new("switch-demo-window-title").with_placeholder("Switch Demo"));
7272
AppLauncher::with_window(window)
7373
.use_simple_logger()

druid/examples/tabs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct AppState {
7272

7373
pub fn main() {
7474
// describe the main window
75-
let main_window = WindowDesc::new(build_root_widget)
75+
let main_window = WindowDesc::new(build_root_widget())
7676
.title("Tabs")
7777
.window_size((700.0, 400.0));
7878

druid/examples/text.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl Controller<AppState, RawLabel<AppState>> for LabelController {
7979

8080
pub fn main() {
8181
// describe the main window
82-
let main_window = WindowDesc::new(build_root_widget)
82+
let main_window = WindowDesc::new(build_root_widget())
8383
.title(WINDOW_TITLE)
8484
.window_size((400.0, 600.0));
8585

druid/examples/timer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Widget<u32> for SimpleBox {
116116
}
117117

118118
pub fn main() {
119-
let window = WindowDesc::new(|| TimerWidget {
119+
let window = WindowDesc::new(TimerWidget {
120120
timer_id: TimerToken::INVALID,
121121
simple_box: WidgetPod::new(SimpleBox),
122122
pos: Point::ZERO,

druid/examples/value_formatting/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct AppData {
3737
}
3838

3939
pub fn main() {
40-
let main_window = WindowDesc::new(ui_builder).title("Formatting and Validation");
40+
let main_window = WindowDesc::new(ui_builder()).title("Formatting and Validation");
4141

4242
let data = AppData {
4343
dollars: 12.2,

druid/examples/view_switcher.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct AppState {
2424
}
2525

2626
pub fn main() {
27-
let main_window = WindowDesc::new(make_ui).title(LocalizedString::new("View Switcher"));
27+
let main_window = WindowDesc::new(make_ui()).title(LocalizedString::new("View Switcher"));
2828
let data = AppState {
2929
current_view: 0,
3030
current_text: "Edit me!".to_string(),

druid/examples/widget_gallery.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ enum MyRadio {
4848
}
4949

5050
pub fn main() {
51-
let main_window = WindowDesc::new(ui_builder).title("Widget Gallery");
51+
let main_window = WindowDesc::new(ui_builder()).title("Widget Gallery");
5252
// Set our initial data
5353
let data = AppData {
5454
label_data: "test".into(),

druid/src/app.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,13 @@ pub struct PendingWindow<T> {
8686

8787
impl<T: Data> PendingWindow<T> {
8888
/// Create a pending window from any widget.
89-
pub fn new<W, F>(root: F) -> PendingWindow<T>
89+
pub fn new<W>(root: W) -> PendingWindow<T>
9090
where
9191
W: Widget<T> + 'static,
92-
F: FnOnce() -> W + 'static,
9392
{
9493
// This just makes our API slightly cleaner; callers don't need to explicitly box.
9594
PendingWindow {
96-
root: Box::new(root()),
95+
root: Box::new(root),
9796
title: LocalizedString::new("app-name").into(),
9897
menu: MenuDesc::platform_default(),
9998
size_policy: WindowSizePolicy::User,
@@ -381,16 +380,12 @@ impl WindowConfig {
381380
}
382381

383382
impl<T: Data> WindowDesc<T> {
384-
/// Create a new `WindowDesc`, taking a function that will generate the root
385-
/// [`Widget`] for this window.
386-
///
387-
/// It is possible that a `WindowDesc` can be reused to launch multiple windows.
383+
/// Create a new `WindowDesc`, taking the root [`Widget`] for this window.
388384
///
389385
/// [`Widget`]: trait.Widget.html
390-
pub fn new<W, F>(root: F) -> WindowDesc<T>
386+
pub fn new<W>(root: W) -> WindowDesc<T>
391387
where
392388
W: Widget<T> + 'static,
393-
F: FnOnce() -> W + 'static,
394389
{
395390
WindowDesc {
396391
pending: PendingWindow::new(root),

0 commit comments

Comments
 (0)