libcosmic/cosmic/widget/canvas/trait.Program.html
2026-04-18 20:11:25 +00:00

84 lines
No EOL
19 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="The state and logic of a `Canvas`."><title>Program in cosmic::widget::canvas - 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="#">Program</a></h2><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><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.draw" title="draw">draw</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.mouse_interaction" title="mouse_interaction">mouse_interaction</a></li><li><a href="#method.update" title="update">update</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-Program%3CMessage,+Theme,+Renderer%3E-for-%26T" title="&#38;T">&#38;T</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In cosmic::<wbr>widget::<wbr>canvas</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">widget</a>::<wbr><a href="index.html">canvas</a></div><h1>Trait <span class="trait">Program</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 Program&lt;Message, Theme = <a class="enum" href="../../iced/enum.Theme.html" title="enum cosmic::iced::Theme">Theme</a>, Renderer = Renderer&gt;<div class="where">where
Renderer: <a class="trait" href="../../iced/daemon/program/graphics/geometry/trait.Renderer.html" title="trait cosmic::iced::daemon::program::graphics::geometry::Renderer">Renderer</a>,</div>{
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> + 'static;
// Required method
fn <a href="#tymethod.draw" class="fn">draw</a>(
&amp;self,
state: &amp;Self::<a class="associatedtype" href="trait.Program.html#associatedtype.State" title="type cosmic::widget::canvas::Program::State">State</a>,
renderer: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;Renderer</a>,
theme: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;Theme</a>,
bounds: <a class="struct" href="../../iced/struct.Rectangle.html" title="struct cosmic::iced::Rectangle">Rectangle</a>,
cursor: <a class="enum" href="../../iced/mouse/enum.Cursor.html" title="enum cosmic::iced::mouse::Cursor">Cursor</a>,
) -&gt; <a class="struct" href="../../cctk/sctk/reexports/client/backend/smallvec/alloc/vec/struct.Vec.html" title="struct cosmic::cctk::sctk::reexports::client::backend::smallvec::alloc::vec::Vec">Vec</a>&lt;&lt;Renderer as <a class="trait" href="../../iced/daemon/program/graphics/geometry/trait.Renderer.html" title="trait cosmic::iced::daemon::program::graphics::geometry::Renderer">Renderer</a>&gt;::<a class="associatedtype" href="../../iced/daemon/program/graphics/geometry/trait.Renderer.html#associatedtype.Geometry" title="type cosmic::iced::daemon::program::graphics::geometry::Renderer::Geometry">Geometry</a>&gt;;
// Provided methods
fn <a href="#method.update" class="fn">update</a>(
&amp;self,
_state: &amp;mut Self::<a class="associatedtype" href="trait.Program.html#associatedtype.State" title="type cosmic::widget::canvas::Program::State">State</a>,
_event: &amp;<a class="enum" href="../../iced/enum.Event.html" title="enum cosmic::iced::Event">Event</a>,
_bounds: <a class="struct" href="../../iced/struct.Rectangle.html" title="struct cosmic::iced::Rectangle">Rectangle</a>,
_cursor: <a class="enum" href="../../iced/mouse/enum.Cursor.html" title="enum cosmic::iced::mouse::Cursor">Cursor</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="struct.Action.html" title="struct cosmic::widget::canvas::Action">Action</a>&lt;Message&gt;&gt; { ... }
<span class="item-spacer"></span> fn <a href="#method.mouse_interaction" class="fn">mouse_interaction</a>(
&amp;self,
_state: &amp;Self::<a class="associatedtype" href="trait.Program.html#associatedtype.State" title="type cosmic::widget::canvas::Program::State">State</a>,
_bounds: <a class="struct" href="../../iced/struct.Rectangle.html" title="struct cosmic::iced::Rectangle">Rectangle</a>,
_cursor: <a class="enum" href="../../iced/mouse/enum.Cursor.html" title="enum cosmic::iced::mouse::Cursor">Cursor</a>,
) -&gt; <a class="enum" href="../../iced/mouse/enum.Interaction.html" title="enum cosmic::iced::mouse::Interaction">Interaction</a> { ... }
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>The state and logic of a <a href="../struct.Canvas.html" title="struct cosmic::widget::Canvas"><code>Canvas</code></a>.</p>
<p>A <a href="trait.Program.html" title="trait cosmic::widget::canvas::Program"><code>Program</code></a> can mutate internal state and produce messages for an
application.</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> + 'static</h4></section></summary><div class="docblock"><p>The internal state mutated by the <a href="trait.Program.html" title="trait cosmic::widget::canvas::Program"><code>Program</code></a>.</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.draw" class="method"><h4 class="code-header">fn <a href="#tymethod.draw" class="fn">draw</a>(
&amp;self,
state: &amp;Self::<a class="associatedtype" href="trait.Program.html#associatedtype.State" title="type cosmic::widget::canvas::Program::State">State</a>,
renderer: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;Renderer</a>,
theme: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;Theme</a>,
bounds: <a class="struct" href="../../iced/struct.Rectangle.html" title="struct cosmic::iced::Rectangle">Rectangle</a>,
cursor: <a class="enum" href="../../iced/mouse/enum.Cursor.html" title="enum cosmic::iced::mouse::Cursor">Cursor</a>,
) -&gt; <a class="struct" href="../../cctk/sctk/reexports/client/backend/smallvec/alloc/vec/struct.Vec.html" title="struct cosmic::cctk::sctk::reexports::client::backend::smallvec::alloc::vec::Vec">Vec</a>&lt;&lt;Renderer as <a class="trait" href="../../iced/daemon/program/graphics/geometry/trait.Renderer.html" title="trait cosmic::iced::daemon::program::graphics::geometry::Renderer">Renderer</a>&gt;::<a class="associatedtype" href="../../iced/daemon/program/graphics/geometry/trait.Renderer.html#associatedtype.Geometry" title="type cosmic::iced::daemon::program::graphics::geometry::Renderer::Geometry">Geometry</a>&gt;</h4></section></summary><div class="docblock"><p>Draws the state of the <a href="trait.Program.html" title="trait cosmic::widget::canvas::Program"><code>Program</code></a>, producing a bunch of <a href="type.Geometry.html" title="type cosmic::widget::canvas::Geometry"><code>Geometry</code></a>.</p>
<p><a href="type.Geometry.html" title="type cosmic::widget::canvas::Geometry"><code>Geometry</code></a> can be easily generated with a <a href="type.Frame.html" title="type cosmic::widget::canvas::Frame"><code>Frame</code></a> or stored in a
<a href="type.Cache.html" title="type cosmic::widget::canvas::Cache"><code>Cache</code></a>.</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.update" class="method"><h4 class="code-header">fn <a href="#method.update" class="fn">update</a>(
&amp;self,
_state: &amp;mut Self::<a class="associatedtype" href="trait.Program.html#associatedtype.State" title="type cosmic::widget::canvas::Program::State">State</a>,
_event: &amp;<a class="enum" href="../../iced/enum.Event.html" title="enum cosmic::iced::Event">Event</a>,
_bounds: <a class="struct" href="../../iced/struct.Rectangle.html" title="struct cosmic::iced::Rectangle">Rectangle</a>,
_cursor: <a class="enum" href="../../iced/mouse/enum.Cursor.html" title="enum cosmic::iced::mouse::Cursor">Cursor</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="struct.Action.html" title="struct cosmic::widget::canvas::Action">Action</a>&lt;Message&gt;&gt;</h4></section></summary><div class="docblock"><p>Updates the <a href="trait.Program.html#associatedtype.State" title="associated type iced_widget::canvas::program::Program::State::State"><code>State</code></a> of the <a href="trait.Program.html" title="trait cosmic::widget::canvas::Program"><code>Program</code></a>.</p>
<p>When a <a href="trait.Program.html" title="trait cosmic::widget::canvas::Program"><code>Program</code></a> is used in a <a href="../struct.Canvas.html" title="struct cosmic::widget::Canvas"><code>Canvas</code></a>, the runtime will call this
method for each <a href="../../iced/enum.Event.html" title="enum cosmic::iced::Event"><code>Event</code></a>.</p>
<p>This method can optionally return an <a href="struct.Action.html" title="struct cosmic::widget::canvas::Action"><code>Action</code></a> to either notify an
application of any meaningful interactions, capture the event, or
request a redraw.</p>
<p>By default, this method does and returns nothing.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.mouse_interaction" class="method"><h4 class="code-header">fn <a href="#method.mouse_interaction" class="fn">mouse_interaction</a>(
&amp;self,
_state: &amp;Self::<a class="associatedtype" href="trait.Program.html#associatedtype.State" title="type cosmic::widget::canvas::Program::State">State</a>,
_bounds: <a class="struct" href="../../iced/struct.Rectangle.html" title="struct cosmic::iced::Rectangle">Rectangle</a>,
_cursor: <a class="enum" href="../../iced/mouse/enum.Cursor.html" title="enum cosmic::iced::mouse::Cursor">Cursor</a>,
) -&gt; <a class="enum" href="../../iced/mouse/enum.Interaction.html" title="enum cosmic::iced::mouse::Interaction">Interaction</a></h4></section></summary><div class="docblock"><p>Returns the current mouse interaction of the <a href="trait.Program.html" title="trait cosmic::widget::canvas::Program"><code>Program</code></a>.</p>
<p>The interaction returned will be in effect even if the cursor position
is out of bounds of the programs <a href="../struct.Canvas.html" title="struct cosmic::widget::Canvas"><code>Canvas</code></a>.</p>
</div></details></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-Program%3CMessage,+Theme,+Renderer%3E-for-%26T" class="impl"><a href="#impl-Program%3CMessage,+Theme,+Renderer%3E-for-%26T" class="anchor">§</a><h3 class="code-header">impl&lt;Message, Theme, Renderer, T&gt; <a class="trait" href="trait.Program.html" title="trait cosmic::widget::canvas::Program">Program</a>&lt;Message, Theme, Renderer&gt; for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;T</a><div class="where">where
Renderer: <a class="trait" href="../../iced/daemon/program/graphics/geometry/trait.Renderer.html" title="trait cosmic::iced::daemon::program::graphics::geometry::Renderer">Renderer</a>,
T: <a class="trait" href="trait.Program.html" title="trait cosmic::widget::canvas::Program">Program</a>&lt;Message, Theme, Renderer&gt;,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.State-1" class="associatedtype trait-impl"><a href="#associatedtype.State-1" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.State" class="associatedtype">State</a> = &lt;T as <a class="trait" href="trait.Program.html" title="trait cosmic::widget::canvas::Program">Program</a>&lt;Message, Theme, Renderer&gt;&gt;::<a class="associatedtype" href="trait.Program.html#associatedtype.State" title="type cosmic::widget::canvas::Program::State">State</a></h4></section><section id="method.update-1" class="method trait-impl"><a href="#method.update-1" class="anchor">§</a><h4 class="code-header">fn <a href="#method.update" class="fn">update</a>(
&amp;self,
state: &amp;mut &lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;T</a> as <a class="trait" href="trait.Program.html" title="trait cosmic::widget::canvas::Program">Program</a>&lt;Message, Theme, Renderer&gt;&gt;::<a class="associatedtype" href="trait.Program.html#associatedtype.State" title="type cosmic::widget::canvas::Program::State">State</a>,
event: &amp;<a class="enum" href="../../iced/enum.Event.html" title="enum cosmic::iced::Event">Event</a>,
bounds: <a class="struct" href="../../iced/struct.Rectangle.html" title="struct cosmic::iced::Rectangle">Rectangle</a>,
cursor: <a class="enum" href="../../iced/mouse/enum.Cursor.html" title="enum cosmic::iced::mouse::Cursor">Cursor</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="struct.Action.html" title="struct cosmic::widget::canvas::Action">Action</a>&lt;Message&gt;&gt;</h4></section><section id="method.draw" class="method trait-impl"><a href="#method.draw" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.draw" class="fn">draw</a>(
&amp;self,
state: &amp;&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;T</a> as <a class="trait" href="trait.Program.html" title="trait cosmic::widget::canvas::Program">Program</a>&lt;Message, Theme, Renderer&gt;&gt;::<a class="associatedtype" href="trait.Program.html#associatedtype.State" title="type cosmic::widget::canvas::Program::State">State</a>,
renderer: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;Renderer</a>,
theme: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;Theme</a>,
bounds: <a class="struct" href="../../iced/struct.Rectangle.html" title="struct cosmic::iced::Rectangle">Rectangle</a>,
cursor: <a class="enum" href="../../iced/mouse/enum.Cursor.html" title="enum cosmic::iced::mouse::Cursor">Cursor</a>,
) -&gt; <a class="struct" href="../../cctk/sctk/reexports/client/backend/smallvec/alloc/vec/struct.Vec.html" title="struct cosmic::cctk::sctk::reexports::client::backend::smallvec::alloc::vec::Vec">Vec</a>&lt;&lt;Renderer as <a class="trait" href="../../iced/daemon/program/graphics/geometry/trait.Renderer.html" title="trait cosmic::iced::daemon::program::graphics::geometry::Renderer">Renderer</a>&gt;::<a class="associatedtype" href="../../iced/daemon/program/graphics/geometry/trait.Renderer.html#associatedtype.Geometry" title="type cosmic::iced::daemon::program::graphics::geometry::Renderer::Geometry">Geometry</a>&gt;</h4></section><section id="method.mouse_interaction-1" class="method trait-impl"><a href="#method.mouse_interaction-1" class="anchor">§</a><h4 class="code-header">fn <a href="#method.mouse_interaction" class="fn">mouse_interaction</a>(
&amp;self,
state: &amp;&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;T</a> as <a class="trait" href="trait.Program.html" title="trait cosmic::widget::canvas::Program">Program</a>&lt;Message, Theme, Renderer&gt;&gt;::<a class="associatedtype" href="trait.Program.html#associatedtype.State" title="type cosmic::widget::canvas::Program::State">State</a>,
bounds: <a class="struct" href="../../iced/struct.Rectangle.html" title="struct cosmic::iced::Rectangle">Rectangle</a>,
cursor: <a class="enum" href="../../iced/mouse/enum.Cursor.html" title="enum cosmic::iced::mouse::Cursor">Cursor</a>,
) -&gt; <a class="enum" href="../../iced/mouse/enum.Interaction.html" title="enum cosmic::iced::mouse::Interaction">Interaction</a></h4></section></div></details><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/canvas/program/trait.Program.js" async></script></section></div></main></body></html>