pub struct SliderWidget { /* private fields */ }Expand description
This is the storage object for the SliderWidget. It stores the config, properties, callback registry.
Implementations§
Source§impl SliderWidget
This is the implementation of the SliderWidget, a control that draws a bounds line indicator, and a
draggable slider.
impl SliderWidget
This is the implementation of the SliderWidget, a control that draws a bounds line indicator, and a
draggable slider.
Sourcepub fn new(
points: Points,
size: Size,
min: u32,
max: u32,
current: u32,
orientation: SliderOrientation,
) -> Self
pub fn new( points: Points, size: Size, min: u32, max: u32, current: u32, orientation: SliderOrientation, ) -> Self
Creates a new SliderWidget given the x, y, w, h coordinates, sets the min and max values,
the current value, and the orientation of the slider as drawn.
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
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}Sourcepub fn on_value_changed<F>(&mut self, callback: F)
pub fn on_value_changed<F>(&mut self, callback: F)
Assigns the callback closure that will be used when the Widget changes value.
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
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}Trait Implementations§
Source§impl CanvasHelper for SliderWidget
impl CanvasHelper for SliderWidget
Source§impl Widget for SliderWidget
This is the Widget implementation of the SliderWidget.
impl Widget for SliderWidget
This is the Widget implementation of the SliderWidget.
Source§fn draw(
&mut self,
c: &mut Canvas<Window>,
_t: &mut TextureCache,
) -> Option<&Texture>
fn draw( &mut self, c: &mut Canvas<Window>, _t: &mut TextureCache, ) -> Option<&Texture>
Draws the SliderWidget contents.
Source§fn mouse_entered(
&mut self,
_widgets: &[WidgetContainer],
_layouts: &[LayoutContainer],
)
fn mouse_entered( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], )
When a mouse enters the bounds of the Widget, this function is triggered.
Source§fn mouse_exited(
&mut self,
_widgets: &[WidgetContainer],
_layouts: &[LayoutContainer],
)
fn mouse_exited( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], )
When a mouse exits the bounds of the Widget, this function is triggered.
Source§fn mouse_moved(
&mut self,
_widgets: &[WidgetContainer],
_layouts: &[LayoutContainer],
points: Points,
)
fn mouse_moved( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], points: Points, )
When a mouse is moved in the bounds of this Widget, this function is triggered.
Source§fn mouse_scrolled(
&mut self,
_widgets: &[WidgetContainer],
_layouts: &[LayoutContainer],
points: Points,
)
fn mouse_scrolled( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], points: Points, )
Handles the scrolling functionality.
Overrides the button_clicked callback to handle toggling.
Source§fn as_any(&mut self) -> &mut dyn Any
fn as_any(&mut self) -> &mut dyn Any
This function is a macro-created getter function that returns the Widget as an Any
type. This allows the Widget trait to be downcast into a struct that implements
the Widget trait.
Source§fn get_config(&mut self) -> &mut WidgetConfig
fn get_config(&mut self) -> &mut WidgetConfig
This function is a macro-created getter function that returns the Widget’s configuration
object as a borrowed mutable reference. This code is auto-generated using the
default_widget_properties!() macro.
Source§fn get_system_properties(&mut self) -> &mut HashMap<i32, String>
fn get_system_properties(&mut self) -> &mut HashMap<i32, String>
This function is a macro-created getter function that returns the Widget’s system
properties as a borrowed mutable reference. This code is auto-generated using the
default_widget_properties!() macro.
Source§fn get_callbacks(&mut self) -> &mut CallbackRegistry
fn get_callbacks(&mut self) -> &mut CallbackRegistry
This function is a macro-created getter function that returns the Widget’s
CallbackRegistry object as a borrowed mutable reference. This code is auto-generated
using the default_widget_properties!() macro.
Source§fn tick_callback(
&mut self,
_widgets: &[WidgetContainer],
_layouts: &[LayoutContainer],
)
fn tick_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], )
This function is a macro-created tick callback override, created by the
default_widget_callbacks!() macro.
Source§fn mouse_entered_callback(
&mut self,
_widgets: &[WidgetContainer],
_layouts: &[LayoutContainer],
)
fn mouse_entered_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], )
This function is a macro-created mouse entered callback override, created by the
default_widget_callbacks!() macro.
Source§fn mouse_exited_callback(
&mut self,
_widgets: &[WidgetContainer],
_layouts: &[LayoutContainer],
)
fn mouse_exited_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], )
This function is a macro-created mouse exited callback override, created by the
default_widget_callbacks!() macro.
Source§fn mouse_moved_callback(
&mut self,
_widgets: &[WidgetContainer],
_layouts: &[LayoutContainer],
_points: Points,
)
fn mouse_moved_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _points: Points, )
This function is a macro-created mouse moved callback override, created by the
default_widget_callbacks!() macro.
Source§fn mouse_scrolled_callback(
&mut self,
_widgets: &[WidgetContainer],
_layouts: &[LayoutContainer],
_points: Points,
)
fn mouse_scrolled_callback( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _points: Points, )
This function is a macro-created mouse scrolled callback override, created by the
default_widget_callbacks!() macro.
This function is a macro-created mouse scrolled callback override, created by the
default_widget_callbacks!() macro.
Source§fn tick(&mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer])
fn tick(&mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer])
Source§fn other_event(
&mut self,
_widgets: &[WidgetContainer],
_layouts: &[LayoutContainer],
_event: Event,
)
fn other_event( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _event: Event, )
Event is sent to the application that is not handled by the Engine::run loop, this
method is called, sending the unhandled Event to the currently active Widget. This behavior
is subject to change as the Engine::run loop is modified to handle more Events.Source§fn on_config_changed(&mut self, _k: u8, _v: Config)
fn on_config_changed(&mut self, _k: u8, _v: Config)
get_config() using the setter is called, so it is best to use the top-level setters
and getters for the configuration values - at least, until the get_config() call can be made
private.Source§fn set_numeric(&mut self, config: u8, value: i32)
fn set_numeric(&mut self, config: u8, value: i32)
Source§fn set_toggle(&mut self, config: u8, flag: bool)
fn set_toggle(&mut self, config: u8, flag: bool)
Source§fn set_compass(&mut self, config: u8, value: CompassPosition)
fn set_compass(&mut self, config: u8, value: CompassPosition)
Source§fn get_point(&mut self, k: u8) -> Points
fn get_point(&mut self, k: u8) -> Points
Points for a configuration key. Returns Points::default if not set.Source§fn get_size(&mut self, k: u8) -> Size
fn get_size(&mut self, k: u8) -> Size
Size for a configuration key. Returns a Size::default if not set.Source§fn get_color(&mut self, k: u8) -> Color
fn get_color(&mut self, k: u8) -> Color
Color for a configuration key. Returns white if not set.Source§fn get_numeric(&mut self, k: u8) -> i32
fn get_numeric(&mut self, k: u8) -> i32
Source§fn get_text(&mut self, k: u8) -> String
fn get_text(&mut self, k: u8) -> String
Source§fn get_toggle(&mut self, k: u8) -> bool
fn get_toggle(&mut self, k: u8) -> bool
false if not set.Source§fn get_compass(&mut self, k: u8) -> CompassPosition
fn get_compass(&mut self, k: u8) -> CompassPosition
CompassPosition toggle for a configuration key. Returns CompassPosition::W if not set.Source§fn set_origin(&mut self, _origin: Points)
fn set_origin(&mut self, _origin: Points)
Widget, adjusting the X and Y coordinates. Automatically sets the
invalidate flag to true when adjusted, but only if the new origin is not the same as
the previous origin.Source§fn set_size(&mut self, _size: Vec<u32>)
fn set_size(&mut self, _size: Vec<u32>)
Widget, adjusting the width and height. Automatically
sets the invalidate flag to true when adjusted, but only if the new size is not the
same as the previous size.Source§fn get_drawing_area(&mut self) -> Rect
fn get_drawing_area(&mut self) -> Rect
Rect object containing the drawing bounds of this Widget.Source§fn is_invalidated(&mut self) -> bool
fn is_invalidated(&mut self) -> bool
Widget is invalidated state.Source§fn set_invalidated(&mut self, flag: bool)
fn set_invalidated(&mut self, flag: bool)
Widget.