pub struct WidgetCore { /* private fields */ }Expand description
The state that every Widget shares.
Store one WidgetCore in each Widget structure and return it from Widget::core and
Widget::core_mut; every getter and setter on the Widget trait works against it. It holds
the Widget’s ID and parent ID (assigned by the WidgetCache), its origin relative to its
parent, its size, its background color, its Behavior flags (including hidden) and VisualState flags, its Appearance (a style per state), its EventMask, whether it needs repainting, and
the texture its backend paints it into.
§Examples
use pushrod::geometry::{point, size};
use pushrod::widget::WidgetCore;
let core = WidgetCore::new(point(10, 20), size(100, 30));Implementations§
Source§impl WidgetCore
impl WidgetCore
Sourcepub fn set_event_mask(&mut self, mask: EventMask)
pub fn set_event_mask(&mut self, mask: EventMask)
Sets the event mask the Widget reports from Widget::event_mask.
Use it while building a Widget. To change a mask after the Widget is in a window, use
WidgetCache::set_event_mask, which also emits
the change.
§Arguments
mask- The classes of events theWidgetwants.
Sourcepub fn add_controller(&mut self, controller: impl Controller + 'static)
pub fn add_controller(&mut self, controller: impl Controller + 'static)
Adds an input controller, and adds the event classes it needs to the event mask.
The default Widget::handle_event feeds every event to the controllers. Call
WidgetCore::set_event_mask before this, not after, or the added classes are replaced.
§Arguments
controller- The controller, such asClickController.
Sourcepub fn new(origin: Point, size: Size) -> Self
pub fn new(origin: Point, size: Size) -> Self
Creates the shared state for a new Widget.
The Widget starts visible, invalidated (so it is painted on the first frame), with a
transparent white background color. Its ID and parent are assigned later, when it is added to
a WidgetCache.
§Arguments
origin- The upper left-hand corner of theWidget, relative to its parent.size- The width and height of theWidgetin pixels.
§Returns
A new WidgetCore, to be stored in a Widget structure.