[−][src]Trait pugl_ui::widget::Widget
The Widget
trait.
Widgets need to implement this trait. Most of the methods have default implementations, so that simple widgets can be easily defined. Eeven layouts are internally treated as widgets.
Data common to all widgets is kept in the struct
WidgetStub
accessible from the widget by
the methods stub()
and stub_mut()
.
Required methods
fn stub(&self) -> &WidgetStub
Supposed to return a reference to the WidgetStub
of the widget
usually implemented by the macro widget_stub!()
.
fn stub_mut(&mut self) -> &mut WidgetStub
Supposed to return a mutable reference to the WidgetStub
of the widget.
Usually implemented by the macro widget_stub!()
.
Provided methods
fn event(&mut self, ev: Event) -> Option<Event>
Called by the UI to pass an event to the widget.
The widget is supposed to process the Event and return None
if the widget has processed the event. If the widget has not
processed the event it shoud return Some(ev)
so that the
event can be passed to its parent widget.
There is EventState
and the macros
event_processed!()
and
event_not_processed!()
to do this.
The default implementation just passes the event without touching it.
fn exposed(&mut self, _expose: &ExposeArea, _cr: &Context)
Called when the widget has to draw itself.
Parameters
expose: &ExposeArea
– a pugl_sys::pugl::ExposeArea carrying the information which rectangle of the widget actually needs to be redrawn.
Default implementation does nothing.
fn min_size(&self) -> Size
Supposed to return the minimum size of the widget.
Default: zero size
fn width_expandable(&self) -> bool
Suposed to return true iff the widget is expandable in x-direction
Default: false
fn height_expandable(&self) -> bool
Suposed to return true iff the widget is expandable in y-direction
Default: false
fn takes_focus(&self) -> bool
Supposed to return true iff the widget can take the focus.
Default: false
fn pointer_enter(&mut self)
Called when the mouse pointer is entering the widget's layout.
Default implementation does nothing.
fn pointer_leave(&mut self)
Called when the mouse pointer is leaving the widget's layout.
Default implementation does nothing.
fn reminder_handler(&mut self) -> bool
Called when the requested reminding time is passed
Supposed to return true, iff the reminder is still needed
Default implementation does nothing and returns false.
fn ask_for_repaint(&mut self)
fn request_reminder(&mut self, timeout: f64)
The widget can request a reminder after timeout
seconds. When the time has passed `reminder_handler() is
called.
Usually not to be reimplemented.
fn reminder_request(&mut self) -> Option<f64>
Hands the reminder request over to the UI
Only to be called by the UI as it consumes the reminder request. Usually not to be reimplemented.
fn has_focus(&self) -> bool
Returns true iff the widget is currently focused.
Usually not to be reimplemented.
fn size(&self) -> Size
Returns the size of the widget after layouting.
Usually not to be reimplemented.
fn pos(&self) -> Coord
Returns the positon (upper left corner of the widget)
Usually not to be reimplemented.
fn geometry(&self) -> (f64, f64, f64, f64, f64, f64)
Returns the six scalar values to conveniently describe the widget's geometry (left, right, top, bottom, width, height)
Usually not to be reimplemented
Useful in implementations of ::exposed()
when used as
let (left, right, top, bottom, width, height) = self.geometry();
fn rect(&self) -> (f64, f64, f64, f64)
Returns four scalar values to conveniently describe the widget's rectangle (x, y, width, height)
Usually not to be reimplemented
Useful in implementations of ::exposed()
when used as
let (x, y, w, h) = self.rect();
fn sized_width(&self) -> bool
Returns true iff the widget has a defined minimum width
Usually not to be reimplemented.
fn sized_height(&self) -> bool
Returns true iff the widget has a defined minimum height
Usually not to be reimplemented.
fn set_width(&mut self, width: f64)
Sets the actual width of the widget to width
.
Usually called by the layouter. Usually not to be reimplemented.
fn set_height(&mut self, height: f64)
Sets the actual height of the widget to height
.
Usually called by the layouter. Usually not to be reimplemented.
fn expand_width(&mut self, ammount: f64)
Expands the width of the widget by ammount
.
Usually called by the layouter. Usually not to be reimplemented.
fn expand_height(&mut self, ammount: f64)
Expands the width of the widget by ammount
.
Usually called by the layouter. Usually not to be reimplemented.
fn set_pos(&mut self, pos: &Coord)
Sets the position of the widget to pos
.
Usually called by the layouter. Usually not to be reimplemented.
fn set_size(&mut self, size: &Size)
Sets the position of the widget to size
.
Usually called by the layouter. Usually not to be reimplemented.
fn layout(&self) -> Layout
Returns the Layout (drawing rect) of the widget.
Usually not to be reimplemented.
fn set_layout(&mut self, layout: &Layout)
sets the Layout of the widget to layout
Probably not needed as only used once in UI
fn is_sensitive(&self) -> bool
Returns true iff the widget is sensitive to user evnets.
Usually not to be reimplemented.
fn is_hovered(&self) -> bool
Returns true iff the widget is currently hovered.
Usually not to be reimplemented.
fn is_hit_by(&self, pos: Coord) -> bool
Returns true iff the widget's Layout is containing pos
.
Usually not to be reimplemented.
fn intersects_with(&self, pos: Coord, size: Size) -> bool
fn set_focus(&mut self, yn: bool)
Sets the widget's focus state to yn
.
Usually not to be reimplemented.
fn needs_repaint(&mut self) -> bool
Returns true iff the widget needs to be repainted.
Usually not to be reimplemented.
fn pointer_enter_wrap(&mut self)
Wrapper for the pointer_enter()
event function.
Usually only called by the UI. Usually not to be reimplemented.
fn pointer_leave_wrap(&mut self)
Wrapper for the pointer_leave()
event function.
Usually only called by the UI. Usually not to be reimplemented.
Implementations
impl dyn Widget
[src]
pub fn is<__T: Widget>(&self) -> bool
[src]
Returns true if the trait object wraps an object of type __T
.
pub fn downcast<__T: Widget>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>
[src]
Returns a boxed object from a boxed trait object if the underlying object is of type
__T
. Returns the original boxed trait if it isn't.
pub fn downcast_rc<__T: Widget>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>
[src]
Returns an Rc
-ed object from an Rc
-ed trait object if the underlying object is of
type __T
. Returns the original Rc
-ed trait if it isn't.
pub fn downcast_ref<__T: Widget>(&self) -> Option<&__T>
[src]
Returns a reference to the object within the trait object if it is of type __T
, or
None
if it isn't.
pub fn downcast_mut<__T: Widget>(&mut self) -> Option<&mut __T>
[src]
Returns a mutable reference to the object within the trait object if it is of type
__T
, or None
if it isn't.
pub fn downcast_arc<__T: Widget>(self: Arc<Self>) -> Result<Arc<__T>, Arc<Self>> where
__T: Any + Send + Sync,
[src]
__T: Any + Send + Sync,
Returns an Arc
-ed object from an Arc
-ed trait object if the underlying object is of
type __T
. Returns the original Arc
-ed trait if it isn't.