[−][src]Trait pushrod_widgets::widget::Widget
This is the Widget trait that all implemented Widgets need to extend in order to function
with the Pushrod library. All functions in this trait (aside from default implementations)
should be implemented by the Widget.
Required methods
fn properties(&mut self) -> &mut WidgetProperties
This provides access to the WidgetProperties set for a Widget. These must be defined
in the structure of the Widget, as they allow for direct manipulation of the properties.
Provided methods
fn draw(
&mut self,
_c: &mut Canvas<Window>,
_t: &mut TextureCache
) -> Option<&Texture>
&mut self,
_c: &mut Canvas<Window>,
_t: &mut TextureCache
) -> Option<&Texture>
Draws the widget. If you wish to modify the canvas object, you must declare it as 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.
So, why not just call draw each time, if the Engine already handles the calling of the
draw for you when an object needs invalidation? This is to avoid excess CPU usage. You
can call the draw method each time: all it will do is return the reference to the already
drawn Texture if you do this. It's only at the time the contents needs to be redrawn will
the logic for the draw take place (so long the invalidated state is obeyed)
fn handle_event(&mut self, _e: PushrodEvent) -> Option<PushrodEvent>
Handles a PushrodEvent sent to the Widget that would also be sent to the application.
If any PushrodEvents trigger a custom Widget-based event, this function can intercept
the incoming event, and issue one of its own. If the function returns no events, a
None can be returned, otherwise a Some(PushrodEvent) should be returned. If this
function returns an event, that event will be sent on to the application as soon as it has
been generated.
fn invalidate(&mut self)
Set the invalidation key for this Widget, indicating that the TextureCache needs to
be redrawn.
fn invalidated(&mut self) -> bool
Flag indicating whether or not the draw method needs to be called for this Widget so
that its TextureCache is refreshed.
Implementors
impl Widget for BaseWidget[src]
Implementation for drawing a BaseWidget, with the Widget trait objects applied.
fn properties(&mut self) -> &mut WidgetProperties[src]
fn draw(
&mut self,
c: &mut Canvas<Window>,
_t: &mut TextureCache
) -> Option<&Texture>[src]
&mut self,
c: &mut Canvas<Window>,
_t: &mut TextureCache
) -> Option<&Texture>
This is a BaseWidget that is used as a standard blank Widget.
- PROPERTY_MAIN_COLOR: the
Colorof the body of theWidget - PROPERTY_BORDER_WIDTH: the width of the border to draw
- PROPERTY_BORDER_COLOR: the
Colorof the border.
impl Widget for ButtonWidget[src]
Implementation for drawing a BaseWidget, with the Widget trait objects applied.
fn properties(&mut self) -> &mut WidgetProperties[src]
fn draw(
&mut self,
c: &mut Canvas<Window>,
t: &mut TextureCache
) -> Option<&Texture>[src]
&mut self,
c: &mut Canvas<Window>,
t: &mut TextureCache
) -> Option<&Texture>
This is a ButtonWidget that is used as a standard blank Widget.
- PROPERTY_MAIN_COLOR: the
Colorof the body of theWidget - PROPERTY_BORDER_WIDTH: the width of the border to draw
- PROPERTY_BORDER_COLOR: the
Colorof the border - PROPERTY_FONT_COLOR: the color of the font
- PROPERTY_FONT_NAME: full or relative path to the font file to use to render the text
- PROPERTY_FONT_SIZE: the size in points of the font
- PROPERTY_FONT_STYLE: the
FontStyleto apply to the font - PROPERTY_TEXT_JUSTIFICATION: The
TEXT_JUSTIFY_*constant to use to position the text inside theWidget - PROPERTY_TEXT:
Stringcontaining the text to display
While the button is selected, the color of the background will be Color::BLACK, and the
text will turn Color::WHITE. If the button is not selected, it will revert back to the
colors that you set for the text color and background colors of the button.
fn handle_event(&mut self, event: PushrodEvent) -> Option<PushrodEvent>[src]
Overrides the handle_event function, which handles the mouse button, widget entering and
exiting events.
impl Widget for CheckBoxWidget[src]
Implementation for drawing a CheckBoxWidget, with the Widget trait objects applied.
fn properties(&mut self) -> &mut WidgetProperties[src]
fn draw(
&mut self,
c: &mut Canvas<Window>,
t: &mut TextureCache
) -> Option<&Texture>[src]
&mut self,
c: &mut Canvas<Window>,
t: &mut TextureCache
) -> Option<&Texture>
This is a ButtonWidget that is used as a standard blank Widget.
- PROPERTY_MAIN_COLOR: the
Colorof the body of theWidget - PROPERTY_BORDER_WIDTH: the width of the border to draw
- PROPERTY_BORDER_COLOR: the
Colorof the border - PROPERTY_FONT_COLOR: the color of the font
- PROPERTY_FONT_NAME: full or relative path to the font file to use to render the text
- PROPERTY_FONT_SIZE: the size in points of the font
- PROPERTY_FONT_STYLE: the
FontStyleto apply to the font - PROPERTY_TEXT_JUSTIFICATION: The
TEXT_JUSTIFY_*constant to use to position the text inside theWidget(only left or right are allowed) - PROPERTY_TEXT:
Stringcontaining the text to display - PROPERTY_TOGGLED: boolean indicating whether or not the button is in a selected state
fn handle_event(&mut self, event: PushrodEvent) -> Option<PushrodEvent>[src]
Overrides the handle_event function, which handles the mouse button, widget entering and
exiting events.
impl Widget for GridWidget[src]
Implementation for drawing a BaseWidget, with the Widget trait objects applied.
fn properties(&mut self) -> &mut WidgetProperties[src]
fn draw(
&mut self,
c: &mut Canvas<Window>,
_t: &mut TextureCache
) -> Option<&Texture>[src]
&mut self,
c: &mut Canvas<Window>,
_t: &mut TextureCache
) -> Option<&Texture>
This is a GridWidget that is used as a standard blank Widget.
- PROPERTY_MAIN_COLOR: the
Colorof the body of theWidget - PROPERTY_BORDER_WIDTH: the width of the border to draw
- PROPERTY_BORDER_COLOR: the
Colorof the border - PROPERTY_GRID_COLOR: the
Colorof the grid if set, otherwise,Color::GRAYis used - PROPERTY_GRID_SPACING: the number of pixels between each grid point/line
- PROPERTY_GRID_CONNECTED: boolean indicating whether or not the grid contains lines (true) or points (false)
impl Widget for GroupBoxWidget[src]
Implementation for drawing a GroupBoxWidget, with the Widget trait objects applied.
fn properties(&mut self) -> &mut WidgetProperties[src]
fn draw(
&mut self,
c: &mut Canvas<Window>,
t: &mut TextureCache
) -> Option<&Texture>[src]
&mut self,
c: &mut Canvas<Window>,
t: &mut TextureCache
) -> Option<&Texture>
This is a BaseWidget that is used as a standard blank Widget.
- PROPERTY_MAIN_COLOR: the
Colorof the body of theWidget - PROPERTY_BORDER_WIDTH: the width of the border to draw
- PROPERTY_BORDER_COLOR: the
Colorof the border. - PROPERTY_FONT_COLOR: the color of the font
- PROPERTY_FONT_NAME: full or relative path to the font file to use to render the text
- PROPERTY_FONT_SIZE: the size in points of the font
- PROPERTY_FONT_STYLE: the
FontStyleto apply to the font - PROPERTY_GROUP_BACKGROUND_COLOR: the background color of the group bounding box
impl Widget for ImageButtonWidget[src]
Implementation for drawing a ImageButtonWidget, with the Widget trait objects applied.
fn properties(&mut self) -> &mut WidgetProperties[src]
fn draw(
&mut self,
c: &mut Canvas<Window>,
t: &mut TextureCache
) -> Option<&Texture>[src]
&mut self,
c: &mut Canvas<Window>,
t: &mut TextureCache
) -> Option<&Texture>
This is an ImageButtonWidget that is used as a standard blank Widget.
- PROPERTY_MAIN_COLOR: the
Colorof the body of theWidget - PROPERTY_BORDER_WIDTH: the width of the border to draw
- PROPERTY_BORDER_COLOR: the
Colorof the border - PROPERTY_FONT_COLOR: the color of the font
- PROPERTY_FONT_NAME: full or relative path to the font file to use to render the text
- PROPERTY_FONT_SIZE: the size in points of the font
- PROPERTY_FONT_STYLE: the
FontStyleto apply to the font - PROPERTY_TEXT_JUSTIFICATION: The
TEXT_JUSTIFY_*constant to use to position the text inside theWidget - PROPERTY_TEXT:
Stringcontaining the text to display - PROPERTY_IMAGE_FILENAME: the image to show in the button (should be an image equal in width and height dimensions)
- PROPERTY_IMAGE_POSITION: the position of the image inside the button - left or right side
While the button is selected, the color of the background will be Color::BLACK, and the
text will turn Color::WHITE. If the button is not selected, it will revert back to the
colors that you set for the text color and background colors of the button.
fn handle_event(&mut self, event: PushrodEvent) -> Option<PushrodEvent>[src]
Overrides the handle_event function, which handles the mouse button, widget entering and
exiting events.
impl Widget for ImageWidget[src]
Creates a new ImageWidget, which draws an image in a supported image format for SDL2 at a specific
location on the screen. Requires the name of the image (the full path to the file), the position
within the widget (defined as ImagePosition), the xywh bounds, and whether or not the image is
scaled within the bounds of the Widget.
fn properties(&mut self) -> &mut WidgetProperties[src]
fn draw(
&mut self,
c: &mut Canvas<Window>,
t: &mut TextureCache
) -> Option<&Texture>[src]
&mut self,
c: &mut Canvas<Window>,
t: &mut TextureCache
) -> Option<&Texture>
This is the drawing implementation of the ImageWidget. The following are the properties that can
be applied:
- PROPERTY_MAIN_COLOR: the
Colorof the body of theWidget - PROPERTY_BORDER_WIDTH: the width of the border to draw
- PROPERTY_BORDER_COLOR: the
Colorof the border. - PROPERTY_IMAGE_POSITION: position of the image within the
ImageWidget - PROPERTY_IMAGE_FILENAME: the filename of the image to display
- PROPERTY_IMAGE_SCALED: boolean flag indicating whether or not to scale the image to the bounds of the
ImageWidget
impl Widget for ProgressWidget[src]
Implementation for drawing a ProgressWidget, with the Widget trait objects applied.
fn properties(&mut self) -> &mut WidgetProperties[src]
fn draw(
&mut self,
c: &mut Canvas<Window>,
_t: &mut TextureCache
) -> Option<&Texture>[src]
&mut self,
c: &mut Canvas<Window>,
_t: &mut TextureCache
) -> Option<&Texture>
Draws the ProgressWidget using the following properties:
- PROPERTY_MAIN_COLOR: the
Colorof the body of theWidget - PROPERTY_BORDER_WIDTH: the width of the border to draw
- PROPERTY_BORDER_COLOR: the
Colorof the border. - PROPERTY_PROGRESS_COLOR: the
Colorof the progress bar - PROPERTY_PROGRESS: the progress value (from 0 to 100)
impl Widget for TextWidget[src]
Implementation for drawing a TextWidget, with the Widget trait objects applied.
fn properties(&mut self) -> &mut WidgetProperties[src]
fn draw(
&mut self,
c: &mut Canvas<Window>,
t: &mut TextureCache
) -> Option<&Texture>[src]
&mut self,
c: &mut Canvas<Window>,
t: &mut TextureCache
) -> Option<&Texture>
This is the draw implementation of the TextWidget. It uses the following properties:
- PROPERTY_MAIN_COLOR: the
Colorof the body of theWidget - PROPERTY_BORDER_WIDTH: the width of the border to draw
- PROPERTY_BORDER_COLOR: the
Colorof the border. - PROPERTY_FONT_COLOR: the color of the font
- PROPERTY_FONT_NAME: full or relative path to the font file to use to render the text
- PROPERTY_FONT_SIZE: the size in points of the font
- PROPERTY_FONT_STYLE: the
FontStyleto apply to the font - PROPERTY_TEXT_JUSTIFICATION: The
TEXT_JUSTIFY_*constant to use to position the text inside theWidget - PROPERTY_TEXT:
Stringcontaining the text to display
impl Widget for ToggleButtonWidget[src]
Implementation for drawing a BaseWidget, with the Widget trait objects applied.
fn properties(&mut self) -> &mut WidgetProperties[src]
fn draw(
&mut self,
c: &mut Canvas<Window>,
t: &mut TextureCache
) -> Option<&Texture>[src]
&mut self,
c: &mut Canvas<Window>,
t: &mut TextureCache
) -> Option<&Texture>
This is a ButtonWidget that is used as a standard blank Widget.
- PROPERTY_MAIN_COLOR: the
Colorof the body of theWidget - PROPERTY_BORDER_WIDTH: the width of the border to draw
- PROPERTY_BORDER_COLOR: the
Colorof the border - PROPERTY_FONT_COLOR: the color of the font
- PROPERTY_FONT_NAME: full or relative path to the font file to use to render the text
- PROPERTY_FONT_SIZE: the size in points of the font
- PROPERTY_FONT_STYLE: the
FontStyleto apply to the font - PROPERTY_TEXT_JUSTIFICATION: The
TEXT_JUSTIFY_*constant to use to position the text inside theWidget - PROPERTY_TEXT:
Stringcontaining the text to display - PROPERTY_TOGGLED: boolean indicating whether or not the button is in a selected state
While the button is selected, the color of the background will be Color::BLACK, and the
text will turn Color::WHITE. If the button is not selected, it will revert back to the
colors that you set for the text color and background colors of the button.
fn handle_event(&mut self, event: PushrodEvent) -> Option<PushrodEvent>[src]
Overrides the handle_event function, which handles the mouse button, widget entering and
exiting events.