1extern crate pushrod;
2extern crate sdl2;
3
4use pushrod::render::engine::Engine;
5use pushrod::render::widget::Widget;
6use pushrod::render::widget_config::{
7 CONFIG_BORDER_WIDTH, CONFIG_COLOR_BORDER, CONFIG_COLOR_HOVER, CONFIG_COLOR_SELECTED,
8};
9use pushrod::render::{make_points, make_size};
10use pushrod::widgets::tile_widget::TileWidget;
11use sdl2::pixels::Color;
12
13pub fn main() {
14 let hover_color = Color::RGBA(0, 0, 0, 255);
15 let selected_color = Color::RGBA(0, 0, 0, 255);
16
17 let sdl_context = sdl2::init().unwrap();
18 let video_subsystem = sdl_context.video().unwrap();
19 let window = video_subsystem
20 .window("pushrod-render tile demo", 370, 100)
21 .position_centered()
22 .opengl()
23 .build()
24 .unwrap();
25 let mut engine = Engine::new(370, 100, 60);
26 let mut tile1 = TileWidget::new(
27 make_points(10, 10),
28 make_size(80, 80),
29 String::from("assets/1.png"),
30 String::from("One"),
31 );
32
33 tile1.set_color(CONFIG_COLOR_HOVER, hover_color);
34 tile1.set_color(CONFIG_COLOR_SELECTED, selected_color);
35 tile1.on_click(|_, _widgets, _layouts, state| {
36 eprintln!("Tile 1 selected: {}", state);
37 });
38
39 let mut tile2 = TileWidget::new(
40 make_points(100, 10),
41 make_size(80, 80),
42 String::from("assets/2.png"),
43 String::from("Two"),
44 );
45
46 tile2.set_color(CONFIG_COLOR_HOVER, hover_color);
47 tile2.set_color(CONFIG_COLOR_SELECTED, selected_color);
48 tile2.on_click(|_, _widgets, _layouts, state| {
49 eprintln!("Tile 2 selected: {}", state);
50 });
51
52 let mut tile3 = TileWidget::new(
53 make_points(190, 10),
54 make_size(80, 80),
55 String::from("assets/3.png"),
56 String::from("Three"),
57 );
58
59 tile3.set_color(CONFIG_COLOR_HOVER, hover_color.clone());
60 tile3.set_color(CONFIG_COLOR_SELECTED, selected_color.clone());
61 tile3.on_click(|_, _widgets, _layouts, state| {
62 eprintln!("Tile 3 selected: {}", state);
63 });
64
65 let mut tile4 = TileWidget::new(
66 make_points(280, 10),
67 make_size(80, 80),
68 String::from("assets/4.png"),
69 String::from("Four"),
70 );
71
72 tile4.set_color(CONFIG_COLOR_HOVER, hover_color.clone());
73 tile4.set_color(CONFIG_COLOR_SELECTED, selected_color.clone());
74 tile4.on_click(|_, _widgets, _layouts, state| {
75 eprintln!("Tile 4 selected: {}", state);
76 });
77
78 engine.add_widget(Box::new(tile1), String::from("tile1"));
79 engine.add_widget(Box::new(tile2), String::from("tile2"));
80 engine.add_widget(Box::new(tile3), String::from("tile3"));
81 engine.add_widget(Box::new(tile4), String::from("tile4"));
82
83 engine.run(sdl_context, window);
84}