pub struct WidgetConfig {
pub config: HashMap<u8, Config>,
/* private fields */
}Expand description
This is the store for the WidgetConfig, which each Widget object needs. This stores
information about the Widget. It currently contains the point of origin, size, a HashMap of
different Colors, a border width, and an invalidation flag.
Fields§
§config: HashMap<u8, Config>The HashMap store for configuration objects.
Implementations§
Source§impl WidgetConfig
This is the implementation of the WidgetConfig.
impl WidgetConfig
This is the implementation of the WidgetConfig.
Sourcepub fn new(points: Points, size: Size) -> Self
pub fn new(points: Points, size: Size) -> Self
Constructor - takes the X, Y, W, and H coordinates of the Widget, physically in the
main Canvas.
Sourcepub fn to_x(&self, x: i32) -> i32
pub fn to_x(&self, x: i32) -> i32
Converts an X point to the physical X point on the Canvas plus the point of origin.
Returns i32 containing the modified X coordinate. This is a convenience method for the
Widget to draw based on a 0x0 point of origin.
Sourcepub fn to_y(&self, y: i32) -> i32
pub fn to_y(&self, y: i32) -> i32
Converts a Y point to the physical Y point on the Canvas plus the point of origin.
Returns i32 containing the modified Y coordinate. This is a convenience method for the
Widget to draw based on a 0x0 point of origin.
Sourcepub fn set_invalidated(&mut self, flag: bool)
pub fn set_invalidated(&mut self, flag: bool)
Sets the invalidation state of the Widget, telling the Engine that the Widget
contents has changed, and must be redrawn. Setting the flag to true indicates that
the Widget needs to be redrawn on the screen, false indicates that it its state has
not changed, and its image can be pulled from a buffer if necessary, skipping the draw
call.
Examples found in repository?
620fn refresh_widgets(_widgets: &[WidgetContainer]) {
621 _widgets[0]
622 .widget
623 .borrow_mut()
624 .get_config()
625 .set_invalidated(true);
626 _widgets[5]
627 .widget
628 .borrow_mut()
629 .get_config()
630 .set_invalidated(true);
631 _widgets[6]
632 .widget
633 .borrow_mut()
634 .get_config()
635 .set_invalidated(true);
636 _widgets[9]
637 .widget
638 .borrow_mut()
639 .get_config()
640 .set_invalidated(true);
641 _widgets[10]
642 .widget
643 .borrow_mut()
644 .get_config()
645 .set_invalidated(true);
646 _widgets[13]
647 .widget
648 .borrow_mut()
649 .get_config()
650 .set_invalidated(true);
651 _widgets[14]
652 .widget
653 .borrow_mut()
654 .get_config()
655 .set_invalidated(true);
656 _widgets[17]
657 .widget
658 .borrow_mut()
659 .get_config()
660 .set_invalidated(true);
661 _widgets[18]
662 .widget
663 .borrow_mut()
664 .get_config()
665 .set_invalidated(true);
666 _widgets[21]
667 .widget
668 .borrow_mut()
669 .get_config()
670 .set_invalidated(true);
671 _widgets[22]
672 .widget
673 .borrow_mut()
674 .get_config()
675 .set_invalidated(true);
676}More examples
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 demo", 800, 600)
20 .position_centered()
21 .opengl()
22 .build()
23 .unwrap();
24 let mut engine = Engine::new(800, 600, 30);
25 let mut new_base_widget = BaseWidget::new(make_points(100, 100), make_size(600, 400));
26
27 new_base_widget
28 .get_config()
29 .set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
30 new_base_widget
31 .get_config()
32 .set_numeric(CONFIG_BORDER_WIDTH, 2);
33
34 new_base_widget
35 .get_callbacks()
36 .on_mouse_entered(|x, _widgets, _layouts| {
37 x.get_config()
38 .set_color(CONFIG_COLOR_BASE, Color::RGB(255, 0, 0));
39 x.get_config().set_invalidated(true);
40 _widgets[0]
41 .widget
42 .borrow_mut()
43 .get_config()
44 .set_invalidated(true);
45 eprintln!("Mouse Entered");
46 });
47
48 new_base_widget
49 .get_callbacks()
50 .on_mouse_exited(|x, _widgets, _layouts| {
51 x.get_config()
52 .set_color(CONFIG_COLOR_BASE, Color::RGB(255, 255, 255));
53 x.get_config().set_invalidated(true);
54 _widgets[0]
55 .widget
56 .borrow_mut()
57 .get_config()
58 .set_invalidated(true);
59 eprintln!("Mouse Exited");
60 });
61
62 new_base_widget
63 .get_callbacks()
64 .on_mouse_moved(|_widget, _widgets, _layouts, points| {
65 eprintln!("Mouse Moved: {:?}", points);
66 });
67
68 new_base_widget
69 .get_callbacks()
70 .on_mouse_scrolled(|_widget, _widgets, _layouts, points| {
71 eprintln!("Mouse Scrolled: {:?}", points);
72 });
73
74 new_base_widget.get_callbacks().on_mouse_clicked(
75 |_widget, _widgets, _layouts, button, clicks, state| {
76 eprintln!(
77 "Mouse Clicked: button={} clicks={} state={}",
78 button, clicks, state
79 );
80 },
81 );
82
83 engine.add_widget(Box::new(new_base_widget), String::from("widget1"));
84
85 engine.on_exit(|_| {
86 eprintln!("Application exiting.");
87 true
88 });
89
90 engine.run(sdl_context, window);
91}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 exit demo", 800, 600)
21 .position_centered()
22 .opengl()
23 .build()
24 .unwrap();
25 let mut engine = Engine::new(800, 600, 30);
26 let mut new_base_widget = BaseWidget::new(make_points(100, 100), make_size(600, 400));
27
28 new_base_widget
29 .get_config()
30 .set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
31 new_base_widget
32 .get_config()
33 .set_numeric(CONFIG_BORDER_WIDTH, 2);
34
35 new_base_widget
36 .get_callbacks()
37 .on_mouse_entered(|x, _widgets, _layouts| {
38 x.get_config()
39 .set_color(CONFIG_COLOR_BASE, Color::RGB(255, 0, 0));
40 x.get_config().set_invalidated(true);
41 _widgets[0]
42 .widget
43 .borrow_mut()
44 .get_config()
45 .set_invalidated(true);
46 eprintln!("Mouse Entered");
47 });
48
49 new_base_widget
50 .get_callbacks()
51 .on_mouse_exited(|x, _widgets, _layouts| {
52 x.get_config()
53 .set_color(CONFIG_COLOR_BASE, Color::RGB(255, 255, 255));
54 x.get_config().set_invalidated(true);
55 _widgets[0]
56 .widget
57 .borrow_mut()
58 .get_config()
59 .set_invalidated(true);
60 eprintln!("Mouse Exited");
61 });
62
63 new_base_widget
64 .get_callbacks()
65 .on_mouse_moved(|_widget, _widgets, _layouts, points| {
66 eprintln!("Mouse Moved: {:?}", points);
67 });
68
69 new_base_widget
70 .get_callbacks()
71 .on_mouse_scrolled(|_widget, _widgets, _layouts, points| {
72 eprintln!("Mouse Scrolled: {:?}", points);
73 });
74
75 new_base_widget.get_callbacks().on_mouse_clicked(
76 |_widget, _widgets, _layouts, button, clicks, state| {
77 eprintln!(
78 "Mouse Clicked: button={} clicks={} state={}",
79 button, clicks, state
80 );
81 },
82 );
83
84 engine.add_widget(Box::new(new_base_widget), String::from("widget1"));
85
86 engine.on_exit(|engine| {
87 let buttons: Vec<_> = vec![
88 ButtonData {
89 flags: MessageBoxButtonFlag::RETURNKEY_DEFAULT,
90 button_id: 1,
91 text: "Yes",
92 },
93 ButtonData {
94 flags: MessageBoxButtonFlag::ESCAPEKEY_DEFAULT,
95 button_id: 2,
96 text: "No",
97 },
98 ];
99
100 let res = show_message_box(
101 MessageBoxFlag::WARNING,
102 buttons.as_slice(),
103 "Quit",
104 "Are you sure?",
105 None,
106 None,
107 )
108 .unwrap();
109
110 if let ClickedButton::CustomButton(x) = res {
111 if x.button_id == 1 {
112 return true;
113 }
114 }
115
116 false
117 });
118
119 engine.run(sdl_context, window);
120}Sourcepub fn invalidated(&self) -> bool
pub fn invalidated(&self) -> bool
Returns the invalidation state. Returns a bool containing the state.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Indicates whether or not this Widget is enabled or disabled - true if enabled,
false otherwise.
Sourcepub fn hide(&mut self)
pub fn hide(&mut self)
Prevents the Widget from being drawn on the screen, or being interacted with. No events
are received by this Widget when hidden.
Indicates whether or not this Widget has been hidden from view - true if this Widget
is hidden, false otherwise.
Sourcepub fn set_color(&mut self, config: u8, color: Color)
pub fn set_color(&mut self, config: u8, color: Color)
Sets a color for a configuration key.
Examples found in repository?
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 text widget demo", 500, 200)
16 .position_centered()
17 .opengl()
18 .build()
19 .unwrap();
20 let mut engine = Engine::new(500, 200, 20);
21 let mut widget1 = TextWidget::new(
22 String::from("assets/OpenSans-Regular.ttf"),
23 sdl2::ttf::FontStyle::NORMAL,
24 28,
25 TextJustify::Left,
26 String::from("Left Justified"),
27 make_points(20, 16),
28 make_size(460, 40),
29 );
30
31 widget1
32 .get_config()
33 .set_color(CONFIG_COLOR_TEXT, Color::RGB(255, 0, 0));
34
35 let mut widget2 = TextWidget::new(
36 String::from("assets/OpenSans-Regular.ttf"),
37 sdl2::ttf::FontStyle::NORMAL,
38 28,
39 TextJustify::Center,
40 String::from("Center Justified"),
41 make_points(20, 80),
42 make_size(460, 40),
43 );
44
45 widget2
46 .get_config()
47 .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 255, 0));
48
49 let mut widget3 = TextWidget::new(
50 String::from("assets/OpenSans-Regular.ttf"),
51 sdl2::ttf::FontStyle::NORMAL,
52 28,
53 TextJustify::Right,
54 String::from("Right Justified"),
55 make_points(20, 144),
56 make_size(460, 40),
57 );
58
59 widget3
60 .get_config()
61 .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 255));
62
63 engine.add_widget(Box::new(widget1), String::from("widget1"));
64 engine.add_widget(Box::new(widget2), String::from("widget2"));
65 engine.add_widget(Box::new(widget3), String::from("widget3"));
66
67 engine.run(sdl_context, window);
68}More examples
32pub fn main() {
33 let sdl_context = sdl2::init().unwrap();
34 let video_subsystem = sdl_context.video().unwrap();
35 let window = video_subsystem
36 .window("pushrod-render grid demo", 600, 340)
37 .position_centered()
38 .opengl()
39 .build()
40 .unwrap();
41 let mut engine = Engine::new(600, 340, 60);
42 let mut grid1 = GridWidget::new(make_points(20, 20), make_size(280, 280), 10, false);
43 let mut grid2 = GridWidget::new(make_points(310, 20), make_size(280, 280), 10, true);
44
45 grid1
46 .get_config()
47 .set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
48 grid1.get_config().set_numeric(CONFIG_BORDER_WIDTH, 1);
49
50 grid2
51 .get_config()
52 .set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
53 grid2.get_config().set_numeric(CONFIG_BORDER_WIDTH, 1);
54
55 let mut slider1 = SliderWidget::new(
56 make_points(20, 310),
57 make_size(320, 20),
58 1,
59 20,
60 10,
61 SliderHorizontal,
62 );
63
64 slider1.on_value_changed(|_slider, _widgets, _layouts, pos| {
65 let text1_id = widget_id_for_name(_widgets, String::from("text1"));
66 let grid1_id = widget_id_for_name(_widgets, String::from("grid1"));
67 let grid2_id = widget_id_for_name(_widgets, String::from("grid2"));
68
69 cast!(_widgets, text1_id, TextWidget).set_text(format!("{}", pos));
70 cast!(_widgets, grid1_id, GridWidget).set_grid_size(pos);
71 cast!(_widgets, grid2_id, GridWidget).set_grid_size(pos);
72 });
73
74 let mut text_widget1 = TextWidget::new(
75 String::from("assets/OpenSans-Regular.ttf"),
76 sdl2::ttf::FontStyle::NORMAL,
77 16,
78 TextJustify::Left,
79 String::from("10"),
80 make_points(360, 310),
81 make_size(40, 20),
82 );
83
84 text_widget1
85 .get_config()
86 .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 0));
87
88 engine.add_widget(Box::new(grid1), String::from("grid1"));
89 engine.add_widget(Box::new(grid2), String::from("grid2"));
90 engine.add_widget(Box::new(slider1), String::from("slider1"));
91 engine.add_widget(Box::new(text_widget1), String::from("text1"));
92
93 engine.run(sdl_context, window);
94}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 demo", 800, 600)
20 .position_centered()
21 .opengl()
22 .build()
23 .unwrap();
24 let mut engine = Engine::new(800, 600, 30);
25 let mut new_base_widget = BaseWidget::new(make_points(100, 100), make_size(600, 400));
26
27 new_base_widget
28 .get_config()
29 .set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
30 new_base_widget
31 .get_config()
32 .set_numeric(CONFIG_BORDER_WIDTH, 2);
33
34 new_base_widget
35 .get_callbacks()
36 .on_mouse_entered(|x, _widgets, _layouts| {
37 x.get_config()
38 .set_color(CONFIG_COLOR_BASE, Color::RGB(255, 0, 0));
39 x.get_config().set_invalidated(true);
40 _widgets[0]
41 .widget
42 .borrow_mut()
43 .get_config()
44 .set_invalidated(true);
45 eprintln!("Mouse Entered");
46 });
47
48 new_base_widget
49 .get_callbacks()
50 .on_mouse_exited(|x, _widgets, _layouts| {
51 x.get_config()
52 .set_color(CONFIG_COLOR_BASE, Color::RGB(255, 255, 255));
53 x.get_config().set_invalidated(true);
54 _widgets[0]
55 .widget
56 .borrow_mut()
57 .get_config()
58 .set_invalidated(true);
59 eprintln!("Mouse Exited");
60 });
61
62 new_base_widget
63 .get_callbacks()
64 .on_mouse_moved(|_widget, _widgets, _layouts, points| {
65 eprintln!("Mouse Moved: {:?}", points);
66 });
67
68 new_base_widget
69 .get_callbacks()
70 .on_mouse_scrolled(|_widget, _widgets, _layouts, points| {
71 eprintln!("Mouse Scrolled: {:?}", points);
72 });
73
74 new_base_widget.get_callbacks().on_mouse_clicked(
75 |_widget, _widgets, _layouts, button, clicks, state| {
76 eprintln!(
77 "Mouse Clicked: button={} clicks={} state={}",
78 button, clicks, state
79 );
80 },
81 );
82
83 engine.add_widget(Box::new(new_base_widget), String::from("widget1"));
84
85 engine.on_exit(|_| {
86 eprintln!("Application exiting.");
87 true
88 });
89
90 engine.run(sdl_context, window);
91}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 exit demo", 800, 600)
21 .position_centered()
22 .opengl()
23 .build()
24 .unwrap();
25 let mut engine = Engine::new(800, 600, 30);
26 let mut new_base_widget = BaseWidget::new(make_points(100, 100), make_size(600, 400));
27
28 new_base_widget
29 .get_config()
30 .set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
31 new_base_widget
32 .get_config()
33 .set_numeric(CONFIG_BORDER_WIDTH, 2);
34
35 new_base_widget
36 .get_callbacks()
37 .on_mouse_entered(|x, _widgets, _layouts| {
38 x.get_config()
39 .set_color(CONFIG_COLOR_BASE, Color::RGB(255, 0, 0));
40 x.get_config().set_invalidated(true);
41 _widgets[0]
42 .widget
43 .borrow_mut()
44 .get_config()
45 .set_invalidated(true);
46 eprintln!("Mouse Entered");
47 });
48
49 new_base_widget
50 .get_callbacks()
51 .on_mouse_exited(|x, _widgets, _layouts| {
52 x.get_config()
53 .set_color(CONFIG_COLOR_BASE, Color::RGB(255, 255, 255));
54 x.get_config().set_invalidated(true);
55 _widgets[0]
56 .widget
57 .borrow_mut()
58 .get_config()
59 .set_invalidated(true);
60 eprintln!("Mouse Exited");
61 });
62
63 new_base_widget
64 .get_callbacks()
65 .on_mouse_moved(|_widget, _widgets, _layouts, points| {
66 eprintln!("Mouse Moved: {:?}", points);
67 });
68
69 new_base_widget
70 .get_callbacks()
71 .on_mouse_scrolled(|_widget, _widgets, _layouts, points| {
72 eprintln!("Mouse Scrolled: {:?}", points);
73 });
74
75 new_base_widget.get_callbacks().on_mouse_clicked(
76 |_widget, _widgets, _layouts, button, clicks, state| {
77 eprintln!(
78 "Mouse Clicked: button={} clicks={} state={}",
79 button, clicks, state
80 );
81 },
82 );
83
84 engine.add_widget(Box::new(new_base_widget), String::from("widget1"));
85
86 engine.on_exit(|engine| {
87 let buttons: Vec<_> = vec![
88 ButtonData {
89 flags: MessageBoxButtonFlag::RETURNKEY_DEFAULT,
90 button_id: 1,
91 text: "Yes",
92 },
93 ButtonData {
94 flags: MessageBoxButtonFlag::ESCAPEKEY_DEFAULT,
95 button_id: 2,
96 text: "No",
97 },
98 ];
99
100 let res = show_message_box(
101 MessageBoxFlag::WARNING,
102 buttons.as_slice(),
103 "Quit",
104 "Are you sure?",
105 None,
106 None,
107 )
108 .unwrap();
109
110 if let ClickedButton::CustomButton(x) = res {
111 if x.button_id == 1 {
112 return true;
113 }
114 }
115
116 false
117 });
118
119 engine.run(sdl_context, window);
120}31pub fn main() {
32 let sdl_context = sdl2::init().unwrap();
33 let video_subsystem = sdl_context.video().unwrap();
34 let window = video_subsystem
35 .window("pushrod-render slider demo", 400, 300)
36 .position_centered()
37 .opengl()
38 .build()
39 .unwrap();
40 let mut engine = Engine::new(400, 300, 60);
41 let mut slider1 = SliderWidget::new(
42 make_points(20, 20),
43 make_size(300, 20),
44 0,
45 100,
46 20,
47 SliderHorizontal,
48 );
49
50 slider1.on_value_changed(|_slider, _widgets, _layouts, pos| {
51 let text1_id = widget_id_for_name(_widgets, String::from("text1"));
52
53 cast!(_widgets, text1_id, TextWidget).set_text(format!("{}", pos));
54 });
55
56 let mut text_widget1 = TextWidget::new(
57 String::from("assets/OpenSans-Regular.ttf"),
58 sdl2::ttf::FontStyle::NORMAL,
59 16,
60 TextJustify::Left,
61 String::from("20"),
62 make_points(330, 20),
63 make_size(50, 20),
64 );
65
66 text_widget1
67 .get_config()
68 .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 0));
69
70 let mut slider2 = SliderWidget::new(
71 make_points(20, 50),
72 make_size(300, 20),
73 20,
74 80,
75 40,
76 SliderHorizontal,
77 );
78
79 slider2.on_value_changed(|_slider, _widgets, _layouts, pos| {
80 let text2_id = widget_id_for_name(_widgets, String::from("text2"));
81
82 cast!(_widgets, text2_id, TextWidget).set_text(format!("{}", pos));
83 });
84
85 let mut text_widget2 = TextWidget::new(
86 String::from("assets/OpenSans-Regular.ttf"),
87 sdl2::ttf::FontStyle::NORMAL,
88 16,
89 TextJustify::Left,
90 String::from("40"),
91 make_points(330, 50),
92 make_size(50, 20),
93 );
94
95 text_widget2
96 .get_config()
97 .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 0));
98
99 let mut slider3 = SliderWidget::new(
100 make_points(30, 80),
101 make_size(20, 170),
102 0,
103 100,
104 0,
105 SliderVertical,
106 );
107
108 slider3.on_value_changed(|_slider, _widgets, _layouts, pos| {
109 let text3_id = widget_id_for_name(_widgets, String::from("text3"));
110
111 cast!(_widgets, text3_id, TextWidget).set_text(format!("{}", pos));
112 });
113
114 let mut text_widget3 = TextWidget::new(
115 String::from("assets/OpenSans-Regular.ttf"),
116 sdl2::ttf::FontStyle::NORMAL,
117 16,
118 TextJustify::Center,
119 String::from("0"),
120 make_points(16, 270),
121 make_size(50, 20),
122 );
123
124 text_widget3
125 .get_config()
126 .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 0));
127
128 let mut slider4 = SliderWidget::new(
129 make_points(60, 80),
130 make_size(20, 170),
131 20,
132 80,
133 40,
134 SliderVertical,
135 );
136
137 slider4.on_value_changed(|_slider, _widgets, _layouts, pos| {
138 let text4_id = widget_id_for_name(_widgets, String::from("text4"));
139
140 cast!(_widgets, text4_id, TextWidget).set_text(format!("{}", pos));
141 });
142
143 let mut text_widget4 = TextWidget::new(
144 String::from("assets/OpenSans-Regular.ttf"),
145 sdl2::ttf::FontStyle::NORMAL,
146 16,
147 TextJustify::Center,
148 String::from("40"),
149 make_points(56, 270),
150 make_size(50, 20),
151 );
152
153 text_widget4
154 .get_config()
155 .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 0));
156
157 engine.add_widget(Box::new(slider1), String::from("slider1"));
158 engine.add_widget(Box::new(text_widget1), String::from("text1"));
159 engine.add_widget(Box::new(slider2), String::from("slider2"));
160 engine.add_widget(Box::new(text_widget2), String::from("text2"));
161 engine.add_widget(Box::new(slider3), String::from("slider3"));
162 engine.add_widget(Box::new(text_widget3), String::from("text3"));
163 engine.add_widget(Box::new(slider4), String::from("slider4"));
164 engine.add_widget(Box::new(text_widget4), String::from("text4"));
165
166 engine.run(sdl_context, window);
167}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}Sourcepub fn set_numeric(&mut self, config: u8, value: i32)
pub fn set_numeric(&mut self, config: u8, value: i32)
Sets a numeric value for a configuration key.
Examples found in repository?
32pub fn main() {
33 let sdl_context = sdl2::init().unwrap();
34 let video_subsystem = sdl_context.video().unwrap();
35 let window = video_subsystem
36 .window("pushrod-render grid demo", 600, 340)
37 .position_centered()
38 .opengl()
39 .build()
40 .unwrap();
41 let mut engine = Engine::new(600, 340, 60);
42 let mut grid1 = GridWidget::new(make_points(20, 20), make_size(280, 280), 10, false);
43 let mut grid2 = GridWidget::new(make_points(310, 20), make_size(280, 280), 10, true);
44
45 grid1
46 .get_config()
47 .set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
48 grid1.get_config().set_numeric(CONFIG_BORDER_WIDTH, 1);
49
50 grid2
51 .get_config()
52 .set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
53 grid2.get_config().set_numeric(CONFIG_BORDER_WIDTH, 1);
54
55 let mut slider1 = SliderWidget::new(
56 make_points(20, 310),
57 make_size(320, 20),
58 1,
59 20,
60 10,
61 SliderHorizontal,
62 );
63
64 slider1.on_value_changed(|_slider, _widgets, _layouts, pos| {
65 let text1_id = widget_id_for_name(_widgets, String::from("text1"));
66 let grid1_id = widget_id_for_name(_widgets, String::from("grid1"));
67 let grid2_id = widget_id_for_name(_widgets, String::from("grid2"));
68
69 cast!(_widgets, text1_id, TextWidget).set_text(format!("{}", pos));
70 cast!(_widgets, grid1_id, GridWidget).set_grid_size(pos);
71 cast!(_widgets, grid2_id, GridWidget).set_grid_size(pos);
72 });
73
74 let mut text_widget1 = TextWidget::new(
75 String::from("assets/OpenSans-Regular.ttf"),
76 sdl2::ttf::FontStyle::NORMAL,
77 16,
78 TextJustify::Left,
79 String::from("10"),
80 make_points(360, 310),
81 make_size(40, 20),
82 );
83
84 text_widget1
85 .get_config()
86 .set_color(CONFIG_COLOR_TEXT, Color::RGB(0, 0, 0));
87
88 engine.add_widget(Box::new(grid1), String::from("grid1"));
89 engine.add_widget(Box::new(grid2), String::from("grid2"));
90 engine.add_widget(Box::new(slider1), String::from("slider1"));
91 engine.add_widget(Box::new(text_widget1), String::from("text1"));
92
93 engine.run(sdl_context, window);
94}More examples
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 demo", 800, 600)
20 .position_centered()
21 .opengl()
22 .build()
23 .unwrap();
24 let mut engine = Engine::new(800, 600, 30);
25 let mut new_base_widget = BaseWidget::new(make_points(100, 100), make_size(600, 400));
26
27 new_base_widget
28 .get_config()
29 .set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
30 new_base_widget
31 .get_config()
32 .set_numeric(CONFIG_BORDER_WIDTH, 2);
33
34 new_base_widget
35 .get_callbacks()
36 .on_mouse_entered(|x, _widgets, _layouts| {
37 x.get_config()
38 .set_color(CONFIG_COLOR_BASE, Color::RGB(255, 0, 0));
39 x.get_config().set_invalidated(true);
40 _widgets[0]
41 .widget
42 .borrow_mut()
43 .get_config()
44 .set_invalidated(true);
45 eprintln!("Mouse Entered");
46 });
47
48 new_base_widget
49 .get_callbacks()
50 .on_mouse_exited(|x, _widgets, _layouts| {
51 x.get_config()
52 .set_color(CONFIG_COLOR_BASE, Color::RGB(255, 255, 255));
53 x.get_config().set_invalidated(true);
54 _widgets[0]
55 .widget
56 .borrow_mut()
57 .get_config()
58 .set_invalidated(true);
59 eprintln!("Mouse Exited");
60 });
61
62 new_base_widget
63 .get_callbacks()
64 .on_mouse_moved(|_widget, _widgets, _layouts, points| {
65 eprintln!("Mouse Moved: {:?}", points);
66 });
67
68 new_base_widget
69 .get_callbacks()
70 .on_mouse_scrolled(|_widget, _widgets, _layouts, points| {
71 eprintln!("Mouse Scrolled: {:?}", points);
72 });
73
74 new_base_widget.get_callbacks().on_mouse_clicked(
75 |_widget, _widgets, _layouts, button, clicks, state| {
76 eprintln!(
77 "Mouse Clicked: button={} clicks={} state={}",
78 button, clicks, state
79 );
80 },
81 );
82
83 engine.add_widget(Box::new(new_base_widget), String::from("widget1"));
84
85 engine.on_exit(|_| {
86 eprintln!("Application exiting.");
87 true
88 });
89
90 engine.run(sdl_context, window);
91}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 exit demo", 800, 600)
21 .position_centered()
22 .opengl()
23 .build()
24 .unwrap();
25 let mut engine = Engine::new(800, 600, 30);
26 let mut new_base_widget = BaseWidget::new(make_points(100, 100), make_size(600, 400));
27
28 new_base_widget
29 .get_config()
30 .set_color(CONFIG_COLOR_BORDER, Color::RGB(0, 0, 0));
31 new_base_widget
32 .get_config()
33 .set_numeric(CONFIG_BORDER_WIDTH, 2);
34
35 new_base_widget
36 .get_callbacks()
37 .on_mouse_entered(|x, _widgets, _layouts| {
38 x.get_config()
39 .set_color(CONFIG_COLOR_BASE, Color::RGB(255, 0, 0));
40 x.get_config().set_invalidated(true);
41 _widgets[0]
42 .widget
43 .borrow_mut()
44 .get_config()
45 .set_invalidated(true);
46 eprintln!("Mouse Entered");
47 });
48
49 new_base_widget
50 .get_callbacks()
51 .on_mouse_exited(|x, _widgets, _layouts| {
52 x.get_config()
53 .set_color(CONFIG_COLOR_BASE, Color::RGB(255, 255, 255));
54 x.get_config().set_invalidated(true);
55 _widgets[0]
56 .widget
57 .borrow_mut()
58 .get_config()
59 .set_invalidated(true);
60 eprintln!("Mouse Exited");
61 });
62
63 new_base_widget
64 .get_callbacks()
65 .on_mouse_moved(|_widget, _widgets, _layouts, points| {
66 eprintln!("Mouse Moved: {:?}", points);
67 });
68
69 new_base_widget
70 .get_callbacks()
71 .on_mouse_scrolled(|_widget, _widgets, _layouts, points| {
72 eprintln!("Mouse Scrolled: {:?}", points);
73 });
74
75 new_base_widget.get_callbacks().on_mouse_clicked(
76 |_widget, _widgets, _layouts, button, clicks, state| {
77 eprintln!(
78 "Mouse Clicked: button={} clicks={} state={}",
79 button, clicks, state
80 );
81 },
82 );
83
84 engine.add_widget(Box::new(new_base_widget), String::from("widget1"));
85
86 engine.on_exit(|engine| {
87 let buttons: Vec<_> = vec![
88 ButtonData {
89 flags: MessageBoxButtonFlag::RETURNKEY_DEFAULT,
90 button_id: 1,
91 text: "Yes",
92 },
93 ButtonData {
94 flags: MessageBoxButtonFlag::ESCAPEKEY_DEFAULT,
95 button_id: 2,
96 text: "No",
97 },
98 ];
99
100 let res = show_message_box(
101 MessageBoxFlag::WARNING,
102 buttons.as_slice(),
103 "Quit",
104 "Are you sure?",
105 None,
106 None,
107 )
108 .unwrap();
109
110 if let ClickedButton::CustomButton(x) = res {
111 if x.button_id == 1 {
112 return true;
113 }
114 }
115
116 false
117 });
118
119 engine.run(sdl_context, window);
120}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}Sourcepub fn set_text(&mut self, config: u8, text: String)
pub fn set_text(&mut self, config: u8, text: String)
Sets a text value for a configuration key.
Sourcepub fn set_toggle(&mut self, config: u8, flag: bool)
pub fn set_toggle(&mut self, config: u8, flag: bool)
Sets a toggle for a configuration key.
Sourcepub fn set_compass(&mut self, config: u8, value: CompassPosition)
pub fn set_compass(&mut self, config: u8, value: CompassPosition)
Sets a compass position for a configuration key.
Sourcepub fn set_padding(&mut self, config: u8, value: PaddingConstraint)
pub fn set_padding(&mut self, config: u8, value: PaddingConstraint)
Applies a PaddingConstraint.
Sourcepub fn get_point(&self, k: u8) -> Points
pub fn get_point(&self, k: u8) -> Points
Retrieves a Points for a configuration key. Returns Points::default if not set.
Sourcepub fn get_size(&self, k: u8) -> Size
pub fn get_size(&self, k: u8) -> Size
Retrieves a Size for a configuration key. Returns a Size::default if not set.
Sourcepub fn get_color(&self, k: u8) -> Color
pub fn get_color(&self, k: u8) -> Color
Retrieves a Color for a configuration key. Returns white if not set.
Sourcepub fn get_numeric(&self, k: u8) -> i32
pub fn get_numeric(&self, k: u8) -> i32
Retrieves a numeric value for a configuration key. Returns 0 if not set.
Sourcepub fn get_text(&self, k: u8) -> String
pub fn get_text(&self, k: u8) -> String
Retrieves text for a configuration key. Returns a blank string if not set.
Sourcepub fn get_toggle(&self, k: u8) -> bool
pub fn get_toggle(&self, k: u8) -> bool
Retrieves a boolean toggle for a configuration key. Returns false if not set.
Sourcepub fn get_compass(&self, k: u8) -> CompassPosition
pub fn get_compass(&self, k: u8) -> CompassPosition
Retrieves a CompassPosition toggle for a configuration key. Returns CompassPosition::W if not set.
Sourcepub fn get_padding(&self, k: u8) -> PaddingConstraint
pub fn get_padding(&self, k: u8) -> PaddingConstraint
Retrieves a PaddingConstraint toggle for a configuration key. Returns empty PaddingConstraint if not set.