Skip to main content

Widget

Trait Widget 

Source
pub trait Widget {
Show 37 methods // Required methods fn as_any(&mut self) -> &mut dyn Any; fn get_config(&mut self) -> &mut WidgetConfig; fn get_system_properties(&mut self) -> &mut HashMap<i32, String>; fn get_callbacks(&mut self) -> &mut CallbackRegistry; // Provided methods fn draw( &mut self, _c: &mut Canvas<Window>, _t: &mut TextureCache, ) -> Option<&Texture> { ... } fn mouse_entered( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], ) { ... } fn mouse_exited( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], ) { ... } fn mouse_moved( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _points: Points, ) { ... } fn mouse_scrolled( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _points: Points, ) { ... } fn button_clicked( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _button: u8, _clicks: u8, _state: bool, ) { ... } fn tick( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], ) { ... } fn other_event( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _event: Event, ) { ... } fn tick_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], ) { ... } fn mouse_entered_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], ) { ... } fn mouse_exited_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], ) { ... } fn mouse_moved_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _points: Points, ) { ... } fn mouse_scrolled_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _points: Points, ) { ... } fn button_clicked_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _button: u8, _clicks: u8, _state: bool, ) { ... } fn on_config_changed(&mut self, _k: u8, _v: Config) { ... } fn set_point(&mut self, config: u8, x: i32, y: i32) { ... } fn set_color(&mut self, config: u8, color: Color) { ... } fn set_numeric(&mut self, config: u8, value: i32) { ... } fn set_text(&mut self, config: u8, text: String) { ... } fn set_toggle(&mut self, config: u8, flag: bool) { ... } fn set_compass(&mut self, config: u8, value: CompassPosition) { ... } fn get_point(&mut self, k: u8) -> Points { ... } fn get_size(&mut self, k: u8) -> Size { ... } fn get_color(&mut self, k: u8) -> Color { ... } fn get_numeric(&mut self, k: u8) -> i32 { ... } fn get_text(&mut self, k: u8) -> String { ... } fn get_toggle(&mut self, k: u8) -> bool { ... } fn get_compass(&mut self, k: u8) -> CompassPosition { ... } fn set_origin(&mut self, _origin: Points) { ... } fn set_size(&mut self, _size: Vec<u32>) { ... } fn get_drawing_area(&mut self) -> Rect { ... } fn is_invalidated(&mut self) -> bool { ... } fn set_invalidated(&mut self, flag: bool) { ... }
}
Expand description

This trait is shared by all Widget objects that have a presence on the screen. Functions that must be implemented are documented in the trait.

§Implementation Notes

If no custom get_config function is defined, and no custom get_system_properties function is defined, you can omit the definition of both, and use the default_widget_properties!() macro to auto-generate this code in your impl of this trait. Keep in mind, however, that these automatically generated implementation details could change in future releases of this library, so it is best to use the default implementation if possible.

Required Methods§

Source

fn as_any(&mut self) -> &mut dyn Any

Retrieves this Widget as an Any object so that it can be downcast using downcast_ref to a struct that implements the Widget trait.

Source

fn get_config(&mut self) -> &mut WidgetConfig

Retrieves the WidgetConfig object for this Widget.

Source

fn get_system_properties(&mut self) -> &mut HashMap<i32, String>

Retrieves a HashMap containing system properties used by the Pushrod event engine.

Source

fn get_callbacks(&mut self) -> &mut CallbackRegistry

Retrieves a Callback registry for this Widget.

Provided Methods§

Source

fn draw( &mut self, _c: &mut Canvas<Window>, _t: &mut TextureCache, ) -> Option<&Texture>

Draws the widget. If you wish to modify the canvas object, you must declare it as mut in your implementation (ie fn draw(&mut self, mut canvas: Canvas<Window>)). The _canvas is the currently active drawing canvas at the time this function is called. This called during the draw loop of the Engine. This returns a reference to the stored Texture object within the Widget. It is then copied to the canvas, and displayed in the display loop. In this function, you can just return a reference to the Texture if no invalidation state was set, otherwise, the draw can be re-performed, and the Texture returned. If the drawing function returns no texture, return a None, and it will not be rendered during the display loop, but it will still be called. A TextureCache is provided in case your Widget needs to cache an image or a font store.

So, why not just call draw each time, if the Engine already handles the calling of the draw for you when an object needs invalidation? This is to avoid excess CPU usage. You can call the draw method each time: all it will do is return the reference to the already drawn Texture if you do this. It’s only at the time the contents needs to be redrawn will the logic for the draw take place (so long the invalidated state is obeyed)

Source

fn mouse_entered( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], )

When a mouse enters the bounds of the Widget, this function is triggered. This function implementation is optional.

Source

fn mouse_exited( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], )

When a mouse exits the bounds of the Widget, this function is triggered. This function implementation is optional.

Source

fn mouse_moved( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _points: Points, )

When a mouse moves within the bounds of the Widget, this function is triggered. It contains the X and Y coordinates relative to the bounds of the Widget. The points start at 0x0. This function implementation is optional.

Source

fn mouse_scrolled( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _points: Points, )

When a mouse scroll is triggered within the bounds of the Widget, this function is triggered. Movement along the X axis indicate horizontal movement, where the Y axis indicates vertical movement. Positive movement means to the right or down, respectively. Negative movement means to the left or up, respectively. This function implementation is optional.

Source

fn button_clicked( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _button: u8, _clicks: u8, _state: bool, )

When a mouse button is clicked within (or outside of) the bounds of the Widget, this function is called. If a mouse button is clicked, and the mouse leaves the bounds of the Widget, the mouse release event will still be triggered for the last Widget which received the mouse down state. This prevents Widgets from becoming confused. This behavior is tracked by the main loop, not by the Widget code. Therefore, when a mouse button is released outside of the bounds of this Widget, you must adjust your state accordingly, if you pay attention to the button_clicked function. This function implementation is optional.

Source

fn tick(&mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer])

When a timer tick goes by (ie. a frame is displayed on the screen), this function is called. This function implementation is optional.

Source

fn other_event( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _event: Event, )

When an Event is sent to the application that is not handled by the Engine::run loop, this method is called, sending the unhandled Event to the currently active Widget. This behavior is subject to change as the Engine::run loop is modified to handle more Events.

Source

fn tick_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], )

This calls the on_tick callback. This is implemented by the default_widget_callbacks! macro, so you do not need to implement it. However, you need to call this function if you wish to honor an on_tick callback.

Source

fn mouse_entered_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], )

This calls the on_mouse_entered callback. This is implemented by the default_widget_callbacks! macro, so you do not need to implement it. However, you need to call this function if you wish to honor an on_mouse_entered callback.

Source

fn mouse_exited_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], )

This calls the on_mouse_exited callback. This is implemented by the default_widget_callbacks! macro, so you do not need to implement it. However, you need to call this function if you wish to honor an on_mouse_exited callback.

Source

fn mouse_moved_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _points: Points, )

This calls the on_mouse_moved callback. This is implemented by the default_widget_callbacks! macro, so you do not need to implement it. However, you need to call this function if you wish to honor an on_mouse_moved callback.

Source

fn mouse_scrolled_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _points: Points, )

This calls the on_mouse_scrolled callback. This is implemented by the default_widget_callbacks! macro, so you do not need to implement it. However, you need to call this function if you wish to honor an on_mouse_scrolled callback.

Source

fn button_clicked_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _button: u8, _clicks: u8, _state: bool, )

This calls the on_button_clicked callback. This is implemented by the default_widget_callbacks! macro, so you do not need to implement it. However, you need to call this function if you wish to honor an on_button_clicked callback.

Source

fn on_config_changed(&mut self, _k: u8, _v: Config)

This callback is called when a setter is used to configure a value. It is not called when a call to get_config() using the setter is called, so it is best to use the top-level setters and getters for the configuration values - at least, until the get_config() call can be made private.

Source

fn set_point(&mut self, config: u8, x: i32, y: i32)

Sets a point for a configuration key.

Source

fn set_color(&mut self, config: u8, color: Color)

Sets a color for a configuration key.

Examples found in repository?
examples/push_button.rs (line 33)
16pub fn main() {
17    let sdl_context = sdl2::init().unwrap();
18    let video_subsystem = sdl_context.video().unwrap();
19    let window = video_subsystem
20        .window("pushrod-render push button demo", 400, 100)
21        .position_centered()
22        .opengl()
23        .build()
24        .unwrap();
25    let mut engine = Engine::new(400, 100, 30);
26    let mut button1 = PushButtonWidget::new(
27        make_points(20, 20),
28        make_size(360, 60),
29        String::from("Click me!"),
30        40,
31    );
32
33    button1.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
34    button1.set_numeric(CONFIG_BORDER_WIDTH, 2);
35    button1.on_click(|_x, _widgets, _layouts| {
36        eprintln!("Click me clicked!");
37    });
38
39    engine.add_widget(Box::new(button1), String::from("button1"));
40
41    engine.run(sdl_context, window);
42}
More examples
Hide additional examples
examples/tab_bar.rs (line 35)
15pub fn main() {
16    let sdl_context = sdl2::init().unwrap();
17    let video_subsystem = sdl_context.video().unwrap();
18    let window = video_subsystem
19        .window("pushrod-render tab bar demo", 400, 300)
20        .position_centered()
21        .opengl()
22        .build()
23        .unwrap();
24    let mut engine = Engine::new(400, 300, 60);
25    let mut widget1 = TabBarWidget::new(
26        make_points(20, 20),
27        make_size(360, 30),
28        vec![
29            String::from("First"),
30            String::from("Second"),
31            String::from("Third"),
32        ],
33    );
34
35    widget1.set_color(CONFIG_COLOR_BASE, Color::RGB(255, 255, 255));
36    widget1.set_color(CONFIG_COLOR_HOVER, Color::RGB(192, 192, 255));
37    widget1.on_tab_selected(|_, _, _, selected_tab| {
38        eprintln!("Selected tab: {}", selected_tab);
39    });
40
41    engine.add_widget(Box::new(widget1), String::from("widget1"));
42
43    engine.run(sdl_context, window);
44}
examples/progress.rs (line 23)
11pub fn main() {
12    let sdl_context = sdl2::init().unwrap();
13    let video_subsystem = sdl_context.video().unwrap();
14    let window = video_subsystem
15        .window("pushrod-render progress demo", 400, 180)
16        .position_centered()
17        .opengl()
18        .build()
19        .unwrap();
20    let mut engine = Engine::new(400, 180, 60);
21    let mut widget1 = ProgressWidget::new(make_points(20, 20), make_size(360, 40), 25);
22
23    widget1.set_color(CONFIG_COLOR_SECONDARY, Color::RGB(255, 0, 0));
24
25    let mut widget2 = ProgressWidget::new(make_points(20, 70), make_size(360, 40), 50);
26
27    widget2.set_color(CONFIG_COLOR_SECONDARY, Color::RGB(255, 0, 0));
28
29    let mut widget3 = ProgressWidget::new(make_points(20, 120), make_size(360, 40), 75);
30
31    widget3.set_color(CONFIG_COLOR_SECONDARY, Color::RGB(255, 0, 0));
32
33    engine.add_widget(Box::new(widget1), String::from("widget1"));
34    engine.add_widget(Box::new(widget2), String::from("widget2"));
35    engine.add_widget(Box::new(widget3), String::from("widget3"));
36
37    engine.run(sdl_context, window);
38}
examples/list.rs (line 26)
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}
examples/toggle_button.rs (line 34)
16pub fn main() {
17    let sdl_context = sdl2::init().unwrap();
18    let video_subsystem = sdl_context.video().unwrap();
19    let window = video_subsystem
20        .window("pushrod-render toggle button demo", 400, 100)
21        .position_centered()
22        .opengl()
23        .build()
24        .unwrap();
25    let mut engine = Engine::new(400, 100, 60);
26    let mut button1 = ToggleButtonWidget::new(
27        make_points(20, 20),
28        make_size(170, 60),
29        String::from("1"),
30        40,
31        false,
32    );
33
34    button1.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
35    button1.set_numeric(CONFIG_BORDER_WIDTH, 2);
36    button1.on_toggle(|_, _widgets, _layouts, _state| {
37        eprintln!("1 Toggled: {}", _state);
38    });
39
40    let mut button2 = ToggleButtonWidget::new(
41        make_points(210, 20),
42        make_size(170, 60),
43        String::from("2"),
44        40,
45        true,
46    );
47
48    button2.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
49    button2.set_numeric(CONFIG_BORDER_WIDTH, 2);
50    button2.on_toggle(|_, _widgets, _layouts, _state| {
51        eprintln!("2 Toggled: {}", _state);
52    });
53
54    engine.add_widget(Box::new(button1), String::from("button1"));
55    engine.add_widget(Box::new(button2), String::from("button2"));
56
57    engine.run(sdl_context, window);
58}
examples/timer.rs (line 37)
25pub fn main() {
26    let sdl_context = sdl2::init().unwrap();
27    let video_subsystem = sdl_context.video().unwrap();
28    let window = video_subsystem
29        .window("pushrod-render timer demo", 400, 180)
30        .position_centered()
31        .opengl()
32        .build()
33        .unwrap();
34    let mut engine = Engine::new(400, 180, 30);
35    let mut widget1 = ProgressWidget::new(make_points(20, 20), make_size(360, 40), 25);
36
37    widget1.set_color(CONFIG_COLOR_SECONDARY, Color::RGB(255, 0, 0));
38    widget1.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 255));
39
40    let mut widget2 = ProgressWidget::new(make_points(20, 70), make_size(360, 40), 50);
41
42    widget2.set_color(CONFIG_COLOR_SECONDARY, Color::RGB(255, 0, 0));
43    widget2.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 255, 0));
44
45    let mut widget3 = ProgressWidget::new(make_points(20, 120), make_size(360, 40), 75);
46
47    widget3.set_color(CONFIG_COLOR_SECONDARY, Color::RGB(255, 0, 0));
48    widget3.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 255, 255));
49
50    let mut timer = TimerWidget::new(100, true);
51    timer.on_timeout(|_, _widgets, _layouts| {
52        let widget1_id = widget_id_for_name(_widgets, String::from("widget1"));
53        let widget2_id = widget_id_for_name(_widgets, String::from("widget2"));
54        let widget3_id = widget_id_for_name(_widgets, String::from("widget3"));
55        let progress1_value: u8 =
56            (cast!(_widgets, widget1_id, ProgressWidget).get_progress() + 1) % 100;
57        let progress2_value: u8 =
58            (cast!(_widgets, widget2_id, ProgressWidget).get_progress() + 1) % 100;
59        let progress3_value: u8 =
60            (cast!(_widgets, widget3_id, ProgressWidget).get_progress() + 1) % 100;
61
62        cast!(_widgets, widget1_id, ProgressWidget).set_progress(progress1_value);
63        cast!(_widgets, widget2_id, ProgressWidget).set_progress(progress2_value);
64        cast!(_widgets, widget3_id, ProgressWidget).set_progress(progress3_value);
65    });
66
67    engine.add_widget(Box::new(widget1), String::from("widget1"));
68    engine.add_widget(Box::new(widget2), String::from("widget2"));
69    engine.add_widget(Box::new(widget3), String::from("widget3"));
70    engine.add_widget(Box::new(timer), String::from("timer1"));
71
72    engine.run(sdl_context, window);
73}
Source

fn set_numeric(&mut self, config: u8, value: i32)

Sets a numeric value for a configuration key.

Examples found in repository?
examples/push_button.rs (line 34)
16pub fn main() {
17    let sdl_context = sdl2::init().unwrap();
18    let video_subsystem = sdl_context.video().unwrap();
19    let window = video_subsystem
20        .window("pushrod-render push button demo", 400, 100)
21        .position_centered()
22        .opengl()
23        .build()
24        .unwrap();
25    let mut engine = Engine::new(400, 100, 30);
26    let mut button1 = PushButtonWidget::new(
27        make_points(20, 20),
28        make_size(360, 60),
29        String::from("Click me!"),
30        40,
31    );
32
33    button1.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
34    button1.set_numeric(CONFIG_BORDER_WIDTH, 2);
35    button1.on_click(|_x, _widgets, _layouts| {
36        eprintln!("Click me clicked!");
37    });
38
39    engine.add_widget(Box::new(button1), String::from("button1"));
40
41    engine.run(sdl_context, window);
42}
More examples
Hide additional examples
examples/list.rs (line 29)
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}
examples/toggle_button.rs (line 35)
16pub fn main() {
17    let sdl_context = sdl2::init().unwrap();
18    let video_subsystem = sdl_context.video().unwrap();
19    let window = video_subsystem
20        .window("pushrod-render toggle button demo", 400, 100)
21        .position_centered()
22        .opengl()
23        .build()
24        .unwrap();
25    let mut engine = Engine::new(400, 100, 60);
26    let mut button1 = ToggleButtonWidget::new(
27        make_points(20, 20),
28        make_size(170, 60),
29        String::from("1"),
30        40,
31        false,
32    );
33
34    button1.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
35    button1.set_numeric(CONFIG_BORDER_WIDTH, 2);
36    button1.on_toggle(|_, _widgets, _layouts, _state| {
37        eprintln!("1 Toggled: {}", _state);
38    });
39
40    let mut button2 = ToggleButtonWidget::new(
41        make_points(210, 20),
42        make_size(170, 60),
43        String::from("2"),
44        40,
45        true,
46    );
47
48    button2.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
49    button2.set_numeric(CONFIG_BORDER_WIDTH, 2);
50    button2.on_toggle(|_, _widgets, _layouts, _state| {
51        eprintln!("2 Toggled: {}", _state);
52    });
53
54    engine.add_widget(Box::new(button1), String::from("button1"));
55    engine.add_widget(Box::new(button2), String::from("button2"));
56
57    engine.run(sdl_context, window);
58}
examples/layout.rs (line 122)
33pub fn main() {
34    let sdl_context = sdl2::init().unwrap();
35    let video_subsystem = sdl_context.video().unwrap();
36    let window = video_subsystem
37        .window("pushrod-render horizontal layout demo", 400, 300)
38        .position_centered()
39        .opengl()
40        .build()
41        .unwrap();
42    let mut engine = Engine::new(400, 300, 60);
43    let mut layout = HorizontalLayout::new(20, 20, 360, 80, PaddingConstraint::new(0, 0, 0, 0, 1));
44    let mut layout2 =
45        VerticalLayout::new(250, 120, 130, 160, PaddingConstraint::new(0, 0, 0, 0, 1));
46    let mut widget1 = BaseWidget::new(make_points_origin(), make_size(0, 0));
47
48    widget1
49        .get_config()
50        .set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
51    widget1.get_config().set_numeric(CONFIG_BORDER_WIDTH, 2);
52
53    let mut widget2 = BaseWidget::new(make_points_origin(), make_size(0, 0));
54
55    widget2
56        .get_config()
57        .set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
58    widget2.get_config().set_numeric(CONFIG_BORDER_WIDTH, 2);
59
60    let mut widget3 = BaseWidget::new(make_points_origin(), make_size(0, 0));
61
62    widget3
63        .get_config()
64        .set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
65    widget3.get_config().set_numeric(CONFIG_BORDER_WIDTH, 2);
66
67    let mut widget4 = BaseWidget::new(make_points_origin(), make_size(0, 0));
68
69    widget4
70        .get_config()
71        .set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
72    widget4.get_config().set_numeric(CONFIG_BORDER_WIDTH, 2);
73
74    let widget1_id = engine.add_widget(Box::new(widget1), String::from("widget1"));
75    let widget2_id = engine.add_widget(Box::new(widget2), String::from("widget2"));
76    let widget3_id = engine.add_widget(Box::new(widget3), String::from("widget3"));
77    let widget4_id = engine.add_widget(Box::new(widget4), String::from("widget4"));
78
79    layout.append_widget(widget1_id);
80    layout.append_widget(widget2_id);
81    layout2.append_widget(widget3_id);
82    layout2.append_widget(widget4_id);
83    engine.add_layout(Box::new(layout));
84    engine.add_layout(Box::new(layout2));
85
86    let mut text_widget1 = TextWidget::new(
87        String::from("assets/OpenSans-Regular.ttf"),
88        sdl2::ttf::FontStyle::NORMAL,
89        16,
90        TextJustify::Right,
91        String::from("Spacing:"),
92        make_points(20, 116),
93        make_size(70, 22),
94    );
95
96    text_widget1
97        .get_config()
98        .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 0));
99
100    let mut text_widget2 = TextWidget::new(
101        String::from("assets/OpenSans-Regular.ttf"),
102        sdl2::ttf::FontStyle::NORMAL,
103        16,
104        TextJustify::Left,
105        String::from("1"),
106        make_points(100, 116),
107        make_size(40, 22),
108    );
109
110    text_widget2
111        .get_config()
112        .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 255));
113
114    let mut button1 = PushButtonWidget::new(
115        make_points(130, 112),
116        make_size(50, 30),
117        String::from("<"),
118        20,
119    );
120
121    button1.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
122    button1.set_numeric(CONFIG_BORDER_WIDTH, 2);
123    button1.on_click(|_, _widgets, _layouts| {
124        let mut spacing = _layouts[0].layout.borrow_mut().get_padding().spacing - 1;
125        let top = _layouts[0].layout.borrow_mut().get_padding().top;
126        let bottom = _layouts[0].layout.borrow_mut().get_padding().bottom;
127        let left = _layouts[0].layout.borrow_mut().get_padding().left;
128        let right = _layouts[0].layout.borrow_mut().get_padding().right;
129        let text_widget2_id = widget_id_for_name(_widgets, String::from("text_widget2"));
130
131        if spacing <= 0 {
132            spacing = 0;
133        }
134
135        let spacing_new = PaddingConstraint::new(top, bottom, left, right, spacing);
136
137        _layouts[0]
138            .layout
139            .borrow_mut()
140            .set_padding(spacing_new.clone());
141        _layouts[1]
142            .layout
143            .borrow_mut()
144            .set_padding(spacing_new.clone());
145
146        refresh_widgets(_widgets);
147
148        cast!(_widgets, text_widget2_id, TextWidget).set_text(format!("{}", spacing));
149    });
150
151    let mut button2 = PushButtonWidget::new(
152        make_points(180, 112),
153        make_size(50, 30),
154        String::from(">"),
155        20,
156    );
157
158    button2.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
159    button2.set_numeric(CONFIG_BORDER_WIDTH, 2);
160    button2.on_click(|_, _widgets, _layouts| {
161        let mut spacing = _layouts[0].layout.borrow_mut().get_padding().spacing + 1;
162        let top = _layouts[0].layout.borrow_mut().get_padding().top;
163        let bottom = _layouts[0].layout.borrow_mut().get_padding().bottom;
164        let left = _layouts[0].layout.borrow_mut().get_padding().left;
165        let right = _layouts[0].layout.borrow_mut().get_padding().right;
166        let text_widget2_id = widget_id_for_name(_widgets, String::from("text_widget2"));
167
168        if spacing >= MAX_SPACING {
169            spacing = MAX_SPACING;
170        }
171
172        let spacing_new = PaddingConstraint::new(top, bottom, left, right, spacing);
173
174        _layouts[0]
175            .layout
176            .borrow_mut()
177            .set_padding(spacing_new.clone());
178        _layouts[1]
179            .layout
180            .borrow_mut()
181            .set_padding(spacing_new.clone());
182
183        refresh_widgets(_widgets);
184
185        cast!(_widgets, text_widget2_id, TextWidget).set_text(format!("{}", spacing));
186    });
187
188    let mut text_widget3 = TextWidget::new(
189        String::from("assets/OpenSans-Regular.ttf"),
190        sdl2::ttf::FontStyle::NORMAL,
191        16,
192        TextJustify::Right,
193        String::from("Top:"),
194        make_points(20, 146),
195        make_size(70, 22),
196    );
197
198    text_widget3
199        .get_config()
200        .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 0));
201
202    let mut text_widget4 = TextWidget::new(
203        String::from("assets/OpenSans-Regular.ttf"),
204        sdl2::ttf::FontStyle::NORMAL,
205        16,
206        TextJustify::Left,
207        String::from("0"),
208        make_points(100, 146),
209        make_size(40, 22),
210    );
211
212    text_widget4
213        .get_config()
214        .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 255));
215
216    let mut button3 = PushButtonWidget::new(
217        make_points(130, 142),
218        make_size(50, 30),
219        String::from("<"),
220        20,
221    );
222
223    button3.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
224    button3.set_numeric(CONFIG_BORDER_WIDTH, 2);
225    button3.on_click(|_, _widgets, _layouts| {
226        let spacing = _layouts[0].layout.borrow_mut().get_padding().spacing;
227        let mut top = _layouts[0].layout.borrow_mut().get_padding().top - 1;
228        let bottom = _layouts[0].layout.borrow_mut().get_padding().bottom;
229        let left = _layouts[0].layout.borrow_mut().get_padding().left;
230        let right = _layouts[0].layout.borrow_mut().get_padding().right;
231        let text_widget4_id = widget_id_for_name(_widgets, String::from("text_widget4"));
232
233        if top <= 0 {
234            top = 0;
235        }
236
237        let spacing_new = PaddingConstraint::new(top, bottom, left, right, spacing);
238
239        _layouts[0]
240            .layout
241            .borrow_mut()
242            .set_padding(spacing_new.clone());
243        _layouts[1]
244            .layout
245            .borrow_mut()
246            .set_padding(spacing_new.clone());
247
248        refresh_widgets(_widgets);
249
250        cast!(_widgets, text_widget4_id, TextWidget).set_text(format!("{}", top));
251    });
252
253    let mut button4 = PushButtonWidget::new(
254        make_points(180, 142),
255        make_size(50, 30),
256        String::from(">"),
257        20,
258    );
259
260    button4.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
261    button4.set_numeric(CONFIG_BORDER_WIDTH, 2);
262    button4.on_click(|_, _widgets, _layouts| {
263        let spacing = _layouts[0].layout.borrow_mut().get_padding().spacing;
264        let mut top = _layouts[0].layout.borrow_mut().get_padding().top + 1;
265        let bottom = _layouts[0].layout.borrow_mut().get_padding().bottom;
266        let left = _layouts[0].layout.borrow_mut().get_padding().left;
267        let right = _layouts[0].layout.borrow_mut().get_padding().right;
268        let text_widget4_id = widget_id_for_name(_widgets, String::from("text_widget4"));
269
270        if top >= MAX_SPACING {
271            top = MAX_SPACING;
272        }
273
274        let spacing_new = PaddingConstraint::new(top, bottom, left, right, spacing);
275
276        _layouts[0]
277            .layout
278            .borrow_mut()
279            .set_padding(spacing_new.clone());
280        _layouts[1]
281            .layout
282            .borrow_mut()
283            .set_padding(spacing_new.clone());
284
285        refresh_widgets(_widgets);
286
287        cast!(_widgets, text_widget4_id, TextWidget).set_text(format!("{}", top));
288    });
289
290    let mut text_widget5 = TextWidget::new(
291        String::from("assets/OpenSans-Regular.ttf"),
292        sdl2::ttf::FontStyle::NORMAL,
293        16,
294        TextJustify::Right,
295        String::from("Bottom:"),
296        make_points(20, 176),
297        make_size(70, 22),
298    );
299
300    text_widget5
301        .get_config()
302        .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 0));
303
304    let mut text_widget6 = TextWidget::new(
305        String::from("assets/OpenSans-Regular.ttf"),
306        sdl2::ttf::FontStyle::NORMAL,
307        16,
308        TextJustify::Left,
309        String::from("0"),
310        make_points(100, 176),
311        make_size(40, 22),
312    );
313
314    text_widget6
315        .get_config()
316        .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 255));
317
318    let mut button5 = PushButtonWidget::new(
319        make_points(130, 172),
320        make_size(50, 30),
321        String::from("<"),
322        20,
323    );
324
325    button5.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
326    button5.set_numeric(CONFIG_BORDER_WIDTH, 2);
327    button5.on_click(|_, _widgets, _layouts| {
328        let spacing = _layouts[0].layout.borrow_mut().get_padding().spacing;
329        let top = _layouts[0].layout.borrow_mut().get_padding().top;
330        let mut bottom = _layouts[0].layout.borrow_mut().get_padding().bottom - 1;
331        let left = _layouts[0].layout.borrow_mut().get_padding().left;
332        let right = _layouts[0].layout.borrow_mut().get_padding().right;
333        let text_widget6_id = widget_id_for_name(_widgets, String::from("text_widget6"));
334
335        if bottom <= 0 {
336            bottom = 0;
337        }
338
339        let spacing_new = PaddingConstraint::new(top, bottom, left, right, spacing);
340
341        _layouts[0]
342            .layout
343            .borrow_mut()
344            .set_padding(spacing_new.clone());
345        _layouts[1]
346            .layout
347            .borrow_mut()
348            .set_padding(spacing_new.clone());
349
350        refresh_widgets(_widgets);
351
352        cast!(_widgets, text_widget6_id, TextWidget).set_text(format!("{}", bottom));
353    });
354
355    let mut button6 = PushButtonWidget::new(
356        make_points(180, 172),
357        make_size(50, 30),
358        String::from(">"),
359        20,
360    );
361
362    button6.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
363    button6.set_numeric(CONFIG_BORDER_WIDTH, 2);
364    button6.on_click(|_, _widgets, _layouts| {
365        let spacing = _layouts[0].layout.borrow_mut().get_padding().spacing;
366        let top = _layouts[0].layout.borrow_mut().get_padding().top;
367        let mut bottom = _layouts[0].layout.borrow_mut().get_padding().bottom + 1;
368        let left = _layouts[0].layout.borrow_mut().get_padding().left;
369        let right = _layouts[0].layout.borrow_mut().get_padding().right;
370        let text_widget6_id = widget_id_for_name(_widgets, String::from("text_widget6"));
371
372        if bottom >= MAX_SPACING {
373            bottom = MAX_SPACING;
374        }
375
376        let spacing_new = PaddingConstraint::new(top, bottom, left, right, spacing);
377
378        _layouts[0]
379            .layout
380            .borrow_mut()
381            .set_padding(spacing_new.clone());
382        _layouts[1]
383            .layout
384            .borrow_mut()
385            .set_padding(spacing_new.clone());
386
387        refresh_widgets(_widgets);
388
389        cast!(_widgets, text_widget6_id, TextWidget).set_text(format!("{}", bottom));
390    });
391
392    let mut text_widget7 = TextWidget::new(
393        String::from("assets/OpenSans-Regular.ttf"),
394        sdl2::ttf::FontStyle::NORMAL,
395        16,
396        TextJustify::Right,
397        String::from("Left:"),
398        make_points(20, 206),
399        make_size(70, 22),
400    );
401
402    text_widget7
403        .get_config()
404        .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 0));
405
406    let mut text_widget8 = TextWidget::new(
407        String::from("assets/OpenSans-Regular.ttf"),
408        sdl2::ttf::FontStyle::NORMAL,
409        16,
410        TextJustify::Left,
411        String::from("0"),
412        make_points(100, 206),
413        make_size(40, 22),
414    );
415
416    text_widget8
417        .get_config()
418        .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 255));
419
420    let mut button7 = PushButtonWidget::new(
421        make_points(130, 202),
422        make_size(50, 30),
423        String::from("<"),
424        20,
425    );
426
427    button7.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
428    button7.set_numeric(CONFIG_BORDER_WIDTH, 2);
429    button7.on_click(|_, _widgets, _layouts| {
430        let spacing = _layouts[0].layout.borrow_mut().get_padding().spacing;
431        let top = _layouts[0].layout.borrow_mut().get_padding().top;
432        let bottom = _layouts[0].layout.borrow_mut().get_padding().bottom;
433        let mut left = _layouts[0].layout.borrow_mut().get_padding().left - 1;
434        let right = _layouts[0].layout.borrow_mut().get_padding().right;
435        let text_widget8_id = widget_id_for_name(_widgets, String::from("text_widget8"));
436
437        if left <= 0 {
438            left = 0;
439        }
440
441        let spacing_new = PaddingConstraint::new(top, bottom, left, right, spacing);
442
443        _layouts[0]
444            .layout
445            .borrow_mut()
446            .set_padding(spacing_new.clone());
447        _layouts[1]
448            .layout
449            .borrow_mut()
450            .set_padding(spacing_new.clone());
451
452        refresh_widgets(_widgets);
453
454        cast!(_widgets, text_widget8_id, TextWidget).set_text(format!("{}", left));
455    });
456
457    let mut button8 = PushButtonWidget::new(
458        make_points(180, 202),
459        make_size(50, 30),
460        String::from(">"),
461        20,
462    );
463
464    button8.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
465    button8.set_numeric(CONFIG_BORDER_WIDTH, 2);
466    button8.on_click(|_, _widgets, _layouts| {
467        let spacing = _layouts[0].layout.borrow_mut().get_padding().spacing;
468        let top = _layouts[0].layout.borrow_mut().get_padding().top;
469        let bottom = _layouts[0].layout.borrow_mut().get_padding().bottom;
470        let mut left = _layouts[0].layout.borrow_mut().get_padding().left + 1;
471        let right = _layouts[0].layout.borrow_mut().get_padding().right;
472        let text_widget8_id = widget_id_for_name(_widgets, String::from("text_widget8"));
473
474        if left >= MAX_SPACING {
475            left = MAX_SPACING;
476        }
477
478        let spacing_new = PaddingConstraint::new(top, bottom, left, right, spacing);
479
480        _layouts[0]
481            .layout
482            .borrow_mut()
483            .set_padding(spacing_new.clone());
484        _layouts[1]
485            .layout
486            .borrow_mut()
487            .set_padding(spacing_new.clone());
488
489        refresh_widgets(_widgets);
490
491        cast!(_widgets, text_widget8_id, TextWidget).set_text(format!("{}", left));
492    });
493
494    let mut text_widget9 = TextWidget::new(
495        String::from("assets/OpenSans-Regular.ttf"),
496        sdl2::ttf::FontStyle::NORMAL,
497        16,
498        TextJustify::Right,
499        String::from("Right:"),
500        make_points(20, 236),
501        make_size(70, 22),
502    );
503
504    text_widget9
505        .get_config()
506        .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 0));
507
508    let mut text_widget10 = TextWidget::new(
509        String::from("assets/OpenSans-Regular.ttf"),
510        sdl2::ttf::FontStyle::NORMAL,
511        16,
512        TextJustify::Left,
513        String::from("0"),
514        make_points(100, 236),
515        make_size(40, 22),
516    );
517
518    text_widget10
519        .get_config()
520        .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 255));
521
522    let mut button9 = PushButtonWidget::new(
523        make_points(130, 232),
524        make_size(50, 30),
525        String::from("<"),
526        20,
527    );
528
529    button9.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
530    button9.set_numeric(CONFIG_BORDER_WIDTH, 2);
531    button9.on_click(|_, _widgets, _layouts| {
532        let spacing = _layouts[0].layout.borrow_mut().get_padding().spacing;
533        let top = _layouts[0].layout.borrow_mut().get_padding().top;
534        let bottom = _layouts[0].layout.borrow_mut().get_padding().bottom;
535        let left = _layouts[0].layout.borrow_mut().get_padding().left;
536        let mut right = _layouts[0].layout.borrow_mut().get_padding().right - 1;
537        let text_widget10_id = widget_id_for_name(_widgets, String::from("text_widget10"));
538
539        if right <= 0 {
540            right = 0;
541        }
542
543        let spacing_new = PaddingConstraint::new(top, bottom, left, right, spacing);
544
545        _layouts[0]
546            .layout
547            .borrow_mut()
548            .set_padding(spacing_new.clone());
549        _layouts[1]
550            .layout
551            .borrow_mut()
552            .set_padding(spacing_new.clone());
553
554        refresh_widgets(_widgets);
555
556        cast!(_widgets, text_widget10_id, TextWidget).set_text(format!("{}", right));
557    });
558
559    let mut button10 = PushButtonWidget::new(
560        make_points(180, 232),
561        make_size(50, 30),
562        String::from(">"),
563        20,
564    );
565
566    button10.set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
567    button10.set_numeric(CONFIG_BORDER_WIDTH, 2);
568    button10.on_click(|_, _widgets, _layouts| {
569        let spacing = _layouts[0].layout.borrow_mut().get_padding().spacing;
570        let top = _layouts[0].layout.borrow_mut().get_padding().top;
571        let bottom = _layouts[0].layout.borrow_mut().get_padding().bottom;
572        let left = _layouts[0].layout.borrow_mut().get_padding().left;
573        let mut right = _layouts[0].layout.borrow_mut().get_padding().right + 1;
574        let text_widget10_id = widget_id_for_name(_widgets, String::from("text_widget10"));
575
576        if right >= MAX_SPACING {
577            right = MAX_SPACING;
578        }
579
580        let spacing_new = PaddingConstraint::new(top, bottom, left, right, spacing);
581
582        _layouts[0]
583            .layout
584            .borrow_mut()
585            .set_padding(spacing_new.clone());
586        _layouts[1]
587            .layout
588            .borrow_mut()
589            .set_padding(spacing_new.clone());
590
591        refresh_widgets(_widgets);
592
593        cast!(_widgets, text_widget10_id, TextWidget).set_text(format!("{}", right));
594    });
595
596    engine.add_widget(Box::new(text_widget1), String::from("text_widget1"));
597    engine.add_widget(Box::new(text_widget2), String::from("text_widget2"));
598    engine.add_widget(Box::new(button1), String::from("button1"));
599    engine.add_widget(Box::new(button2), String::from("button2"));
600    engine.add_widget(Box::new(text_widget3), String::from("text_widget3"));
601    engine.add_widget(Box::new(text_widget4), String::from("text_widget4"));
602    engine.add_widget(Box::new(button3), String::from("button3"));
603    engine.add_widget(Box::new(button4), String::from("button4"));
604    engine.add_widget(Box::new(text_widget5), String::from("text_widget5"));
605    engine.add_widget(Box::new(text_widget6), String::from("text_widget6"));
606    engine.add_widget(Box::new(button5), String::from("button5"));
607    engine.add_widget(Box::new(button6), String::from("button6"));
608    engine.add_widget(Box::new(text_widget7), String::from("text_widget7"));
609    engine.add_widget(Box::new(text_widget8), String::from("text_widget8"));
610    engine.add_widget(Box::new(button7), String::from("button7"));
611    engine.add_widget(Box::new(button8), String::from("button8"));
612    engine.add_widget(Box::new(text_widget9), String::from("text_widget9"));
613    engine.add_widget(Box::new(text_widget10), String::from("text_widget10"));
614    engine.add_widget(Box::new(button9), String::from("button9"));
615    engine.add_widget(Box::new(button10), String::from("button10"));
616
617    engine.run(sdl_context, window);
618}
Source

fn set_text(&mut self, config: u8, text: String)

Sets a text value for a configuration key.

Source

fn set_toggle(&mut self, config: u8, flag: bool)

Sets a toggle for a configuration key.

Source

fn set_compass(&mut self, config: u8, value: CompassPosition)

Sets a compass position for a configuration key.

Examples found in repository?
examples/image.rs (line 32)
11pub fn main() {
12    const WIDTH: u32 = 500;
13    const HEIGHT: u32 = 270;
14
15    let sdl_context = sdl2::init().unwrap();
16    let video_subsystem = sdl_context.video().unwrap();
17    let window = video_subsystem
18        .window("pushrod-render image demo", WIDTH, HEIGHT)
19        .position_centered()
20        .opengl()
21        .build()
22        .unwrap();
23    let mut engine = Engine::new(WIDTH, HEIGHT, 60);
24    let mut widget1 = ImageWidget::new(
25        String::from("assets/rust-48x48.jpg"),
26        make_points(20, 16),
27        make_size(60, 60),
28        false,
29    );
30
31    widget1.set_color(CONFIG_COLOR_BASE, Color::RGB(0, 0, 0));
32    widget1.set_compass(CONFIG_IMAGE_POSITION, CompassPosition::NW);
33
34    let mut widget2 = ImageWidget::new(
35        String::from("assets/rust-48x48.jpg"),
36        make_points(90, 16),
37        make_size(60, 60),
38        false,
39    );
40
41    widget2.set_color(CONFIG_COLOR_BASE, Color::RGB(0, 0, 0));
42    widget2.set_compass(CONFIG_IMAGE_POSITION, CompassPosition::N);
43
44    let mut widget3 = ImageWidget::new(
45        String::from("assets/rust-48x48.jpg"),
46        make_points(160, 16),
47        make_size(60, 60),
48        false,
49    );
50
51    widget3.set_color(CONFIG_COLOR_BASE, Color::RGB(0, 0, 0));
52    widget3.set_compass(CONFIG_IMAGE_POSITION, CompassPosition::NE);
53
54    let mut widget4 = ImageWidget::new(
55        String::from("assets/rust-48x48.jpg"),
56        make_points(20, 86),
57        make_size(60, 60),
58        false,
59    );
60
61    widget4.set_color(CONFIG_COLOR_BASE, Color::RGB(0, 0, 0));
62    widget4.set_compass(CONFIG_IMAGE_POSITION, CompassPosition::W);
63
64    let mut widget5 = ImageWidget::new(
65        String::from("assets/rust-48x48.jpg"),
66        make_points(90, 86),
67        make_size(60, 60),
68        false,
69    );
70
71    widget5.set_color(CONFIG_COLOR_BASE, Color::RGB(0, 0, 0));
72    widget5.set_compass(CONFIG_IMAGE_POSITION, CompassPosition::Center);
73
74    let mut widget6 = ImageWidget::new(
75        String::from("assets/rust-48x48.jpg"),
76        make_points(160, 86),
77        make_size(60, 60),
78        false,
79    );
80
81    widget6.set_color(CONFIG_COLOR_BASE, Color::RGB(0, 0, 0));
82    widget6.set_compass(CONFIG_IMAGE_POSITION, CompassPosition::E);
83
84    let mut widget7 = ImageWidget::new(
85        String::from("assets/rust-48x48.jpg"),
86        make_points(20, 156),
87        make_size(60, 60),
88        false,
89    );
90
91    widget7.set_color(CONFIG_COLOR_BASE, Color::RGB(0, 0, 0));
92    widget7.set_compass(CONFIG_IMAGE_POSITION, CompassPosition::SW);
93
94    let mut widget8 = ImageWidget::new(
95        String::from("assets/rust-48x48.jpg"),
96        make_points(90, 156),
97        make_size(60, 60),
98        false,
99    );
100
101    widget8.set_color(CONFIG_COLOR_BASE, Color::RGB(0, 0, 0));
102    widget8.set_compass(CONFIG_IMAGE_POSITION, CompassPosition::S);
103
104    let mut widget9 = ImageWidget::new(
105        String::from("assets/rust-48x48.jpg"),
106        make_points(160, 156),
107        make_size(60, 60),
108        false,
109    );
110
111    widget9.set_color(CONFIG_COLOR_BASE, Color::RGB(0, 0, 0));
112    widget9.set_compass(CONFIG_IMAGE_POSITION, CompassPosition::SE);
113
114    let mut widget10 = ImageWidget::new(
115        String::from("assets/rust-48x48.jpg"),
116        make_points(230, 16),
117        make_size(80, 80),
118        true,
119    );
120
121    widget10.set_color(CONFIG_COLOR_BASE, Color::RGB(0, 0, 0));
122    widget10.set_compass(CONFIG_IMAGE_POSITION, CompassPosition::NW);
123
124    let mut widget11 = ImageWidget::new(
125        String::from("assets/rust-48x48.jpg"),
126        make_points(260, 46),
127        make_size(120, 120),
128        true,
129    );
130
131    widget11.set_color(CONFIG_COLOR_BASE, Color::RGB(0, 0, 0));
132    widget11.set_compass(CONFIG_IMAGE_POSITION, CompassPosition::NW);
133
134    let mut widget12 = ImageWidget::new(
135        String::from("assets/rust-48x48.jpg"),
136        make_points(320, 86),
137        make_size(160, 160),
138        true,
139    );
140
141    widget12.set_color(CONFIG_COLOR_BASE, Color::RGB(0, 0, 0));
142    widget12.set_compass(CONFIG_IMAGE_POSITION, CompassPosition::NW);
143
144    engine.add_widget(Box::new(widget1), String::from("widget1"));
145    engine.add_widget(Box::new(widget2), String::from("widget2"));
146    engine.add_widget(Box::new(widget3), String::from("widget3"));
147    engine.add_widget(Box::new(widget4), String::from("widget4"));
148    engine.add_widget(Box::new(widget5), String::from("widget5"));
149    engine.add_widget(Box::new(widget6), String::from("widget6"));
150    engine.add_widget(Box::new(widget7), String::from("widget7"));
151    engine.add_widget(Box::new(widget8), String::from("widget8"));
152    engine.add_widget(Box::new(widget9), String::from("widget9"));
153    engine.add_widget(Box::new(widget10), String::from("widget10"));
154    engine.add_widget(Box::new(widget11), String::from("widget11"));
155    engine.add_widget(Box::new(widget12), String::from("widget12"));
156
157    engine.run(sdl_context, window);
158}
Source

fn get_point(&mut self, k: u8) -> Points

Retrieves a Points for a configuration key. Returns Points::default if not set.

Source

fn get_size(&mut self, k: u8) -> Size

Retrieves a Size for a configuration key. Returns a Size::default if not set.

Source

fn get_color(&mut self, k: u8) -> Color

Retrieves a Color for a configuration key. Returns white if not set.

Source

fn get_numeric(&mut self, k: u8) -> i32

Retrieves a numeric value for a configuration key. Returns 0 if not set.

Source

fn get_text(&mut self, k: u8) -> String

Retrieves text for a configuration key. Returns a blank string if not set.

Source

fn get_toggle(&mut self, k: u8) -> bool

Retrieves a boolean toggle for a configuration key. Returns false if not set.

Source

fn get_compass(&mut self, k: u8) -> CompassPosition

Retrieves a CompassPosition toggle for a configuration key. Returns CompassPosition::W if not set.

Source

fn set_origin(&mut self, _origin: Points)

Sets the origin of the Widget, adjusting the X and Y coordinates. Automatically sets the invalidate flag to true when adjusted, but only if the new origin is not the same as the previous origin.

Source

fn set_size(&mut self, _size: Vec<u32>)

Sets the size of the Widget, adjusting the width and height. Automatically sets the invalidate flag to true when adjusted, but only if the new size is not the same as the previous size.

Source

fn get_drawing_area(&mut self) -> Rect

Returns a Rect object containing the drawing bounds of this Widget.

Source

fn is_invalidated(&mut self) -> bool

Returns whether or not a Widget is invalidated state.

Source

fn set_invalidated(&mut self, flag: bool)

Sets invalidation state for the current Widget.

Implementors§

Source§

impl Widget for CheckboxWidget

This is the Widget implementation of the CheckboxWidget.

Source§

impl Widget for GridWidget

This is the Widget implementation of the GridWidget.

Source§

impl Widget for ImageButtonWidget

This is the Widget implementation of the ImageButtonWidget.

Source§

impl Widget for ImageWidget

This is the Widget implementation of the ImageWidget. Image is rendered onto a 3D texture, then copied to the canvas after rendering.

Source§

impl Widget for ListWidget

This is the Widget implementation of the ListWidget.

Source§

impl Widget for ProgressWidget

This is the Widget implementation of the ProgressWidget. It contains a BaseWidget within its bounds to draw the base background, then draws the progress fill over the top.

Source§

impl Widget for PushButtonWidget

This is the Widget implementation of the PushButtonWidget.

Source§

impl Widget for SliderWidget

This is the Widget implementation of the SliderWidget.

Source§

impl Widget for TabBarWidget

This is the Widget implementation of the TabBarWidget.

Source§

impl Widget for TextWidget

This is the Widget implementation of the TextWidget. Text is rendered onto a 3D texture, then copied to the canvas after rendering. It uses blended mode texture mapping, which may be slow (as described by the SDL2 documentation), so this might change later to use 8 bit color mapping.

Source§

impl Widget for TileWidget

This is the Widget implementation of the TileWidget.

Source§

impl Widget for TimerWidget

This is the Widget implementation of the TimerWidget.

Source§

impl Widget for ToggleButtonWidget

This is the Widget implementation of the ToggleButtonWidget.

Source§

impl Widget for BaseWidget

Implementation for drawing a BaseWidget, with the Widget trait objects applied. This code can be used as a base implementation, or an example of how to create a Widget in Pushrod. The base set of Widgets show off a multitude of different uses for handling events, display contents, and so on. Look through the code in the pushrod::widgets module to get more of an idea of what is possible.