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_BASE, CONFIG_COLOR_BORDER, CONFIG_COLOR_HOVER,
8 CONFIG_COLOR_SECONDARY,
9};
10use pushrod::render::{make_points, make_size};
11use pushrod::widgets::list_widget::*;
12use sdl2::pixels::Color;
13
14pub fn main() {
15 let sdl_context = sdl2::init().unwrap();
16 let video_subsystem = sdl_context.video().unwrap();
17 let window = video_subsystem
18 .window("pushrod-render list demo", 400, 300)
19 .position_centered()
20 .opengl()
21 .build()
22 .unwrap();
23 let mut engine = Engine::new(400, 300, 60);
24 let mut widget1 = ListWidget::new(make_points(20, 20), make_size(200, 260));
25
26 widget1.set_color(CONFIG_COLOR_BASE, Color::RGB(255, 255, 255));
27 widget1.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
28 widget1.set_color(CONFIG_COLOR_HOVER, Color::RGB(0x90, 0x90, 0xFF));
29 widget1.set_numeric(CONFIG_BORDER_WIDTH, 1);
30
31 widget1.add_item(String::from("Item 1"));
32 widget1.add_item(String::from("Item 2"));
33 widget1.add_item(String::from("Item 3"));
34 widget1.add_item(String::from("Item 4"));
35 widget1.add_item(String::from("Item 5"));
36
37 widget1.on_selected(|x, _widgets, _layout, selected_item| {
38 eprintln!("Selected: {}", selected_item);
39 });
40
41 engine.add_widget(Box::new(widget1), String::from("widget1"));
42
43 engine.run(sdl_context, window);
44}