pub struct TabBarWidget { /* private fields */ }Expand description
This is the storage object for the TabBarWidget. It stores the config, properties, callback registry, tab
items, and other storage values for internal rendering.
Implementations§
Source§impl TabBarWidget
This is the implementation of the TabBarWidget, which displays a series of tabs specified by the
tab items in the constructor. Tab bar items are automatically sized and rendered depending on the
number of items specified.
impl TabBarWidget
This is the implementation of the TabBarWidget, which displays a series of tabs specified by the
tab items in the constructor. Tab bar items are automatically sized and rendered depending on the
number of items specified.
Sourcepub fn new(points: Points, size: Size, tab_items: Vec<String>) -> Self
pub fn new(points: Points, size: Size, tab_items: Vec<String>) -> Self
Creates a new TabBarWidget, given the x, y, w, h coordinates, and the tab items to be shown
in the tab bar area.
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 tab bar demo", 400, 300)
20 .position_centered()
21 .opengl()
22 .build()
23 .unwrap();
24 let mut engine = Engine::new(400, 300, 60);
25 let mut widget1 = TabBarWidget::new(
26 make_points(20, 20),
27 make_size(360, 30),
28 vec![
29 String::from("First"),
30 String::from("Second"),
31 String::from("Third"),
32 ],
33 );
34
35 widget1.set_color(CONFIG_COLOR_BASE, Color::RGB(255, 255, 255));
36 widget1.set_color(CONFIG_COLOR_HOVER, Color::RGB(192, 192, 255));
37 widget1.on_tab_selected(|_, _, _, selected_tab| {
38 eprintln!("Selected tab: {}", selected_tab);
39 });
40
41 engine.add_widget(Box::new(widget1), String::from("widget1"));
42
43 engine.run(sdl_context, window);
44}Sourcepub fn on_tab_selected<F>(&mut self, callback: F)
pub fn on_tab_selected<F>(&mut self, callback: F)
Assigns the callback closure that will be used when a tab is selected.
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 tab bar demo", 400, 300)
20 .position_centered()
21 .opengl()
22 .build()
23 .unwrap();
24 let mut engine = Engine::new(400, 300, 60);
25 let mut widget1 = TabBarWidget::new(
26 make_points(20, 20),
27 make_size(360, 30),
28 vec![
29 String::from("First"),
30 String::from("Second"),
31 String::from("Third"),
32 ],
33 );
34
35 widget1.set_color(CONFIG_COLOR_BASE, Color::RGB(255, 255, 255));
36 widget1.set_color(CONFIG_COLOR_HOVER, Color::RGB(192, 192, 255));
37 widget1.on_tab_selected(|_, _, _, selected_tab| {
38 eprintln!("Selected tab: {}", selected_tab);
39 });
40
41 engine.add_widget(Box::new(widget1), String::from("widget1"));
42
43 engine.run(sdl_context, window);
44}Trait Implementations§
Source§impl Widget for TabBarWidget
This is the Widget implementation of the TabBarWidget.
impl Widget for TabBarWidget
This is the Widget implementation of the TabBarWidget.
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. Overridden by
this Widget.
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. Overidden by
this Widget.
Source§fn mouse_moved(
&mut self,
_widgets: &[WidgetContainer],
_layouts: &[LayoutContainer],
points: Points,
)
fn mouse_moved( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], points: Points, )
Overrides the mouse_moved function, used to determine the position of the tab bar that is
currently under the mouse coordinates.
Overrides the button_clicked function, used to determine when a mouse clicks inside the bounds
of a tab, triggering the on_tab_selected callback where appropriate.
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 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>
mut in
your implementation (ie fn draw(&mut self, mut canvas: Canvas<Window>)). The _canvas
is the currently active drawing canvas at the time this function is called. This called
during the draw loop of the Engine. This returns a reference to the stored Texture object
within the Widget. It is then copied to the canvas, and displayed in the display loop.
In this function, you can just return a reference to the Texture if no invalidation state
was set, otherwise, the draw can be re-performed, and the Texture returned. If the drawing
function returns no texture, return a None, and it will not be rendered during the display
loop, but it will still be called. A TextureCache is provided in case your Widget needs
to cache an image or a font store. Read moreSource§fn mouse_scrolled(
&mut self,
_widgets: &[WidgetContainer],
_layouts: &[LayoutContainer],
_points: Points,
)
fn mouse_scrolled( &mut self, _widgets: &[WidgetContainer], _layouts: &[LayoutContainer], _points: Points, )
Widget, this function is
triggered. Movement along the X axis indicate horizontal movement, where the Y axis
indicates vertical movement. Positive movement means to the right or down, respectively.
Negative movement means to the left or up, respectively. This function implementation
is optional.Source§fn 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.