Skip to main content

Module widget

Module widget 

Source
Expand description

§Widget

A UI element that exists in a window, whether visible or otherwise, that consumes and alternatively generates events.

Every Widget owns a WidgetCore, which stores the state that all Widgets share: the ID, parent ID, origin, size, color, visibility, and invalidation flag. The Widget trait provides default implementations for all of the getters and setters against the WidgetCore, so a new Widget only needs to implement three functions:

use pushrod::paint::{self, Painter};
use pushrod::widget::{Widget, WidgetCore};

pub struct MyWidget {
    core: WidgetCore,
}

impl Widget for MyWidget {
    fn core(&self) -> &WidgetCore { &self.core }
    fn core_mut(&mut self) -> &mut WidgetCore { &mut self.core }

    fn paint(&self, p: &mut dyn Painter) {
        paint::fill(p, self.get_color());
    }
}

If the compiler is happy, the Widget is complete: there are no lists of Widget types to update elsewhere in the library.

Structs§

Behavior
What a Widget can do, stored on its WidgetCore.
VisualState
How a Widget currently looks, stored on its WidgetCore.
WidgetCore
The state that every Widget shares.

Constants§

ROOT_WIDGET_ID
The ID of the window’s root Widget.

Traits§

Widget
A drawable, interactive object presented in a window.

Type Aliases§

WidgetId
The ID of a Widget.