<!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>WidgetImpl in widgetry - Rust</title><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../SourceSerif4-Regular.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../FiraSans-Regular.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../FiraSans-Medium.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../SourceCodePro-Regular.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../SourceSerif4-Bold.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../SourceCodePro-Semibold.ttf.woff2"><linkrel="stylesheet"type="text/css"href="../normalize.css"><linkrel="stylesheet"type="text/css"href="../rustdoc.css"id="mainThemeStyle"><linkrel="stylesheet"type="text/css"href="../ayu.css"disabled><linkrel="stylesheet"type="text/css"href="../dark.css"disabled><linkrel="stylesheet"type="text/css"href="../light.css"id="themeStyle"><scriptid="default-settings"></script><scriptsrc="../storage.js"></script><scriptsrc="../crates.js"></script><scriptdefersrc="../main.js"></script>
<noscript><linkrel="stylesheet"href="../noscript.css"></noscript><linkrel="alternate icon"type="image/png"href="../favicon-16x16.png"><linkrel="alternate icon"type="image/png"href="../favicon-32x32.png"><linkrel="icon"type="image/svg+xml"href="../favicon.svg"></head><bodyclass="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="mobile-topbar"><buttonclass="sidebar-menu-toggle">☰</button><aclass="sidebar-logo"href="../widgetry/index.html"><divclass="logo-container"><imgclass="rust-logo"src="../rust-logo.svg"alt="logo"></div>
</a><h2class="location"><ahref="#">WidgetImpl</a></h2><divclass="sidebar-elems"><section><divclass="block"><h3class="sidebar-title"><ahref="#required-methods">Required Methods</a></h3><ul><li><ahref="#tymethod.draw">draw</a></li><li><ahref="#tymethod.event">event</a></li><li><ahref="#tymethod.get_dims">get_dims</a></li><li><ahref="#tymethod.set_pos">set_pos</a></li></ul></div><divclass="block"><h3class="sidebar-title"><ahref="#provided-methods">Provided Methods</a></h3><ul><li><ahref="#method.can_restore">can_restore</a></li><li><ahref="#method.restore">restore</a></li></ul></div><divclass="block"><h3class="sidebar-title"><ahref="#implementations">Methods</a></h3><ul><li><ahref="#method.downcast">downcast</a></li><li><ahref="#method.downcast_mut">downcast_mut</a></li><li><ahref="#method.downcast_rc">downcast_rc</a></li><li><ahref="#method.downcast_ref">downcast_ref</a></li><li><ahref="#method.is">is</a></li></ul></div><divclass="block"><h3class="sidebar-title"><ahref="#implementors">Implementors</a></h3></div></section><h2class="location"><ahref="index.html">In widgetry</a></h2><divid="sidebar-vars"data-name="WidgetImpl"data-ty="trait"data-relpath=""></div><scriptdefersrc="sidebar-items.js"></script></div></nav><main><divclass="width-limiter"><divclass="sub-container"><aclass="sub-logo-container"href="../widgetry/index.html"><imgclass="rust-logo"src="../rust-logo.svg"alt="logo"></a><navclass="sub"><divclass="theme-picker hidden"><buttonid="theme-picker"aria-label="Pick another theme!"aria-haspopup="menu"title="themes"><imgwidth="22"height="22"alt="Pick another theme!"src="../brush.svg"></button><divid="theme-choices"role="menu"></div></div><formclass="search-form"><divclass="search-container"><span></span><inputclass="search-input"name="search"autocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"><buttontype="button"id="help-button"title="help">?</button><aid="settings-menu"href="../settings.html"title="settings"><imgwidth="22"height="22"alt="Change settings"src="../wheel.svg"></a></div></form></nav></div><sectionid="main-content"class="content"><divclass="main-heading">
<h1class="fqn"><spanclass="in-band">Trait <ahref="index.html">widgetry</a>::<wbr><aclass="trait"href="#">WidgetImpl</a><buttonid="copy-path"onclick="copy_path(this)"title="Copy item path to clipboard"><imgsrc="../clipboard.svg"width="19"height="18"alt="Copy item path"></button></span></h1><spanclass="out-of-band"><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#48-69">source</a> · <aid="toggle-all-docs"href="javascript:void(0)"title="collapse all docs">[<spanclass="inner">−</span>]</a></span></div><divclass="docblock item-decl"><preclass="rust trait"><code>pub trait WidgetImpl: Downcast {
}</code></pre></div><detailsclass="rustdoc-toggle top-doc"open><summaryclass="hideme"><span>Expand description</span></summary><divclass="docblock"><p>Create a new widget by implementing this trait. You can instantiate your widget by calling
</div></details><h2id="required-methods"class="small-section-header">Required methods<ahref="#required-methods"class="anchor"></a></h2><divclass="methods"><detailsclass="rustdoc-toggle"open><summary><divid="tymethod.get_dims"class="method has-srclink"><divclass="rightside"><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#51">source</a></div><h4class="code-header">fn <ahref="#tymethod.get_dims"class="fnname">get_dims</a>(&self) -><aclass="struct"href="screen_geom/struct.ScreenDims.html"title="struct widgetry::screen_geom::ScreenDims">ScreenDims</a></h4></div></summary><divclass="docblock"><p>What width and height does the widget occupy? If this changes, be sure to set
</div></details><detailsclass="rustdoc-toggle"open><summary><divid="tymethod.set_pos"class="method has-srclink"><divclass="rightside"><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#53">source</a></div><h4class="code-header">fn <ahref="#tymethod.set_pos"class="fnname">set_pos</a>(&mut self, top_left: <aclass="struct"href="screen_geom/struct.ScreenPt.html"title="struct widgetry::screen_geom::ScreenPt">ScreenPt</a>)</h4></div></summary><divclass="docblock"><p>Your widget’s top left corner should be here. Handle mouse events and draw appropriately.</p>
</div></details><detailsclass="rustdoc-toggle"open><summary><divid="tymethod.event"class="method has-srclink"><divclass="rightside"><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#56">source</a></div><h4class="code-header">fn <ahref="#tymethod.event"class="fnname">event</a>(&mut self, ctx: &mut <aclass="struct"href="event_ctx/struct.EventCtx.html"title="struct widgetry::event_ctx::EventCtx">EventCtx</a><'_>, output: &mut <aclass="struct"href="widgets/struct.WidgetOutput.html"title="struct widgetry::widgets::WidgetOutput">WidgetOutput</a>)</h4></div></summary><divclass="docblock"><p>Your chance to react to an event. Any side effects outside of this widget are communicated
</div></details><detailsclass="rustdoc-toggle"open><summary><divid="tymethod.draw"class="method has-srclink"><divclass="rightside"><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#58">source</a></div><h4class="code-header">fn <ahref="#tymethod.draw"class="fnname">draw</a>(&self, g: &mut <aclass="struct"href="drawing/struct.GfxCtx.html"title="struct widgetry::drawing::GfxCtx">GfxCtx</a><'_>)</h4></div></summary><divclass="docblock"><p>Draw the widget. Be sure to draw relative to the top-left specified by <code>set_pos</code>.</p>
</div></details></div><h2id="provided-methods"class="small-section-header">Provided methods<ahref="#provided-methods"class="anchor"></a></h2><divclass="methods"><detailsclass="rustdoc-toggle"open><summary><divid="method.can_restore"class="method has-srclink"><divclass="rightside"><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#61-63">source</a></div><h4class="code-header">fn <ahref="#method.can_restore"class="fnname">can_restore</a>(&self) -><aclass="primitive"href="https://doc.rust-lang.org/1.60.0/std/primitive.bool.html">bool</a></h4></div></summary><divclass="docblock"><p>If a new Panel is being created to replace an older one, all widgets have the chance to
</div></details><detailsclass="rustdoc-toggle"open><summary><divid="method.restore"class="method has-srclink"><divclass="rightside"><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#66-68">source</a></div><h4class="code-header">fn <ahref="#method.restore"class="fnname">restore</a>(&mut self, _: &mut <aclass="struct"href="event_ctx/struct.EventCtx.html"title="struct widgetry::event_ctx::EventCtx">EventCtx</a><'_>, _prev: &dyn <aclass="trait"href="widgets/trait.WidgetImpl.html"title="trait widgetry::widgets::WidgetImpl">WidgetImpl</a>)</h4></div></summary><divclass="docblock"><p>Restore state from the previous version of this widget, with the same ID. Implementors must
</div></details></div><h2id="implementations"class="small-section-header">Implementations<ahref="#implementations"class="anchor"></a></h2><detailsclass="rustdoc-toggle implementors-toggle"open><summary><sectionid="impl"class="impl has-srclink"><spanclass="rightside"><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#112">source</a></span><ahref="#impl"class="anchor"></a><h3class="code-header in-band">impl dyn <aclass="trait"href="widgets/trait.WidgetImpl.html"title="trait widgetry::widgets::WidgetImpl">WidgetImpl</a></h3></section></summary><divclass="impl-items"><detailsclass="rustdoc-toggle method-toggle"open><summary><sectionid="method.is"class="method has-srclink"><spanclass="rightside"><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#112">source</a></span><ahref="#method.is"class="anchor"></a><h4class="code-header">pub fn <ahref="#method.is"class="fnname">is</a><__T: <aclass="trait"href="widgets/trait.WidgetImpl.html"title="trait widgetry::widgets::WidgetImpl">WidgetImpl</a>>(&self) -><aclass="primitive"href="https://doc.rust-lang.org/1.60.0/std/primitive.bool.html">bool</a></h4></section></summary><divclass="docblock"><p>Returns true if the trait object wraps an object of type <code>__T</code>.</p>
</div></details><detailsclass="rustdoc-toggle method-toggle"open><summary><sectionid="method.downcast"class="method has-srclink"><spanclass="rightside"><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#112">source</a></span><ahref="#method.downcast"class="anchor"></a><h4class="code-header">pub fn <ahref="#method.downcast"class="fnname">downcast</a><__T: <aclass="trait"href="widgets/trait.WidgetImpl.html"title="trait widgetry::widgets::WidgetImpl">WidgetImpl</a>>(self: <aclass="struct"href="https://doc.rust-lang.org/1.60.0/alloc/boxed/struct.Box.html"title="struct alloc::boxed::Box">Box</a><Self>) -><aclass="enum"href="https://doc.rust-lang.org/1.60.0/core/result/enum.Result.html"title="enum core::result::Result">Result</a><<aclass="struct"href="https://doc.rust-lang.org/1.60.0/alloc/boxed/struct.Box.html"title="struct alloc::boxed::Box">Box</a><__T>, <aclass="struct"href="https://doc.rust-lang.org/1.60.0/alloc/boxed/struct.Box.html"title="struct alloc::boxed::Box">Box</a><Self>></h4></section></summary><divclass="docblock"><p>Returns a boxed object from a boxed trait object if the underlying object is of type
</div></details><detailsclass="rustdoc-toggle method-toggle"open><summary><sectionid="method.downcast_rc"class="method has-srclink"><spanclass="rightside"><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#112">source</a></span><ahref="#method.downcast_rc"class="anchor"></a><h4class="code-header">pub fn <ahref="#method.downcast_rc"class="fnname">downcast_rc</a><__T: <aclass="trait"href="widgets/trait.WidgetImpl.html"title="trait widgetry::widgets::WidgetImpl">WidgetImpl</a>>(self: <aclass="struct"href="https://doc.rust-lang.org/1.60.0/alloc/rc/struct.Rc.html"title="struct alloc::rc::Rc">Rc</a><Self>) -><aclass="enum"href="https://doc.rust-lang.org/1.60.0/core/result/enum.Result.html"title="enum core::result::Result">Result</a><<aclass="struct"href="https://doc.rust-lang.org/1.60.0/alloc/rc/struct.Rc.html"title="struct alloc::rc::Rc">Rc</a><__T>, <aclass="struct"href="https://doc.rust-lang.org/1.60.0/alloc/rc/struct.Rc.html"title="struct alloc::rc::Rc">Rc</a><Self>></h4></section></summary><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></details><detailsclass="rustdoc-toggle method-toggle"open><summary><sectionid="method.downcast_ref"class="method has-srclink"><spanclass="rightside"><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#112">source</a></span><ahref="#method.downcast_ref"class="anchor"></a><h4class="code-header">pub fn <ahref="#method.downcast_ref"class="fnname">downcast_ref</a><__T: <aclass="trait"href="widgets/trait.WidgetImpl.html"title="trait widgetry::widgets::WidgetImpl">WidgetImpl</a>>(&self) -><aclass="enum"href="https://doc.rust-lang.org/1.60.0/core/option/enum.Option.html"title="enum core::option::Option">Option</a><<aclass="primitive"href="https://doc.rust-lang.org/1.60.0/std/primitive.reference.html">&</a>__T></h4></section></summary><divclass="docblock"><p>Returns a reference to the object within the trait object if it is of type <code>__T</code>, or
</div></details><detailsclass="rustdoc-toggle method-toggle"open><summary><sectionid="method.downcast_mut"class="method has-srclink"><spanclass="rightside"><aclass="srclink"href="../src/widgetry/widgets/mod.rs.html#112">source</a></span><ahref="#method.downcast_mut"class="anchor"></a><h4class="code-header">pub fn <ahref="#method.downcast_mut"class="fnname">downcast_mut</a><__T: <aclass="trait"href="widgets/trait.WidgetImpl.html"title="trait widgetry::widgets::WidgetImpl">WidgetImpl</a>>(&mut self) -><aclass="enum"href="https://doc.rust-lang.org/1.60.0/core/option/enum.Option.html"title="enum core::option::Option">Option</a><<aclass="primitive"href="https://doc.rust-lang.org/1.60.0/std/primitive.reference.html">&mut </a>__T></h4></section></summary><divclass="docblock"><p>Returns a mutable reference to the object within the trait object if it is of type