pub struct CallbackRegistry {
pub on_tick: FunctionNoParametersType,
pub on_mouse_entered: FunctionNoParametersType,
pub on_mouse_exited: FunctionNoParametersType,
pub on_mouse_moved: FunctionPointParametersType,
pub on_mouse_scrolled: FunctionPointParametersType,
pub on_mouse_clicked: FunctionClickParametersType,
/* private fields */
}Expand description
This is a registry that contains a series of FnMut definitions for actions that can be applied
to a Widget. These can vary from a screen refresh (tick), to a mouse move event, etc. Each
callback gains access to the list of WidgetContainer objects stored by the cache. This is
important in case you wish to modify other Widgets on the screen as a result of some action
that took place.
Keep in mind, however, that you cannot re-borrow your own widget from the WidgetContainer
list, as this will cause a runtime exception. For that, use the top-level Widget object that
was supplied. This will allow you to make changes to the current Widget reference, since it
is an active, mutable reference.
Fields§
§on_tick: FunctionNoParametersTypeThis is the function that is set when a screen refresh cycle occurs. This function is always guaranteed to be called, but there is no guarantee it will call it consistently because of the screen refresh rate. If there is a lot of activity on the screen, this callback will be called less often.
on_mouse_entered: FunctionNoParametersTypeThis function is called when a mouse enters the scope of a Widget.
on_mouse_exited: FunctionNoParametersTypeThis function is called when a mouse exits the scope of a Widget.
on_mouse_moved: FunctionPointParametersTypeThis function is called when a mouse moves inside the scope of a Widget. It contains
the points as a Vec<i32> containing the X and Y coordinates of the position of the mouse
inside the Widget.
on_mouse_scrolled: FunctionPointParametersTypeThis function is called when a mouse scroll occurs inside the scope of a Widget. It
contains the points as a Vec<u8> indicating the amount of movement either horizontally or
vertically.
on_mouse_clicked: FunctionClickParametersTypeThis function is called when a mouse button is pressed or released. It contains the mouse
button number, the number of clicks registered, and a boolean flag indicating whether or not
the mouse button was pressed (true) or released (false).
Implementations§
Source§impl CallbackRegistry
Implementation of the CallbackRegistry.
impl CallbackRegistry
Implementation of the CallbackRegistry.
Sourcepub fn on_tick<F>(&mut self, callback: F)
pub fn on_tick<F>(&mut self, callback: F)
Assigns an FnMut that will be called when a screen tick refresh is performed. If this
is not set, this function will be bypassed.
Sourcepub fn on_mouse_entered<F>(&mut self, callback: F)
pub fn on_mouse_entered<F>(&mut self, callback: F)
Assigns an FnMut that will be called when the mouse enters the scope of a Widget. If this
is not set, this function will be bypassed.
Examples found in repository?
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}More examples
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 on_mouse_exited<F>(&mut self, callback: F)
pub fn on_mouse_exited<F>(&mut self, callback: F)
Assigns an FnMut that will be called when the mouse exits the scope of a Widget. If this
is not set, this function will be bypassed.
Examples found in repository?
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}More examples
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 on_mouse_moved<F>(&mut self, callback: F)
pub fn on_mouse_moved<F>(&mut self, callback: F)
Assigns an FnMut that will be called when the mouse moves within the scope of a Widget. If this
is not set, this function will be bypassed.
Examples found in repository?
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}More examples
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 on_mouse_scrolled<F>(&mut self, callback: F)
pub fn on_mouse_scrolled<F>(&mut self, callback: F)
Assigns an FnMut that will be called when the mouse scroll occurs within the scope of a
Widget. If this is not set, this function will be bypassed.
Examples found in repository?
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}More examples
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 on_mouse_clicked<F>(&mut self, callback: F)
pub fn on_mouse_clicked<F>(&mut self, callback: F)
Assigns an FnMut that will be called when the mouse click occurs within the scope of a
Widget. If this is not set, this function will be bypassed.
Examples found in repository?
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}More examples
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 has_on_tick(&mut self) -> bool
pub fn has_on_tick(&mut self) -> bool
Tells the Widget whether or not an on_tick callback has been set.
Sourcepub fn has_on_mouse_entered(&mut self) -> bool
pub fn has_on_mouse_entered(&mut self) -> bool
Tells the Widget whether or not an on_mouse_entered callback has been set.
Sourcepub fn has_on_mouse_exited(&mut self) -> bool
pub fn has_on_mouse_exited(&mut self) -> bool
Tells the Widget whether or not an on_mouse_exited callback has been set.
Sourcepub fn has_on_mouse_moved(&mut self) -> bool
pub fn has_on_mouse_moved(&mut self) -> bool
Tells the Widget whether or not an on_mouse_moved callback has been set.
Sourcepub fn has_on_mouse_scrolled(&mut self) -> bool
pub fn has_on_mouse_scrolled(&mut self) -> bool
Tells the Widget whether or not an on_mouse_scrolled callback has been set.
Sourcepub fn has_on_mouse_clicked(&mut self) -> bool
pub fn has_on_mouse_clicked(&mut self) -> bool
Tells the Widget whether or not an on_mouse_clicked callback has been set.