<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><metaname="generator"content="rustdoc"><metaname="description"content="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."><metaname="keywords"content="rust, rustlang, rust-lang, WidgetImpl"><title>widgetry::WidgetImpl - Rust</title><linkrel="stylesheet"type="text/css"href="../normalize.css"><linkrel="stylesheet"type="text/css"href="../rustdoc.css"id="mainThemeStyle"><linkrel="stylesheet"type="text/css"href="../light.css"id="themeStyle"><linkrel="stylesheet"type="text/css"href="../dark.css"disabled><linkrel="stylesheet"type="text/css"href="../ayu.css"disabled><scriptid="default-settings"></script><scriptsrc="../storage.js"></script><scriptsrc="../crates.js"></script><noscript><linkrel="stylesheet"href="../noscript.css"></noscript><linkrel="icon"type="image/svg+xml"href="../favicon.svg">
<linkrel="alternate icon"type="image/png"href="../favicon-32x32.png"><styletype="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><bodyclass="rustdoc trait"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="sidebar"><divclass="sidebar-menu"role="button">☰</div><ahref='../widgetry/index.html'><divclass='logo-container rust-logo'><imgsrc='../rust-logo.png'alt='logo'></div></a><pclass="location">Trait WidgetImpl</p><divclass="sidebar-elems"><divclass="block items"><aclass="sidebar-title"href="#required-methods">Required Methods</a><divclass="sidebar-links"><ahref="#tymethod.event">event</a><ahref="#tymethod.draw">draw</a><ahref="#tymethod.get_dims">get_dims</a><ahref="#tymethod.set_pos">set_pos</a></div><aclass="sidebar-title"href="#provided-methods">Provided Methods</a><divclass="sidebar-links"><ahref="#method.can_restore">can_restore</a><ahref="#method.restore">restore</a></div><aclass="sidebar-title"href="#implementations">Methods</a><divclass="sidebar-links"><ahref="#method.downcast">downcast</a><ahref="#method.downcast_mut">downcast_mut</a><ahref="#method.downcast_rc">downcast_rc</a><ahref="#method.downcast_ref">downcast_ref</a><ahref="#method.is">is</a></div><aclass="sidebar-title"href="#implementors">Implementors</a></div><pclass="location"><ahref="index.html">widgetry</a></p><divid="sidebar-vars"data-name="WidgetImpl"data-ty="trait"data-relpath=""></div><scriptdefersrc="sidebar-items.js"></script></div></nav><divclass="theme-picker"><buttonid="theme-picker"aria-label="Pick another theme!"aria-haspopup="menu"><imgsrc="../brush.svg"width="18"height="18"alt="Pick another theme!"></button><divid="theme-choices"role="menu"></div></div><scriptsrc="../theme.js"></script><navclass="sub"><formclass="search-form"><divclass="search-container"><div><selectid="crate-search"><optionvalue="All crates">All crates</option></select><inputclass="search-input"name="search"disabledautocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"></div><buttontype="button"class="help-button">?</button>
</div><h2id="required-methods"class="small-section-header">Required methods<ahref="#required-methods"class="anchor"></a></h2><divclass="methods"><h3id="tymethod.get_dims"class="method"><code>fn <ahref="#tymethod.get_dims"class="fnname">get_dims</a>(&self) -><aclass="struct"href="../widgetry/screen_geom/struct.ScreenDims.html"title="struct widgetry::screen_geom::ScreenDims">ScreenDims</a></code><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#49"title="goto source code">[src]</a></h3><divclass="docblock"><p>What width and height does the widget occupy? If this changes, be sure to set
</div><h3id="tymethod.set_pos"class="method"><code>fn <ahref="#tymethod.set_pos"class="fnname">set_pos</a>(&mut self, top_left: <aclass="struct"href="../widgetry/screen_geom/struct.ScreenPt.html"title="struct widgetry::screen_geom::ScreenPt">ScreenPt</a>)</code><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#51"title="goto source code">[src]</a></h3><divclass="docblock"><p>Your widget’s top left corner should be here. Handle mouse events and draw appropriately.</p>
</div><h3id="tymethod.event"class="method"><code>fn <ahref="#tymethod.event"class="fnname">event</a>(&mut self, ctx: &mut <aclass="struct"href="../widgetry/event_ctx/struct.EventCtx.html"title="struct widgetry::event_ctx::EventCtx">EventCtx</a><'_>, output: &mut <aclass="struct"href="../widgetry/widgets/struct.WidgetOutput.html"title="struct widgetry::widgets::WidgetOutput">WidgetOutput</a>)</code><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#54"title="goto source code">[src]</a></h3><divclass="docblock"><p>Your chance to react to an event. Any side effects outside of this widget are communicated
</div><h3id="tymethod.draw"class="method"><code>fn <ahref="#tymethod.draw"class="fnname">draw</a>(&self, g: &mut <aclass="struct"href="../widgetry/drawing/struct.GfxCtx.html"title="struct widgetry::drawing::GfxCtx">GfxCtx</a><'_>)</code><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#56"title="goto source code">[src]</a></h3><divclass="docblock"><p>Draw the widget. Be sure to draw relative to the top-left specified by <code>set_pos</code>.</p>
</div></div><spanclass="loading-content">Loading content...</span><h2id="provided-methods"class="small-section-header">Provided methods<ahref="#provided-methods"class="anchor"></a></h2><divclass="methods"><h3id="method.can_restore"class="method"><code>fn <ahref="#method.can_restore"class="fnname">can_restore</a>(&self) -><aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#59-61"title="goto source code">[src]</a></h3><divclass="docblock"><p>If a new Panel is being created to replace an older one, all widgets have the chance to
</div><h3id="method.restore"class="method"><code>fn <ahref="#method.restore"class="fnname">restore</a>(&mut self, _: &mut <aclass="struct"href="../widgetry/event_ctx/struct.EventCtx.html"title="struct widgetry::event_ctx::EventCtx">EventCtx</a><'_>, _prev: &dyn <aclass="trait"href="../widgetry/widgets/trait.WidgetImpl.html"title="trait widgetry::widgets::WidgetImpl">WidgetImpl</a>)</code><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#64-66"title="goto source code">[src]</a></h3><divclass="docblock"><p>Restore state from the previous version of this widget, with the same ID. Implementors must
</div></div><spanclass="loading-content">Loading content...</span><h2id="implementations"class="small-section-header">Implementations<ahref="#implementations"class="anchor"></a></h2><h3id="impl"class="impl"><codeclass="in-band">impl dyn <aclass="trait"href="../widgetry/widgets/trait.WidgetImpl.html"title="trait widgetry::widgets::WidgetImpl">WidgetImpl</a></code><ahref="#impl"class="anchor"></a><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#98"title="goto source code">[src]</a></h3><divclass="impl-items"><h4id="method.is"class="method"><code>pub fn <ahref="#method.is"class="fnname">is</a><__T: <aclass="trait"href="../widgetry/widgets/trait.WidgetImpl.html"title="trait widgetry::widgets::WidgetImpl">WidgetImpl</a>>(&self) -><aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#98"title="goto source code">[src]</a></h4><divclass="docblock"><p>Returns true if the trait object wraps an object of type <code>__T</code>.</p>
</div><h4id="method.downcast"class="method"><code>pub fn <ahref="#method.downcast"class="fnname">downcast</a><__T: <aclass="trait"href="../widgetry/widgets/trait.WidgetImpl.html"title="trait widgetry::widgets::WidgetImpl">WidgetImpl</a>>(self: <aclass="struct"href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html"title="struct alloc::boxed::Box">Box</a><Self>) -><aclass="enum"href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html"title="enum core::result::Result">Result</a><<aclass="struct"href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html"title="struct alloc::boxed::Box">Box</a><__T>, <aclass="struct"href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html"title="struct alloc::boxed::Box">Box</a><Self>></code><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#98"title="goto source code">[src]</a></h4><divclass="docblock"><p>Returns a boxed object from a boxed trait object if the underlying object is of type
</div><h4id="method.downcast_rc"class="method"><code>pub fn <ahref="#method.downcast_rc"class="fnname">downcast_rc</a><__T: <aclass="trait"href="../widgetry/widgets/trait.WidgetImpl.html"title="trait widgetry::widgets::WidgetImpl">WidgetImpl</a>>(self: <aclass="struct"href="https://doc.rust-lang.org/nightly/alloc/rc/struct.Rc.html"title="struct alloc::rc::Rc">Rc</a><Self>) -><aclass="enum"href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html"title="enum core::result::Result">Result</a><<aclass="struct"href="https://doc.rust-lang.org/nightly/alloc/rc/struct.Rc.html"title="struct alloc::rc::Rc">Rc</a><__T>, <aclass="struct"href="https://doc.rust-lang.org/nightly/alloc/rc/struct.Rc.html"title="struct alloc::rc::Rc">Rc</a><Self>></code><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#98"title="goto source code">[src]</a></h4><divclass="docblock"><p>Returns an <code>Rc</code>-ed object from an <code>Rc</code>-ed trait object if the underlying object is of
</div><h4id="method.downcast_ref"class="method"><code>pub fn <ahref="#method.downcast_ref"class="fnname">downcast_ref</a><__T: <aclass="trait"href="../widgetry/widgets/trait.WidgetImpl.html"title="trait widgetry::widgets::WidgetImpl">WidgetImpl</a>>(&self) -><aclass="enum"href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html"title="enum core::option::Option">Option</a><<aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>__T></code><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#98"title="goto source code">[src]</a></h4><divclass="docblock"><p>Returns a reference to the object within the trait object if it is of type <code>__T</code>, or
</div><h4id="method.downcast_mut"class="method"><code>pub fn <ahref="#method.downcast_mut"class="fnname">downcast_mut</a><__T: <aclass="trait"href="../widgetry/widgets/trait.WidgetImpl.html"title="trait widgetry::widgets::WidgetImpl">WidgetImpl</a>>(&mut self) -><aclass="enum"href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html"title="enum core::option::Option">Option</a><<aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>__T></code><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#98"title="goto source code">[src]</a></h4><divclass="docblock"><p>Returns a mutable reference to the object within the trait object if it is of type