[−][src]Trait pushrod::widget::widget::Widget
Implementable trait that is used by every Widget. These are the public methods,
and a function may override them.
You must implement the following methods:
- config
- callbacks
You should override draw, but you are not required to. (If you don't, however, your
widget won't really do much.)
If you want a blank base widget, refer to the CanvasWidget, which will create a
base widget that paints the contents of its bounds with whatever color has been
specified with set_color.
Required methods
fn config(&mut self) -> &mut Configurable
Retrieves the configuration HashMap that stores the configuration list of settings for this widget.
To implement this, the following code could be used in your object's structure:
struct MyWidget { config: Configurable, } impl MyWidget { fn new() -> Self { Self { config: Configurable::new(), } } }
And in the overridden function for get_config in your implementation, use:
struct MyWidget { config: Configurable, callbacks: CallbackStore, } impl Widget for MyWidget { fn config(&mut self) -> &mut Configurable { &mut self.config } fn callbacks(&mut self) -> &mut CallbackStore { &mut self.callbacks } // Not necessary below, but here for illustration if you want to override these calls. fn mouse_entered(&mut self, widget_id: i32) {} fn mouse_exited(&mut self, widget_id: i32) {} fn mouse_scrolled(&mut self, widget_id: i32, point: Point) {} }
This uses a RefCell, since configurations require a mutable reference to the HashMap
that stores the configs.
fn callbacks(&mut self) -> &mut CallbackStore
Returns the CallbackStore for this Widget. This contains a set of callbacks that only
apply to this Widget.
Provided methods
fn invalidate(&mut self)
Indicates that a widget needs to be redrawn/refreshed.
fn clear_invalidate(&mut self)
Clears the invalidation flag.
fn is_invalidated(&mut self) -> bool
Checks to see whether or not the widget needs to be redrawn/refreshed.
fn set_origin(&mut self, x: i32, y: i32)
Sets the Point of origin for this widget, given the X and Y origin points. Invalidates the widget afterward.
fn get_origin(&mut self) -> Point
Retrieves the Point of origin for this object.
Defaults to origin (0, 0) if not set.
fn set_size(&mut self, w: i32, h: i32)
Sets the Size for this widget, given a width and height. Invalidates the widget afterward.
fn get_size(&mut self) -> Size
Retrieves the Size bounds for this widget.
Defaults to size (0, 0) if not set.
fn set_color(&mut self, color: Color)
Sets the color for this widget. Invalidates the widget afterward.
fn get_color(&mut self) -> Color
Retrieves the color of this widget.
Defaults to white color [1.0; 4] if not set.
fn perform_single_callback(&mut self, callback_id: u32, widget_id: i32)
Performs a callback stored in the CallbackStore for this Widget, but only for the
CallbackTypes::SingleCallback enum type. If the callback does not exist, or is not
defined properly, it will be silently dropped and ignored.
fn perform_bool_callback(
&mut self,
callback_id: u32,
widget_id: i32,
flag: bool
)
&mut self,
callback_id: u32,
widget_id: i32,
flag: bool
)
Performs a callback stored in the CallbackStore for this Widget, but only for the
CallbackTypes::BoolCallback enum type. If the callback does not exist, or is not
defined properly, it will be silently dropped and ignored.
fn perform_point_callback(
&mut self,
callback_id: u32,
widget_id: i32,
point: Point
)
&mut self,
callback_id: u32,
widget_id: i32,
point: Point
)
Performs a callback stored in the CallbackStore for this Widget, but only for the
CallbackTypes::PointCallback enum type. If the callback does not exist, or is not
defined properly, it will be silently dropped and ignored.
fn perform_size_callback(
&mut self,
callback_id: u32,
widget_id: i32,
size: Size
)
&mut self,
callback_id: u32,
widget_id: i32,
size: Size
)
Performs a callback stored in the CallbackStore for this Widget, but only for the
CallbackTypes::SizeCallback enum type. If the callback does not exist, or is not
defined properly, it will be silently dropped and ignored.
fn perform_button_callback(
&mut self,
callback_id: u32,
widget_id: i32,
button: Button
)
&mut self,
callback_id: u32,
widget_id: i32,
button: Button
)
fn perform_key_callback(
&mut self,
callback_id: u32,
widget_id: i32,
key: Key,
state: ButtonState
)
&mut self,
callback_id: u32,
widget_id: i32,
key: Key,
state: ButtonState
)
Performs a callback stored in the CallbackStore for this Widget, but only for the
CallbackTypes::KeyCallback enum type. If the callback does not exist, or is not
defined properly, it will be silently dropped and ignored.
fn key_pressed(&mut self, widget_id: i32, key: &Key, state: &ButtonState)
Called when a keyboard event takes place within the bounds of a widget. Includes the widget ID, the key code that was affected, and its state - pressed or released.
fn mouse_entered(&mut self, widget_id: i32)
Called when a mouse enters the bounds of the widget. Includes the widget ID. Only override if you want to signal a mouse enter event.
fn mouse_exited(&mut self, widget_id: i32)
Called when a mouse exits the bounds of the widget. Includes the widget ID. Only override if you want to signal a mouse exit event.
fn mouse_scrolled(&mut self, widget_id: i32, point: Point)
Called when a scroll event is called within the bounds of the widget. Includes the widget ID. Only override if you want to signal a mouse scroll event.
fn mouse_moved(&mut self, widget_id: i32, point: Point)
Called when the mouse pointer is moved inside a widget. Includes the widget ID and point. Only override if you want to track mouse movement.
fn window_resized(&mut self, widget_id: i32, size: Size)
Called when the main window is resized. Includes the widget ID and the new window size. Only override if you want to respond to a window resize (and if the window is resizable.)
fn window_focused(&mut self, widget_id: i32, focused: bool)
Called when a window focus state changes. Includes the widget ID and a focus flag: true
when window gains focus, false otherwise. Only override if you want to signal a window
focus event.
fn button_down(&mut self, widget_id: i32, button: Button)
Called when a mouse button is clicked down. Includes the widget ID and the button code. Only override if you want to respond to a mouse click.
fn button_up_inside(&mut self, widget_id: i32, button: Button)
Called when a mouse button is released inside the same Widget that it was clicked inside.
Includes the widget ID and the button code. Only override if you want to respond to a mouse
button release.
fn button_up_outside(&mut self, widget_id: i32, button: Button)
Called when a mouse button is released outside the same Widget that it was clicked inside.
Includes the widget ID and the button code. Only override if you want to respond to a mouse
button release.
fn on_key_pressed(&mut self, callback: KeyCallback)
fn on_mouse_entered(&mut self, callback: SingleCallback)
Sets the closure action to be performed when a mouse enters a Widget.
fn on_mouse_exited(&mut self, callback: SingleCallback)
Sets the closure action to be performed when a mouse exits a Widget.
fn on_mouse_scrolled(&mut self, callback: PointCallback)
Sets the closure action to be performed when a mouse scrolls inside a Widget.
fn on_mouse_moved(&mut self, callback: PointCallback)
Sets the closure action to be performed when a mouse moves within a Widget. The mouse
point is based on the position within the Widget, not its Point relative to the window.
fn on_window_resized(&mut self, callback: SizeCallback)
Sets the window resize action to be performed when the window is resized.
fn on_focused(&mut self, callback: BoolCallback)
Sets the window focused action to be performed when the window is (un)focused.
fn on_button_down(&mut self, callback: ButtonCallback)
Sets the button click action to be performed when a mouse button is clicked.
fn on_button_up_inside(&mut self, callback: ButtonCallback)
Sets the callback to be performed when a mouse button is released within the same Widget
that it was pressed down inside.
fn on_button_up_outside(&mut self, callback: ButtonCallback)
Sets the callback to be performed when a mouse button is released outside of the same Widget
that it was pressed down inside.
fn draw(&mut self, c: Context, g: &mut G2d, clip: &DrawState)
Draws the contents of the widget, provided a piston2d Context and G2d object.
It is highly recommended that you call clear_invalidate() after the draw completes,
otherwise, this will continue to be redrawn continuously (unless this is the desired
behavior.)
Implementors
impl Widget for BoxWidget[src]
Implementation of the BoxWidget object with the Widget traits implemented.
This implementation is similar to the CanvasWidget, but incorporates a drawable box inside
the widget. Base widget is the CanvasWidget.
This is basically just a box with a fill color. Use this to draw other things like buttons, text widgets, and so on, if you need anything with a drawable border.
fn config(&mut self) -> &mut Configurable[src]
fn callbacks(&mut self) -> &mut CallbackStore[src]
fn set_origin(&mut self, x: i32, y: i32)[src]
Sets the Point of origin for this widget and the base widget, given the X and Y
coordinates. Invalidates the widget afterward.
fn set_size(&mut self, w: i32, h: i32)[src]
Sets the Size for this widget and the base widget, given width and height. Invalidates the widget afterward.
fn set_color(&mut self, color: Color)[src]
Sets the color for this widget. Invalidates the widget afterward.
fn get_color(&mut self) -> Color[src]
Retrieves the color of this widget.
Defaults to white color [1.0; 4] if not set.
fn draw(&mut self, c: Context, g: &mut G2d, clip: &DrawState)[src]
Draws the contents of the widget in this order:
- Base widget first
- Box graphic for the specified width
fn invalidate(&mut self)[src]
fn clear_invalidate(&mut self)[src]
fn is_invalidated(&mut self) -> bool[src]
fn get_origin(&mut self) -> Point[src]
fn get_size(&mut self) -> Size[src]
fn perform_single_callback(&mut self, callback_id: u32, widget_id: i32)[src]
fn perform_bool_callback(
&mut self,
callback_id: u32,
widget_id: i32,
flag: bool
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
flag: bool
)
fn perform_point_callback(
&mut self,
callback_id: u32,
widget_id: i32,
point: Point
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
point: Point
)
fn perform_size_callback(
&mut self,
callback_id: u32,
widget_id: i32,
size: Size
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
size: Size
)
fn perform_button_callback(
&mut self,
callback_id: u32,
widget_id: i32,
button: Button
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
button: Button
)
fn perform_key_callback(
&mut self,
callback_id: u32,
widget_id: i32,
key: Key,
state: ButtonState
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
key: Key,
state: ButtonState
)
fn key_pressed(&mut self, widget_id: i32, key: &Key, state: &ButtonState)[src]
fn mouse_entered(&mut self, widget_id: i32)[src]
fn mouse_exited(&mut self, widget_id: i32)[src]
fn mouse_scrolled(&mut self, widget_id: i32, point: Point)[src]
fn mouse_moved(&mut self, widget_id: i32, point: Point)[src]
fn window_resized(&mut self, widget_id: i32, size: Size)[src]
fn window_focused(&mut self, widget_id: i32, focused: bool)[src]
fn button_down(&mut self, widget_id: i32, button: Button)[src]
fn button_up_inside(&mut self, widget_id: i32, button: Button)[src]
fn button_up_outside(&mut self, widget_id: i32, button: Button)[src]
fn on_key_pressed(&mut self, callback: KeyCallback)[src]
fn on_mouse_entered(&mut self, callback: SingleCallback)[src]
fn on_mouse_exited(&mut self, callback: SingleCallback)[src]
fn on_mouse_scrolled(&mut self, callback: PointCallback)[src]
fn on_mouse_moved(&mut self, callback: PointCallback)[src]
fn on_window_resized(&mut self, callback: SizeCallback)[src]
fn on_focused(&mut self, callback: BoolCallback)[src]
fn on_button_down(&mut self, callback: ButtonCallback)[src]
fn on_button_up_inside(&mut self, callback: ButtonCallback)[src]
fn on_button_up_outside(&mut self, callback: ButtonCallback)[src]
impl Widget for ImageWidget[src]
Implementation of the ImageWidget object. Draws an image on the screen based on the
image file you specify.
fn config(&mut self) -> &mut Configurable[src]
fn callbacks(&mut self) -> &mut CallbackStore[src]
fn draw(&mut self, c: Context, g: &mut G2d, clip: &DrawState)[src]
Draws the contents of the widget.
fn invalidate(&mut self)[src]
fn clear_invalidate(&mut self)[src]
fn is_invalidated(&mut self) -> bool[src]
fn set_origin(&mut self, x: i32, y: i32)[src]
fn get_origin(&mut self) -> Point[src]
fn set_size(&mut self, w: i32, h: i32)[src]
fn get_size(&mut self) -> Size[src]
fn set_color(&mut self, color: Color)[src]
fn get_color(&mut self) -> Color[src]
fn perform_single_callback(&mut self, callback_id: u32, widget_id: i32)[src]
fn perform_bool_callback(
&mut self,
callback_id: u32,
widget_id: i32,
flag: bool
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
flag: bool
)
fn perform_point_callback(
&mut self,
callback_id: u32,
widget_id: i32,
point: Point
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
point: Point
)
fn perform_size_callback(
&mut self,
callback_id: u32,
widget_id: i32,
size: Size
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
size: Size
)
fn perform_button_callback(
&mut self,
callback_id: u32,
widget_id: i32,
button: Button
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
button: Button
)
fn perform_key_callback(
&mut self,
callback_id: u32,
widget_id: i32,
key: Key,
state: ButtonState
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
key: Key,
state: ButtonState
)
fn key_pressed(&mut self, widget_id: i32, key: &Key, state: &ButtonState)[src]
fn mouse_entered(&mut self, widget_id: i32)[src]
fn mouse_exited(&mut self, widget_id: i32)[src]
fn mouse_scrolled(&mut self, widget_id: i32, point: Point)[src]
fn mouse_moved(&mut self, widget_id: i32, point: Point)[src]
fn window_resized(&mut self, widget_id: i32, size: Size)[src]
fn window_focused(&mut self, widget_id: i32, focused: bool)[src]
fn button_down(&mut self, widget_id: i32, button: Button)[src]
fn button_up_inside(&mut self, widget_id: i32, button: Button)[src]
fn button_up_outside(&mut self, widget_id: i32, button: Button)[src]
fn on_key_pressed(&mut self, callback: KeyCallback)[src]
fn on_mouse_entered(&mut self, callback: SingleCallback)[src]
fn on_mouse_exited(&mut self, callback: SingleCallback)[src]
fn on_mouse_scrolled(&mut self, callback: PointCallback)[src]
fn on_mouse_moved(&mut self, callback: PointCallback)[src]
fn on_window_resized(&mut self, callback: SizeCallback)[src]
fn on_focused(&mut self, callback: BoolCallback)[src]
fn on_button_down(&mut self, callback: ButtonCallback)[src]
fn on_button_up_inside(&mut self, callback: ButtonCallback)[src]
fn on_button_up_outside(&mut self, callback: ButtonCallback)[src]
impl Widget for TextWidget[src]
Implementation of the TextWidget object with the Widget traits implemented.
fn config(&mut self) -> &mut Configurable[src]
fn callbacks(&mut self) -> &mut CallbackStore[src]
fn draw(&mut self, c: Context, g: &mut G2d, clip: &DrawState)[src]
Draws the contents of the widget.
fn invalidate(&mut self)[src]
fn clear_invalidate(&mut self)[src]
fn is_invalidated(&mut self) -> bool[src]
fn set_origin(&mut self, x: i32, y: i32)[src]
fn get_origin(&mut self) -> Point[src]
fn set_size(&mut self, w: i32, h: i32)[src]
fn get_size(&mut self) -> Size[src]
fn set_color(&mut self, color: Color)[src]
fn get_color(&mut self) -> Color[src]
fn perform_single_callback(&mut self, callback_id: u32, widget_id: i32)[src]
fn perform_bool_callback(
&mut self,
callback_id: u32,
widget_id: i32,
flag: bool
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
flag: bool
)
fn perform_point_callback(
&mut self,
callback_id: u32,
widget_id: i32,
point: Point
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
point: Point
)
fn perform_size_callback(
&mut self,
callback_id: u32,
widget_id: i32,
size: Size
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
size: Size
)
fn perform_button_callback(
&mut self,
callback_id: u32,
widget_id: i32,
button: Button
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
button: Button
)
fn perform_key_callback(
&mut self,
callback_id: u32,
widget_id: i32,
key: Key,
state: ButtonState
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
key: Key,
state: ButtonState
)
fn key_pressed(&mut self, widget_id: i32, key: &Key, state: &ButtonState)[src]
fn mouse_entered(&mut self, widget_id: i32)[src]
fn mouse_exited(&mut self, widget_id: i32)[src]
fn mouse_scrolled(&mut self, widget_id: i32, point: Point)[src]
fn mouse_moved(&mut self, widget_id: i32, point: Point)[src]
fn window_resized(&mut self, widget_id: i32, size: Size)[src]
fn window_focused(&mut self, widget_id: i32, focused: bool)[src]
fn button_down(&mut self, widget_id: i32, button: Button)[src]
fn button_up_inside(&mut self, widget_id: i32, button: Button)[src]
fn button_up_outside(&mut self, widget_id: i32, button: Button)[src]
fn on_key_pressed(&mut self, callback: KeyCallback)[src]
fn on_mouse_entered(&mut self, callback: SingleCallback)[src]
fn on_mouse_exited(&mut self, callback: SingleCallback)[src]
fn on_mouse_scrolled(&mut self, callback: PointCallback)[src]
fn on_mouse_moved(&mut self, callback: PointCallback)[src]
fn on_window_resized(&mut self, callback: SizeCallback)[src]
fn on_focused(&mut self, callback: BoolCallback)[src]
fn on_button_down(&mut self, callback: ButtonCallback)[src]
fn on_button_up_inside(&mut self, callback: ButtonCallback)[src]
fn on_button_up_outside(&mut self, callback: ButtonCallback)[src]
impl Widget for TimerWidget[src]
Implementation of the TimerWidget object with the Widget traits implemented.
fn config(&mut self) -> &mut Configurable[src]
fn callbacks(&mut self) -> &mut CallbackStore[src]
fn is_invalidated(&mut self) -> bool[src]
Timer is always invalidated, this way, the tick function is always called on each screen refresh.
fn get_origin(&mut self) -> Point[src]
Origin is always set to X/Y at points 0x0.
fn get_size(&mut self) -> Size[src]
Size is always unsized, as timers are invisible.
fn draw(&mut self, _context: Context, _graphics: &mut G2d, _clip: &DrawState)[src]
Does not draw anything - only calls the timer tick() function to increment the
timer.
fn invalidate(&mut self)[src]
fn clear_invalidate(&mut self)[src]
fn set_origin(&mut self, x: i32, y: i32)[src]
fn set_size(&mut self, w: i32, h: i32)[src]
fn set_color(&mut self, color: Color)[src]
fn get_color(&mut self) -> Color[src]
fn perform_single_callback(&mut self, callback_id: u32, widget_id: i32)[src]
fn perform_bool_callback(
&mut self,
callback_id: u32,
widget_id: i32,
flag: bool
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
flag: bool
)
fn perform_point_callback(
&mut self,
callback_id: u32,
widget_id: i32,
point: Point
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
point: Point
)
fn perform_size_callback(
&mut self,
callback_id: u32,
widget_id: i32,
size: Size
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
size: Size
)
fn perform_button_callback(
&mut self,
callback_id: u32,
widget_id: i32,
button: Button
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
button: Button
)
fn perform_key_callback(
&mut self,
callback_id: u32,
widget_id: i32,
key: Key,
state: ButtonState
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
key: Key,
state: ButtonState
)
fn key_pressed(&mut self, widget_id: i32, key: &Key, state: &ButtonState)[src]
fn mouse_entered(&mut self, widget_id: i32)[src]
fn mouse_exited(&mut self, widget_id: i32)[src]
fn mouse_scrolled(&mut self, widget_id: i32, point: Point)[src]
fn mouse_moved(&mut self, widget_id: i32, point: Point)[src]
fn window_resized(&mut self, widget_id: i32, size: Size)[src]
fn window_focused(&mut self, widget_id: i32, focused: bool)[src]
fn button_down(&mut self, widget_id: i32, button: Button)[src]
fn button_up_inside(&mut self, widget_id: i32, button: Button)[src]
fn button_up_outside(&mut self, widget_id: i32, button: Button)[src]
fn on_key_pressed(&mut self, callback: KeyCallback)[src]
fn on_mouse_entered(&mut self, callback: SingleCallback)[src]
fn on_mouse_exited(&mut self, callback: SingleCallback)[src]
fn on_mouse_scrolled(&mut self, callback: PointCallback)[src]
fn on_mouse_moved(&mut self, callback: PointCallback)[src]
fn on_window_resized(&mut self, callback: SizeCallback)[src]
fn on_focused(&mut self, callback: BoolCallback)[src]
fn on_button_down(&mut self, callback: ButtonCallback)[src]
fn on_button_up_inside(&mut self, callback: ButtonCallback)[src]
fn on_button_up_outside(&mut self, callback: ButtonCallback)[src]
impl Widget for CanvasWidget[src]
Implementation of the CanvasWidget object with the Widget traits implemented.
This function only implements config and callbacks, which are used as a base for
all Widgets.
fn config(&mut self) -> &mut Configurable[src]
fn callbacks(&mut self) -> &mut CallbackStore[src]
fn invalidate(&mut self)[src]
fn clear_invalidate(&mut self)[src]
fn is_invalidated(&mut self) -> bool[src]
fn set_origin(&mut self, x: i32, y: i32)[src]
fn get_origin(&mut self) -> Point[src]
fn set_size(&mut self, w: i32, h: i32)[src]
fn get_size(&mut self) -> Size[src]
fn set_color(&mut self, color: Color)[src]
fn get_color(&mut self) -> Color[src]
fn perform_single_callback(&mut self, callback_id: u32, widget_id: i32)[src]
fn perform_bool_callback(
&mut self,
callback_id: u32,
widget_id: i32,
flag: bool
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
flag: bool
)
fn perform_point_callback(
&mut self,
callback_id: u32,
widget_id: i32,
point: Point
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
point: Point
)
fn perform_size_callback(
&mut self,
callback_id: u32,
widget_id: i32,
size: Size
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
size: Size
)
fn perform_button_callback(
&mut self,
callback_id: u32,
widget_id: i32,
button: Button
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
button: Button
)
fn perform_key_callback(
&mut self,
callback_id: u32,
widget_id: i32,
key: Key,
state: ButtonState
)[src]
&mut self,
callback_id: u32,
widget_id: i32,
key: Key,
state: ButtonState
)