Trait widgetry::widgets::WidgetImpl
source · pub trait WidgetImpl: Downcast {
// Required methods
fn get_dims(&self) -> ScreenDims;
fn set_pos(&mut self, top_left: ScreenPt);
fn event(&mut self, ctx: &mut EventCtx<'_>, output: &mut WidgetOutput);
fn draw(&self, g: &mut GfxCtx<'_>);
// Provided methods
fn can_restore(&self) -> bool { ... }
fn restore(&mut self, _: &mut EventCtx<'_>, _prev: &dyn WidgetImpl) { ... }
}
Expand description
Create a new widget by implementing this trait. You can instantiate your widget by calling
Widget::new(Box::new(instance of your new widget))
, which gives you the usual style options.
Required Methods§
sourcefn get_dims(&self) -> ScreenDims
fn get_dims(&self) -> ScreenDims
What width and height does the widget occupy? If this changes, be sure to set
redo_layout
to true in event
.
sourcefn set_pos(&mut self, top_left: ScreenPt)
fn set_pos(&mut self, top_left: ScreenPt)
Your widget’s top left corner should be here. Handle mouse events and draw appropriately.
sourcefn event(&mut self, ctx: &mut EventCtx<'_>, output: &mut WidgetOutput)
fn event(&mut self, ctx: &mut EventCtx<'_>, output: &mut WidgetOutput)
Your chance to react to an event. Any side effects outside of this widget are communicated through the output.
Provided Methods§
sourcefn can_restore(&self) -> bool
fn can_restore(&self) -> bool
If a new Panel is being created to replace an older one, all widgets have the chance to preserve state from the previous version.
sourcefn restore(&mut self, _: &mut EventCtx<'_>, _prev: &dyn WidgetImpl)
fn restore(&mut self, _: &mut EventCtx<'_>, _prev: &dyn WidgetImpl)
Restore state from the previous version of this widget, with the same ID. Implementors must downcast.
Implementations§
source§impl dyn WidgetImpl
impl dyn WidgetImpl
sourcepub fn is<__T: WidgetImpl>(&self) -> bool
pub fn is<__T: WidgetImpl>(&self) -> bool
Returns true if the trait object wraps an object of type __T
.
sourcepub fn downcast<__T: WidgetImpl>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>
pub fn downcast<__T: WidgetImpl>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>
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.
sourcepub fn downcast_rc<__T: WidgetImpl>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>
pub fn downcast_rc<__T: WidgetImpl>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>
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.
sourcepub fn downcast_ref<__T: WidgetImpl>(&self) -> Option<&__T>
pub fn downcast_ref<__T: WidgetImpl>(&self) -> Option<&__T>
Returns a reference to the object within the trait object if it is of type __T
, or
None
if it isn’t.
sourcepub fn downcast_mut<__T: WidgetImpl>(&mut self) -> Option<&mut __T>
pub fn downcast_mut<__T: WidgetImpl>(&mut self) -> Option<&mut __T>
Returns a mutable reference to the object within the trait object if it is of type
__T
, or None
if it isn’t.