63 lines
No EOL
16 KiB
HTML
63 lines
No EOL
16 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A reusable, custom widget that uses The Elm Architecture."><title>Component in cosmic::iced::widget - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../static.files/storage-68b7e25d.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../cosmic/index.html">cosmic</a><span class="version">1.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Component</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#state" title="State">State</a></li></ul><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.Event" title="Event">Event</a></li><li><a href="#associatedtype.State" title="State">State</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.update" title="update">update</a></li><li><a href="#tymethod.view" title="view">view</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.operate" title="operate">operate</a></li><li><a href="#method.size_hint" title="size_hint">size_hint</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In cosmic::<wbr>iced::<wbr>widget</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../index.html">cosmic</a>::<wbr><a href="../index.html">iced</a>::<wbr><a href="index.html">widget</a></div><h1>Trait <span class="trait">Component</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>pub trait Component<Message, Theme = <a class="enum" href="../enum.Theme.html" title="enum cosmic::iced::Theme">Theme</a>, Renderer = Renderer> {
|
||
type <a href="#associatedtype.State" class="associatedtype">State</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a>;
|
||
type <a href="#associatedtype.Event" class="associatedtype">Event</a>;
|
||
|
||
// Required methods
|
||
fn <a href="#tymethod.update" class="fn">update</a>(
|
||
&mut self,
|
||
state: &mut Self::<a class="associatedtype" href="trait.Component.html#associatedtype.State" title="type cosmic::iced::widget::Component::State">State</a>,
|
||
event: Self::<a class="associatedtype" href="trait.Component.html#associatedtype.Event" title="type cosmic::iced::widget::Component::Event">Event</a>,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Message>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.view" class="fn">view</a>(
|
||
&self,
|
||
state: &Self::<a class="associatedtype" href="trait.Component.html#associatedtype.State" title="type cosmic::iced::widget::Component::State">State</a>,
|
||
) -> <a class="struct" href="../daemon/program/graphics/core/struct.Element.html" title="struct cosmic::iced::daemon::program::graphics::core::Element">Element</a><'_, Self::<a class="associatedtype" href="trait.Component.html#associatedtype.Event" title="type cosmic::iced::widget::Component::Event">Event</a>, Theme, Renderer>;
|
||
|
||
// Provided methods
|
||
fn <a href="#method.operate" class="fn">operate</a>(
|
||
&self,
|
||
_bounds: <a class="struct" href="../struct.Rectangle.html" title="struct cosmic::iced::Rectangle">Rectangle</a>,
|
||
_state: &mut Self::<a class="associatedtype" href="trait.Component.html#associatedtype.State" title="type cosmic::iced::widget::Component::State">State</a>,
|
||
_operation: &mut dyn <a class="trait" href="../../widget/trait.Operation.html" title="trait cosmic::widget::Operation">Operation</a>,
|
||
) { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.size_hint" class="fn">size_hint</a>(&self) -> <a class="struct" href="../struct.Size.html" title="struct cosmic::iced::Size">Size</a><<a class="enum" href="../enum.Length.html" title="enum cosmic::iced::Length">Length</a>> { ... }
|
||
}</code></pre><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.13.0: components introduce encapsulated state and hamper the use of a single source of truth. Instead, leverage the Elm Architecture directly, or implement a custom widget</span></div></span><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A reusable, custom widget that uses The Elm Architecture.</p>
|
||
<p>A <a href="trait.Component.html" title="trait cosmic::iced::widget::Component"><code>Component</code></a> allows you to implement custom widgets as if they were
|
||
<code>iced</code> applications with encapsulated state.</p>
|
||
<p>In other words, a <a href="trait.Component.html" title="trait cosmic::iced::widget::Component"><code>Component</code></a> allows you to turn <code>iced</code> applications into
|
||
custom widgets and embed them without cumbersome wiring.</p>
|
||
<p>A <a href="trait.Component.html" title="trait cosmic::iced::widget::Component"><code>Component</code></a> produces widgets that may fire an <a href="trait.Component.html#associatedtype.Event" title="associated type cosmic::iced::widget::Component::Event"><code>Event</code></a>
|
||
and update the internal state of the <a href="trait.Component.html" title="trait cosmic::iced::widget::Component"><code>Component</code></a>.</p>
|
||
<p>Additionally, a <a href="trait.Component.html" title="trait cosmic::iced::widget::Component"><code>Component</code></a> is capable of producing a <code>Message</code> to notify
|
||
the parent application of any relevant interactions.</p>
|
||
<h2 id="state"><a class="doc-anchor" href="#state">§</a>State</h2>
|
||
<p>A component can store its state in one of two ways: either as data within the
|
||
implementor of the trait, or in a type <a href="trait.Component.html#associatedtype.State" title="associated type cosmic::iced::widget::Component::State"><code>State</code></a> that is managed
|
||
by the runtime and provided to the trait methods. These two approaches are not
|
||
mutually exclusive and have opposite pros and cons.</p>
|
||
<p>For instance, if a piece of state is needed by multiple components that reside
|
||
in different branches of the tree, then it’s more convenient to let a common
|
||
ancestor store it and pass it down.</p>
|
||
<p>On the other hand, if a piece of state is only needed by the component itself,
|
||
you can store it as part of its internal <a href="trait.Component.html#associatedtype.State" title="associated type cosmic::iced::widget::Component::State"><code>State</code></a>.</p>
|
||
</div></details><h2 id="required-associated-types" class="section-header">Required Associated Types<a href="#required-associated-types" class="anchor">§</a></h2><div class="methods"><details class="toggle" open><summary><section id="associatedtype.State" class="method"><h4 class="code-header">type <a href="#associatedtype.State" class="associatedtype">State</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.13.0: components introduce encapsulated state and hamper the use of a single source of truth. Instead, leverage the Elm Architecture directly, or implement a custom widget</span></div></span></summary><div class="docblock"><p>The internal state of this <a href="trait.Component.html" title="trait cosmic::iced::widget::Component"><code>Component</code></a>.</p>
|
||
</div></details><details class="toggle" open><summary><section id="associatedtype.Event" class="method"><h4 class="code-header">type <a href="#associatedtype.Event" class="associatedtype">Event</a></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.13.0: components introduce encapsulated state and hamper the use of a single source of truth. Instead, leverage the Elm Architecture directly, or implement a custom widget</span></div></span></summary><div class="docblock"><p>The type of event this <a href="trait.Component.html" title="trait cosmic::iced::widget::Component"><code>Component</code></a> handles internally.</p>
|
||
</div></details></div><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.update" class="method"><h4 class="code-header">fn <a href="#tymethod.update" class="fn">update</a>(
|
||
&mut self,
|
||
state: &mut Self::<a class="associatedtype" href="trait.Component.html#associatedtype.State" title="type cosmic::iced::widget::Component::State">State</a>,
|
||
event: Self::<a class="associatedtype" href="trait.Component.html#associatedtype.Event" title="type cosmic::iced::widget::Component::Event">Event</a>,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Message></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.13.0: components introduce encapsulated state and hamper the use of a single source of truth. Instead, leverage the Elm Architecture directly, or implement a custom widget</span></div></span></summary><div class="docblock"><p>Processes an <a href="trait.Component.html#associatedtype.Event" title="associated type cosmic::iced::widget::Component::Event"><code>Event</code></a> and updates the <a href="trait.Component.html" title="trait cosmic::iced::widget::Component"><code>Component</code></a> state accordingly.</p>
|
||
<p>It can produce a <code>Message</code> for the parent application.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.view" class="method"><h4 class="code-header">fn <a href="#tymethod.view" class="fn">view</a>(&self, state: &Self::<a class="associatedtype" href="trait.Component.html#associatedtype.State" title="type cosmic::iced::widget::Component::State">State</a>) -> <a class="struct" href="../daemon/program/graphics/core/struct.Element.html" title="struct cosmic::iced::daemon::program::graphics::core::Element">Element</a><'_, Self::<a class="associatedtype" href="trait.Component.html#associatedtype.Event" title="type cosmic::iced::widget::Component::Event">Event</a>, Theme, Renderer></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.13.0: components introduce encapsulated state and hamper the use of a single source of truth. Instead, leverage the Elm Architecture directly, or implement a custom widget</span></div></span></summary><div class="docblock"><p>Produces the widgets of the <a href="trait.Component.html" title="trait cosmic::iced::widget::Component"><code>Component</code></a>, which may trigger an <a href="trait.Component.html#associatedtype.Event" title="associated type cosmic::iced::widget::Component::Event"><code>Event</code></a>
|
||
on user interaction.</p>
|
||
</div></details></div><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.operate" class="method"><h4 class="code-header">fn <a href="#method.operate" class="fn">operate</a>(
|
||
&self,
|
||
_bounds: <a class="struct" href="../struct.Rectangle.html" title="struct cosmic::iced::Rectangle">Rectangle</a>,
|
||
_state: &mut Self::<a class="associatedtype" href="trait.Component.html#associatedtype.State" title="type cosmic::iced::widget::Component::State">State</a>,
|
||
_operation: &mut dyn <a class="trait" href="../../widget/trait.Operation.html" title="trait cosmic::widget::Operation">Operation</a>,
|
||
)</h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.13.0: components introduce encapsulated state and hamper the use of a single source of truth. Instead, leverage the Elm Architecture directly, or implement a custom widget</span></div></span></summary><div class="docblock"><p>Update the <a href="trait.Component.html" title="trait cosmic::iced::widget::Component"><code>Component</code></a> state based on the provided <a href="../../widget/trait.Operation.html" title="trait cosmic::widget::Operation"><code>Operation</code></a></p>
|
||
<p>By default, it does nothing.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.size_hint" class="method"><h4 class="code-header">fn <a href="#method.size_hint" class="fn">size_hint</a>(&self) -> <a class="struct" href="../struct.Size.html" title="struct cosmic::iced::Size">Size</a><<a class="enum" href="../enum.Length.html" title="enum cosmic::iced::Length">Length</a>></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.13.0: components introduce encapsulated state and hamper the use of a single source of truth. Instead, leverage the Elm Architecture directly, or implement a custom widget</span></div></span></summary><div class="docblock"><p>Returns a <a href="../struct.Size.html" title="struct cosmic::iced::Size"><code>Size</code></a> hint for laying out the <a href="trait.Component.html" title="trait cosmic::iced::widget::Component"><code>Component</code></a>.</p>
|
||
<p>This hint may be used by some widget containers to adjust their sizing strategy
|
||
during construction.</p>
|
||
</div></details></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"></div><script src="../../../trait.impl/iced_widget/lazy/component/trait.Component.js" async></script></section></div></main></body></html> |