1use arkham::prelude::*;
2
3#[derive(Copy, Clone)]
4enum Route {
5 Main,
6 Secondary,
7}
8
9fn main() {
10 let _ = App::new(root).insert_state(Route::Main).run();
11}
12
13fn root(ctx: &mut ViewContext, route: State<Route>) {
14 let size = ctx.size();
15 let r = *route.get();
16 ctx.insert((0, 0), "Press Q to quit");
17 match r {
18 Route::Main => {
19 ctx.component(Rect::new((0, 1), size), main_route);
20 }
21 Route::Secondary => {
22 ctx.component(Rect::new((0, 1), size), secondary_route);
23 }
24 }
25}
26
27fn main_route(ctx: &mut ViewContext, kb: Res<Keyboard>, route: State<Route>) {
28 ctx.insert(
29 0,
30 "Welcome to the main screen, press 2 to goto the secondary screen",
31 );
32 if kb.char() == Some('2') {
33 *route.get_mut() = Route::Secondary;
34 ctx.render();
35 }
36}
37
38fn secondary_route(ctx: &mut ViewContext, kb: Res<Keyboard>, route: State<Route>) {
39 ctx.insert(
40 0,
41 "Welcome to the secondary screen, press 1 to goto the main screen",
42 );
43
44 if kb.char() == Some('1') {
45 *route.get_mut() = Route::Main;
46 ctx.render();
47 }
48}