Skip to main content

WidgetCache

Struct WidgetCache 

Source
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.

Source

pub fn new() -> Self

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn button_clicked( &mut self, widget_id: i32, button: u8, clicks: u8, state: bool, cache: &[LayoutContainer], )

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for WidgetCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.