Skip to content

Commit

Permalink
Use run
Browse files Browse the repository at this point in the history
  • Loading branch information
wtholliday committed Dec 24, 2023
1 parent e32a8c3 commit d225b27
Show file tree
Hide file tree
Showing 32 changed files with 98 additions and 72 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ obligatory Counter (`cargo run --example counter`):
use rui::*;

fn main() {
rui(state(
state(
|| 1,
|count, cx| {
vstack((
Expand All @@ -38,7 +38,8 @@ fn main() {
.padding(Auto),
))
},
));
)
.run()
}
```

Expand All @@ -50,15 +51,16 @@ some shapes (`cargo run --example shapes`):
use rui::*;

fn main() {
rui(vstack((
vstack((
circle()
.color(RED_HIGHLIGHT)
.padding(Auto),
rectangle()
.corner_radius(5.0)
.color(AZURE_HIGHLIGHT)
.padding(Auto)
)));
))
.run()
}
```

Expand All @@ -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(
Expand All @@ -83,7 +85,8 @@ fn main() {

let radius = 100.0;
vger.fill_circle(LocalPoint::zero(), radius, paint);
}));
})
.run()
}
```

Expand All @@ -110,13 +113,14 @@ fn my_slider(s: impl Binding<f32>) -> 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()
}
```

Expand Down
5 changes: 3 additions & 2 deletions examples/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rui::*;
struct MyAction {}

fn main() {
rui(vstack((
vstack((
rectangle()
.tap(|_| {
println!("rect tapped");
Expand All @@ -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()
}
5 changes: 3 additions & 2 deletions examples/any_view.rs
Original file line number Diff line number Diff line change
@@ -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()
}
5 changes: 3 additions & 2 deletions examples/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

fn main() {
rui(state(
state(
|| "task not started".to_string(),
|s, cx| {
hstack((
Expand All @@ -19,5 +19,6 @@ fn main() {
text(&cx[s]),
))
},
));
)
.run()
}
5 changes: 3 additions & 2 deletions examples/background.rs
Original file line number Diff line number Diff line change
@@ -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()
}
5 changes: 3 additions & 2 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use rui::*;

fn main() {
rui(vstack((
vstack((
"This is a test.",
rectangle().flex(),
"This is another test.",
rectangle().flex(),
)));
))
.run()
}
5 changes: 3 additions & 2 deletions examples/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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((
Expand Down Expand Up @@ -62,5 +62,6 @@ fn main() {
)),
))
},
))
)
.run()
}
5 changes: 3 additions & 2 deletions examples/canvas.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -14,5 +14,6 @@ fn main() {

let radius = 100.0;
vger.fill_circle(LocalPoint::zero(), radius, paint);
}));
})
.run()
}
5 changes: 3 additions & 2 deletions examples/clip.rs
Original file line number Diff line number Diff line change
@@ -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()
}
5 changes: 3 additions & 2 deletions examples/counter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rui::*;

fn main() {
rui(state(
state(
|| 1,
|count, cx| {
vstack((
Expand All @@ -12,5 +12,6 @@ fn main() {
.padding(Auto),
))
},
));
)
.run()
}
5 changes: 3 additions & 2 deletions examples/counter2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rui::*;

fn main() {
rui(state(
state(
|| 1,
|count, cx| {
vstack((
Expand All @@ -16,5 +16,6 @@ fn main() {
.padding(Auto),
))
},
));
)
.run()
}
5 changes: 3 additions & 2 deletions examples/counter_list.rs
Original file line number Diff line number Diff line change
@@ -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| {
Expand All @@ -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)]
Expand Down
5 changes: 3 additions & 2 deletions examples/counter_redux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
5 changes: 3 additions & 2 deletions examples/counter_redux_nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -45,5 +45,6 @@ fn main() {
},
),
))
}));
})
.run()
}
5 changes: 3 additions & 2 deletions examples/counter_redux_redux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -58,5 +58,6 @@ fn main() {
|_| button_a("increment every 5 clicks", LocalAction::Increment),
),
))
}));
})
.run()
}
5 changes: 3 additions & 2 deletions examples/custom_modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ where
}

fn main() {
rui(vstack((
vstack((
my_control().padding(Auto),
my_control().agro().padding(Auto),
)))
))
.run()
}
5 changes: 1 addition & 4 deletions examples/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
5 changes: 3 additions & 2 deletions examples/font_size.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rui::*;

fn main() {
rui(state(
state(
|| 0.0,
|size, cx| {
let s = (cx[size] * 100.0) as u32;
Expand All @@ -11,5 +11,6 @@ fn main() {
hslider(size),
))
},
));
)
.run()
}
5 changes: 3 additions & 2 deletions examples/gestures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -43,5 +43,6 @@ fn main() {
.padding(Auto)
})
}),
)));
))
.run()
}
5 changes: 3 additions & 2 deletions examples/key_mods.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rui::*;

fn main() {
rui(hstack((
hstack((
zstack((
circle()
.color(RED_HIGHLIGHT.alpha(0.8))
Expand All @@ -25,5 +25,6 @@ fn main() {
"Handle key pressed"
.key(|cx, key| println!("key: {:?}, key modifiers state: {:?}", key, cx.key_mods))
.padding(Auto),
)));
))
.run()
}
5 changes: 3 additions & 2 deletions examples/knob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -15,5 +15,6 @@ fn main() {
|s, _| knob(s).padding(Auto),
),
))
}));
})
.run()
}
Loading

0 comments on commit d225b27

Please sign in to comment.