pub struct WidgetCache { /* private fields */ }Expand description
This is the WidgetCache struct, which contains a list of Widgets that are managed by the Pushrod
Engine. Widget IDs are automatically generated by the WidgetCache, which automatically
assigns the Widget ID at the time it’s added to the cache. Parent IDs must already exist,
otherwise, an error is thrown at the time the Widget is attempted to be added. Widget IDs
always start at 1.
Implementations§
Source§impl WidgetCache
This is the WidgetCache implementation. This cache object manages the Widget list for use by the
Pushrod Engine.
impl WidgetCache
This is the WidgetCache implementation. This cache object manages the Widget list for use by the
Pushrod Engine.
pub fn new() -> Self
Sourcepub fn add_widget(
&mut self,
widget: Box<dyn Widget>,
widget_name: String,
) -> i32
pub fn add_widget( &mut self, widget: Box<dyn Widget>, widget_name: String, ) -> i32
This adds a Widget to the render list. It requires that the Widget being added is in a Box,
along with a widget_name. Returns the ID of the Widget that was added. Use this ID if
you plan on adding further Widgets, with this Widget as the parent. The point of
origin (extracted from the Widget’s position at creation time) is its physical location
inside the Window.
Sourcepub fn find_widget(&mut self, x: i32, y: i32) -> i32
pub fn find_widget(&mut self, x: i32, y: i32) -> i32
This locates the ID of a Widget at a given x and y coordinate. If a Widget could not
be found, the top-level Widget (id 0) is returned. This function returns the top-most
visible Widget id.
Sourcepub fn get_container_by_id(&mut self, id: i32) -> &mut WidgetContainer
pub fn get_container_by_id(&mut self, id: i32) -> &mut WidgetContainer
Returns a WidgetContainer object by its ID. This is the same Widget ID that is returned
when using the add_widget function. There are no bounds checks here, so if the ID does not
exist, it will throw an exception at runtime. Be careful: it’s better to use the
get_container_by_name function to avoid this.
Sourcepub fn get_container_by_name(&mut self, name: String) -> &mut WidgetContainer
pub fn get_container_by_name(&mut self, name: String) -> &mut WidgetContainer
Returns a WidgetContainer object by the name of the Widget. If the WidgetContainer
cannot find the Widget by the name specified, the top-level Widget is returned for
safety.
This function calls the button_clicked callback for the Widget specified by widget_id.
When state is set to true, this indicates that a mouse button down was detected. When set
to false, it indicates that the mouse button was released. When setting the button state
to widget_id == -1, the button click message will be sent to all Widgets, so use
widget_id == -1 with care.
Sourcepub fn mouse_moved(
&mut self,
widget_id: i32,
points: Vec<i32>,
cache: &[LayoutContainer],
)
pub fn mouse_moved( &mut self, widget_id: i32, points: Vec<i32>, cache: &[LayoutContainer], )
This function calls the mouse_moved callback for the Widget specified by widget_id.
Sourcepub fn mouse_scrolled(
&mut self,
widget_id: i32,
points: Vec<i32>,
cache: &[LayoutContainer],
)
pub fn mouse_scrolled( &mut self, widget_id: i32, points: Vec<i32>, cache: &[LayoutContainer], )
This function calls the mouse_scrolled callback for the Widget specified by widget_id.
Sourcepub fn mouse_exited(&mut self, widget_id: i32, cache: &[LayoutContainer])
pub fn mouse_exited(&mut self, widget_id: i32, cache: &[LayoutContainer])
This function calls the mouse_exited callback for the Widget specified by widget_id.
Sourcepub fn mouse_entered(&mut self, widget_id: i32, cache: &[LayoutContainer])
pub fn mouse_entered(&mut self, widget_id: i32, cache: &[LayoutContainer])
This function calls the mouse_entered callback for the Widget specified by widget_id.
Sourcepub fn tick(&mut self, _cache: &[LayoutContainer])
pub fn tick(&mut self, _cache: &[LayoutContainer])
This function calls the tick method on all registered Widgets in the cache. The purpose
for the tick is to indicate that a drawing loop is about to occur, and the Widget can
update itself as necessary beforehand.
Sourcepub fn other_event(
&mut self,
widget_id: i32,
event: Event,
cache: &[LayoutContainer],
)
pub fn other_event( &mut self, widget_id: i32, event: Event, cache: &[LayoutContainer], )
This function sends all other un-handled events from SDL2 to the currently highlighted
Widget.
Sourcepub fn draw_loop(&mut self, c: &mut Canvas<Window>) -> bool
pub fn draw_loop(&mut self, c: &mut Canvas<Window>) -> bool
This function performs the draw loop for all of the Widgets stored in the cache. Each
Widget receives a mutable reference to the Canvas so that the Widget can be drawn on
the screen during the draw loop of the Engine. This draw_loop function automatically
clips the screen area so that the Widget cannot draw outside of its bounds. Returns true
if the display loop needs to refresh the top-level canvas, false otherwise.
Sourcepub fn borrow_cache(&mut self) -> &[WidgetContainer]
pub fn borrow_cache(&mut self) -> &[WidgetContainer]
Returns a borrowed slice of the WidgetContainer Vec object, which can be passed on to
Layout objects so that the layout can be computed and performed.