From d225b2738d80124d6911372ef23ae9ccf37d3099 Mon Sep 17 00:00:00 2001 From: Taylor Holliday Date: Sun, 24 Dec 2023 09:56:38 -0800 Subject: [PATCH] Use run --- README.md | 20 ++++++++++++-------- examples/action.rs | 5 +++-- examples/any_view.rs | 5 +++-- examples/async.rs | 5 +++-- examples/background.rs | 5 +++-- examples/basic.rs | 5 +++-- examples/calc.rs | 5 +++-- examples/canvas.rs | 5 +++-- examples/clip.rs | 5 +++-- examples/counter.rs | 5 +++-- examples/counter2.rs | 5 +++-- examples/counter_list.rs | 5 +++-- examples/counter_redux.rs | 5 +++-- examples/counter_redux_nested.rs | 5 +++-- examples/counter_redux_redux.rs | 5 +++-- examples/custom_modifier.rs | 5 +++-- examples/env.rs | 5 +---- examples/font_size.rs | 5 +++-- examples/gestures.rs | 5 +++-- examples/key_mods.rs | 5 +++-- examples/knob.rs | 5 +++-- examples/lens.rs | 5 +++-- examples/list.rs | 4 +--- examples/menu.rs | 5 +++-- examples/nested.rs | 5 +++-- examples/shapes.rs | 5 +++-- examples/slider.rs | 5 +++-- examples/text_editor.rs | 5 +++-- examples/text_layout.rs | 4 ++-- examples/todo_list.rs | 5 +++-- examples/toggle.rs | 2 +- examples/zstack.rs | 5 +++-- 32 files changed, 98 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index 18a99a80..0c1e4ca7 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ obligatory Counter (`cargo run --example counter`): use rui::*; fn main() { - rui(state( + state( || 1, |count, cx| { vstack(( @@ -38,7 +38,8 @@ fn main() { .padding(Auto), )) }, - )); + ) + .run() } ``` @@ -50,7 +51,7 @@ some shapes (`cargo run --example shapes`): use rui::*; fn main() { - rui(vstack(( + vstack(( circle() .color(RED_HIGHLIGHT) .padding(Auto), @@ -58,7 +59,8 @@ fn main() { .corner_radius(5.0) .color(AZURE_HIGHLIGHT) .padding(Auto) - ))); + )) + .run() } ``` @@ -70,7 +72,7 @@ canvas for gpu drawing (`cargo run --example canvas`): use rui::*; fn main() { - rui(canvas(|_, rect, vger| { + canvas(|_, rect, vger| { vger.translate(rect.center() - LocalPoint::zero()); let paint = vger.linear_gradient( @@ -83,7 +85,8 @@ fn main() { let radius = 100.0; vger.fill_circle(LocalPoint::zero(), radius, paint); - })); + }) + .run() } ``` @@ -110,13 +113,14 @@ fn my_slider(s: impl Binding) -> impl View { } fn main() { - rui(state(MyState::default, |state, cx| + state(MyState::default, |state, cx| map( cx[state].value, move |v, cx| cx[state].value = v, |s, _| my_slider(s), ), - )); + ) + .run() } ``` diff --git a/examples/action.rs b/examples/action.rs index b6a4eb6e..2155bfd6 100644 --- a/examples/action.rs +++ b/examples/action.rs @@ -3,7 +3,7 @@ use rui::*; struct MyAction {} fn main() { - rui(vstack(( + vstack(( rectangle() .tap(|_| { println!("rect tapped"); @@ -12,5 +12,6 @@ fn main() { .padding(Auto), text("tap the rectangle to send an action"), )) - .handle(|_, _: &MyAction| println!("action received"))); + .handle(|_, _: &MyAction| println!("action received")) + .run() } diff --git a/examples/any_view.rs b/examples/any_view.rs index 54099fe8..11eb021b 100644 --- a/examples/any_view.rs +++ b/examples/any_view.rs @@ -1,12 +1,13 @@ use rui::*; fn main() { - rui(list(vec![7, 42], |i| { + list(vec![7, 42], |i| { if *i == 7 { any_view(circle()) } else { any_view(rectangle()) } .padding(Auto) - })); + }) + .run() } diff --git a/examples/async.rs b/examples/async.rs index 0d4b0e93..e4e8d0b5 100644 --- a/examples/async.rs +++ b/examples/async.rs @@ -5,7 +5,7 @@ use std::{ }; fn main() { - rui(state( + state( || "task not started".to_string(), |s, cx| { hstack(( @@ -19,5 +19,6 @@ fn main() { text(&cx[s]), )) }, - )); + ) + .run() } diff --git a/examples/background.rs b/examples/background.rs index 8b803f72..89028636 100644 --- a/examples/background.rs +++ b/examples/background.rs @@ -1,7 +1,8 @@ use rui::*; fn main() { - rui("this is a test" + "this is a test" .padding(Auto) - .background(rectangle().corner_radius(5.0).color(AZURE_HIGHLIGHT))); + .background(rectangle().corner_radius(5.0).color(AZURE_HIGHLIGHT)) + .run() } diff --git a/examples/basic.rs b/examples/basic.rs index d07608b9..a6fe5801 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,10 +1,11 @@ use rui::*; fn main() { - rui(vstack(( + vstack(( "This is a test.", rectangle().flex(), "This is another test.", rectangle().flex(), - ))); + )) + .run() } diff --git a/examples/calc.rs b/examples/calc.rs index 525afaa5..ebed7a8d 100644 --- a/examples/calc.rs +++ b/examples/calc.rs @@ -26,7 +26,7 @@ fn calc_button(title: &str, callback: impl Fn(&mut Context) + 'static) -> impl V } fn main() { - rui(state( + state( || String::from("0"), |s, cx| { vstack(( @@ -62,5 +62,6 @@ fn main() { )), )) }, - )) + ) + .run() } diff --git a/examples/canvas.rs b/examples/canvas.rs index 0c6afbcd..3ebbfa2b 100644 --- a/examples/canvas.rs +++ b/examples/canvas.rs @@ -1,7 +1,7 @@ use rui::*; fn main() { - rui(canvas(|_, rect, vger| { + canvas(|_, rect, vger| { vger.translate(rect.center() - LocalPoint::zero()); let paint = vger.linear_gradient( @@ -14,5 +14,6 @@ fn main() { let radius = 100.0; vger.fill_circle(LocalPoint::zero(), radius, paint); - })); + }) + .run() } diff --git a/examples/clip.rs b/examples/clip.rs index f9215ffe..680dcc55 100644 --- a/examples/clip.rs +++ b/examples/clip.rs @@ -1,10 +1,11 @@ use rui::*; fn main() { - rui(hstack(( + hstack(( text("This text is clipped.") // .offset([0.0, 0.0]) .clip(), text("This text isn't clipped."), - ))) + )) + .run() } diff --git a/examples/counter.rs b/examples/counter.rs index a468724e..b56110d4 100644 --- a/examples/counter.rs +++ b/examples/counter.rs @@ -1,7 +1,7 @@ use rui::*; fn main() { - rui(state( + state( || 1, |count, cx| { vstack(( @@ -12,5 +12,6 @@ fn main() { .padding(Auto), )) }, - )); + ) + .run() } diff --git a/examples/counter2.rs b/examples/counter2.rs index aba442f9..2f2ebb6b 100644 --- a/examples/counter2.rs +++ b/examples/counter2.rs @@ -1,7 +1,7 @@ use rui::*; fn main() { - rui(state( + state( || 1, |count, cx| { vstack(( @@ -16,5 +16,6 @@ fn main() { .padding(Auto), )) }, - )); + ) + .run() } diff --git a/examples/counter_list.rs b/examples/counter_list.rs index d312ac1c..d31b57c4 100644 --- a/examples/counter_list.rs +++ b/examples/counter_list.rs @@ -1,7 +1,7 @@ use rui::*; fn main() { - rui(state(Counters::default, |counters, cx| { + state(Counters::default, |counters, cx| { vstack(( list(cx[counters].ids(), move |&i| { with_cx(move |cx| { @@ -23,7 +23,8 @@ fn main() { format!("total: {}", cx[counters].sum_counters()).padding(Auto), button("add counter", move |cx| cx[counters].add_counter()).padding(Auto), )) - })); + }) + .run() } #[derive(Default, Debug)] diff --git a/examples/counter_redux.rs b/examples/counter_redux.rs index b089e84c..2d0b8757 100644 --- a/examples/counter_redux.rs +++ b/examples/counter_redux.rs @@ -24,11 +24,12 @@ fn reduce(state: &mut AppState, action: &Action) { } fn main() { - rui(redux(AppState::new, reduce, |state| { + redux(AppState::new, reduce, |state| { vstack(( format!("{}", state.count).padding(Auto), button_a("increment", Action::Increment).padding(Auto), button_a("decrement", Action::Decrement).padding(Auto), )) - })); + }) + .run() } diff --git a/examples/counter_redux_nested.rs b/examples/counter_redux_nested.rs index 3f0bdcf9..04aba6f9 100644 --- a/examples/counter_redux_nested.rs +++ b/examples/counter_redux_nested.rs @@ -27,7 +27,7 @@ fn reduce(state: &mut AppState, action: &Action) { } fn main() { - rui(redux(AppState::new, reduce, |app_state| { + redux(AppState::new, reduce, |app_state| { vstack(( format!("{}", app_state.count).padding(Auto), state( @@ -45,5 +45,6 @@ fn main() { }, ), )) - })); + }) + .run() } diff --git a/examples/counter_redux_redux.rs b/examples/counter_redux_redux.rs index ea722dc4..242f686e 100644 --- a/examples/counter_redux_redux.rs +++ b/examples/counter_redux_redux.rs @@ -49,7 +49,7 @@ fn reduce_local(state: &mut LocalState, action: &LocalAction) -> Action { } fn main() { - rui(redux(AppState::new, reduce, |app_state| { + redux(AppState::new, reduce, |app_state| { vstack(( format!("{}", app_state.count).padding(Auto), redux( @@ -58,5 +58,6 @@ fn main() { |_| button_a("increment every 5 clicks", LocalAction::Increment), ), )) - })); + }) + .run() } diff --git a/examples/custom_modifier.rs b/examples/custom_modifier.rs index 9ef4989b..6e293f75 100644 --- a/examples/custom_modifier.rs +++ b/examples/custom_modifier.rs @@ -38,8 +38,9 @@ where } fn main() { - rui(vstack(( + vstack(( my_control().padding(Auto), my_control().agro().padding(Auto), - ))) + )) + .run() } diff --git a/examples/env.rs b/examples/env.rs index 1e095c6a..40f03904 100644 --- a/examples/env.rs +++ b/examples/env.rs @@ -22,8 +22,5 @@ fn my_control() -> impl View { } fn main() { - rui(vstack(( - my_control(), - my_control().env(MyControlType::Agro), - ))) + vstack((my_control(), my_control().env(MyControlType::Agro))).run() } diff --git a/examples/font_size.rs b/examples/font_size.rs index c00559fc..ad39b31d 100644 --- a/examples/font_size.rs +++ b/examples/font_size.rs @@ -1,7 +1,7 @@ use rui::*; fn main() { - rui(state( + state( || 0.0, |size, cx| { let s = (cx[size] * 100.0) as u32; @@ -11,5 +11,6 @@ fn main() { hslider(size), )) }, - )); + ) + .run() } diff --git a/examples/gestures.rs b/examples/gestures.rs index ee1281e8..b851ca80 100644 --- a/examples/gestures.rs +++ b/examples/gestures.rs @@ -14,7 +14,7 @@ fn anim_to(current: &mut LocalOffset, target: LocalOffset) -> bool { } fn main() { - rui(hstack(( + hstack(( circle() .color(RED_HIGHLIGHT.alpha(0.8)) .tap(|_cx| println!("tapped circle")) @@ -43,5 +43,6 @@ fn main() { .padding(Auto) }) }), - ))); + )) + .run() } diff --git a/examples/key_mods.rs b/examples/key_mods.rs index 45871a71..c812bb4c 100644 --- a/examples/key_mods.rs +++ b/examples/key_mods.rs @@ -1,7 +1,7 @@ use rui::*; fn main() { - rui(hstack(( + hstack(( zstack(( circle() .color(RED_HIGHLIGHT.alpha(0.8)) @@ -25,5 +25,6 @@ fn main() { "Handle key pressed" .key(|cx, key| println!("key: {:?}, key modifiers state: {:?}", key, cx.key_mods)) .padding(Auto), - ))); + )) + .run() } diff --git a/examples/knob.rs b/examples/knob.rs index 0e52a5f6..1ffc2533 100644 --- a/examples/knob.rs +++ b/examples/knob.rs @@ -6,7 +6,7 @@ struct MyState { } fn main() { - rui(state(MyState::default, |state, cx| { + state(MyState::default, |state, cx| { vstack(( format!("value: {:?}", cx[state]).padding(Auto), map( @@ -15,5 +15,6 @@ fn main() { |s, _| knob(s).padding(Auto), ), )) - })); + }) + .run() } diff --git a/examples/lens.rs b/examples/lens.rs index 73d121ba..40885935 100644 --- a/examples/lens.rs +++ b/examples/lens.rs @@ -8,12 +8,13 @@ struct MyState { make_lens!(ValueLens, MyState, f32, value); fn main() { - rui(state(MyState::default, |state, cx| { + state(MyState::default, |state, cx| { vstack(( cx[state].value.font_size(10).padding(Auto), hslider(bind(state, ValueLens {})) .thumb_color(RED_HIGHLIGHT) .padding(Auto), )) - })); + }) + .run() } diff --git a/examples/list.rs b/examples/list.rs index 13ab4daa..80303824 100644 --- a/examples/list.rs +++ b/examples/list.rs @@ -5,7 +5,5 @@ fn main() { let ids = (0usize..data.len()).collect(); - rui(list(ids, move |id| { - hstack((circle(), data[*id].to_string())) - })); + list(ids, move |id| hstack((circle(), data[*id].to_string()))).run() } diff --git a/examples/menu.rs b/examples/menu.rs index 116fa204..e6b530f8 100644 --- a/examples/menu.rs +++ b/examples/menu.rs @@ -4,7 +4,7 @@ use rui::*; // Run with: cargo run --example menu --no-default-features --features tao fn main() { - rui(hstack(( + hstack(( circle() .color(RED_HIGHLIGHT) .padding(Auto) @@ -20,5 +20,6 @@ fn main() { .command_group((command("Custom 2:Four") .action(|| println!("four")) .hotkey(HotKey::KeyF),)), - ))); + )) + .run() } diff --git a/examples/nested.rs b/examples/nested.rs index e0b8b88c..31400809 100644 --- a/examples/nested.rs +++ b/examples/nested.rs @@ -8,7 +8,7 @@ fn my_rectangle() -> impl View { } fn main() { - rui(hstack(( + hstack(( my_rectangle(), vstack(( my_rectangle(), @@ -20,5 +20,6 @@ fn main() { )), )), )), - ))); + )) + .run() } diff --git a/examples/shapes.rs b/examples/shapes.rs index a73a3a2b..a061b562 100644 --- a/examples/shapes.rs +++ b/examples/shapes.rs @@ -1,11 +1,12 @@ use rui::*; fn main() { - rui(hstack(( + hstack(( circle().color(RED_HIGHLIGHT).padding(Auto), rectangle() .corner_radius(5.0) .color(AZURE_HIGHLIGHT) .padding(Auto), - ))); + )) + .run() } diff --git a/examples/slider.rs b/examples/slider.rs index 1a5a7689..8c100a0b 100644 --- a/examples/slider.rs +++ b/examples/slider.rs @@ -16,11 +16,12 @@ fn my_slider(s: impl Binding) -> impl View { } fn main() { - rui(state(MyState::default, |state_handle, cx| { + state(MyState::default, |state_handle, cx| { map( cx[state_handle].value, move |v, cx| cx[state_handle].value = v, |s, _| my_slider(s), ) - })); + }) + .run() } diff --git a/examples/text_editor.rs b/examples/text_editor.rs index 3d7c290e..36bb41ab 100644 --- a/examples/text_editor.rs +++ b/examples/text_editor.rs @@ -2,7 +2,7 @@ use rui::*; fn main() { let lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; - rui(vstack(( + vstack(( state( move || lorem.to_string(), |state, _| text_editor(state).padding(Auto), @@ -23,5 +23,6 @@ fn main() { .corner_radius(5.0), ) .padding(Auto), - ))); + )) + .run() } diff --git a/examples/text_layout.rs b/examples/text_layout.rs index 414cf6cc..e0bbf3e4 100644 --- a/examples/text_layout.rs +++ b/examples/text_layout.rs @@ -1,7 +1,7 @@ use rui::*; fn main() { - rui(canvas(|_cx, rect, vger| { + canvas(|_cx, rect, vger| { let lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; @@ -40,5 +40,5 @@ fn main() { vger.text(lorem, font_size, TEXT_COLOR, break_width); - }).padding(Auto)); + }).padding(Auto).run() } diff --git a/examples/todo_list.rs b/examples/todo_list.rs index 96c12fc2..591b3b72 100644 --- a/examples/todo_list.rs +++ b/examples/todo_list.rs @@ -27,7 +27,8 @@ fn todo_list(todos: impl Binding>) -> impl View { } fn main() { - rui(state(std::vec::Vec::new, move |todos, _| { + state(std::vec::Vec::new, move |todos, _| { vstack((add_button(todos), todo_list(todos))) - })); + }) + .run() } diff --git a/examples/toggle.rs b/examples/toggle.rs index dfeb19ec..a172ca8f 100644 --- a/examples/toggle.rs +++ b/examples/toggle.rs @@ -1,5 +1,5 @@ use rui::*; fn main() { - rui(state(|| false, |s, _| toggle(s))); + state(|| false, |s, _| toggle(s)).run() } diff --git a/examples/zstack.rs b/examples/zstack.rs index 34b2fb72..317c85ee 100644 --- a/examples/zstack.rs +++ b/examples/zstack.rs @@ -1,8 +1,9 @@ use rui::*; fn main() { - rui(zstack(( + zstack(( "This is a test.", circle().color(RED_HIGHLIGHT).padding(Auto), - ))); + )) + .run() }