56 lines
14 KiB
HTML
56 lines
14 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 widget providing a conjoined set of linear items that function in conjunction as a single button."><title>cosmic::widget::segmented_button - 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 mod"><!--[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="#">Module segmented_<wbr>button</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example" title="Example">Example</a></li></ul><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#functions" title="Functions">Functions</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In cosmic::<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">widget</a></div><h1>Module <span>segmented_button</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/cosmic/widget/segmented_button/mod.rs.html#4-112">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A widget providing a conjoined set of linear items that function in conjunction as a single button.</p>
|
||
|
|
<h3 id="example"><a class="doc-anchor" href="#example">§</a>Example</h3>
|
||
|
|
<p>Add the model and a message variant in your application for handling selections.</p>
|
||
|
|
|
||
|
|
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">use </span>iced_core::Length;
|
||
|
|
<span class="kw">use </span>cosmic::theme;
|
||
|
|
<span class="kw">use </span>cosmic::widget::segmented_button;
|
||
|
|
|
||
|
|
<span class="kw">enum </span>AppMessage {
|
||
|
|
Selected(segmented_button::Key)
|
||
|
|
}
|
||
|
|
|
||
|
|
<span class="kw">struct </span>App {
|
||
|
|
model: segmented_button::SingleSelectModel,
|
||
|
|
}</code></pre></div>
|
||
|
|
<p>Then add choices to the model, while activating the first.</p>
|
||
|
|
|
||
|
|
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code>application.model = segmented_button::Model::builder()
|
||
|
|
.insert(|b| b.text(<span class="string">"Choice A"</span>).data(<span class="number">0u16</span>))
|
||
|
|
.insert(|b| b.text(<span class="string">"Choice B"</span>).data(<span class="number">1u16</span>))
|
||
|
|
.insert(|b| b.text(<span class="string">"Choice C"</span>).data(<span class="number">2u16</span>))
|
||
|
|
.build();</code></pre></div>
|
||
|
|
<p>Or incrementally insert items with</p>
|
||
|
|
|
||
|
|
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">let </span>id = application.model.insert()
|
||
|
|
.text(<span class="string">"Choice C"</span>)
|
||
|
|
.icon(<span class="string">"custom-icon"</span>)
|
||
|
|
.data(<span class="number">3u16</span>)
|
||
|
|
.data(<span class="string">"custom-meta"</span>)
|
||
|
|
.id();</code></pre></div>
|
||
|
|
<p>Then use it in the view method to create segmented button widgets.</p>
|
||
|
|
|
||
|
|
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">let </span>widget = segmented_button::horizontal(<span class="kw-2">&</span>application.model)
|
||
|
|
.style(theme::SegmentedButton::ViewSeitcher)
|
||
|
|
.button_height(<span class="number">32</span>)
|
||
|
|
.button_padding([<span class="number">16</span>, <span class="number">10</span>, <span class="number">16</span>, <span class="number">10</span>])
|
||
|
|
.button_spacing(<span class="number">8</span>)
|
||
|
|
.icon_size(<span class="number">16</span>)
|
||
|
|
.spacing(<span class="number">8</span>)
|
||
|
|
.on_activate(AppMessage::Selected);</code></pre></div>
|
||
|
|
<p>And respond to events like so:</p>
|
||
|
|
|
||
|
|
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">match </span>message {
|
||
|
|
AppMessage::Selected(id) => {
|
||
|
|
application.model.activate(id);
|
||
|
|
|
||
|
|
<span class="kw">if let </span><span class="prelude-val">Some</span>(number) = application.model.data::<u16>(id) {
|
||
|
|
<span class="macro">println!</span>(<span class="string">"activated item with number {number}"</span>);
|
||
|
|
}
|
||
|
|
|
||
|
|
<span class="kw">if let </span><span class="prelude-val">Some</span>(text) = application.text(id) {
|
||
|
|
<span class="macro">println!</span>(<span class="string">"activated button with text {text}"</span>);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}</code></pre></div>
|
||
|
|
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.Appearance.html" title="struct cosmic::widget::segmented_button::Appearance">Appearance</a></dt><dd>Appearance of the segmented button.</dd><dt><a class="struct" href="struct.BuilderEntity.html" title="struct cosmic::widget::segmented_button::BuilderEntity">Builder<wbr>Entity</a></dt><dd>Constructs a new item for the <a href="struct.ModelBuilder.html" title="struct cosmic::widget::segmented_button::ModelBuilder"><code>ModelBuilder</code></a>.</dd><dt><a class="struct" href="struct.Entity.html" title="struct cosmic::widget::segmented_button::Entity">Entity</a></dt><dd>A unique ID for an item in the <a href="struct.Model.html" title="struct cosmic::widget::segmented_button::Model"><code>Model</code></a>.</dd><dt><a class="struct" href="struct.EntityMut.html" title="struct cosmic::widget::segmented_button::EntityMut">Entity<wbr>Mut</a></dt><dd>A newly-inserted item which may have additional actions applied to it.</dd><dt><a class="struct" href="struct.Id.html" title="struct cosmic::widget::segmented_button::Id">Id</a></dt><dd>The iced identifier of a segmented button.</dd><dt><a class="struct" href="struct.ItemAppearance.html" title="struct cosmic::widget::segmented_button::ItemAppearance">Item<wbr>Appearance</a></dt><dd>Appearance of an item in the segmented button.</dd><dt><a class="struct" href="struct.ItemStatusAppearance.html" title="struct cosmic::widget::segmented_button::ItemStatusAppearance">Item<wbr>Status<wbr>Appearance</a></dt><dd>Appearance of an item based on its status.</dd><dt><a class="struct" href="struct.Model.html" title="struct cosmic::widget::segmented_button::Model">Model</a></dt><dd>The model held by the application, containing the unique IDs and data of each inserted item.</dd><dt><a class="struct" href="struct.ModelBuilder.html" title="struct cosmic::widget::segmented_button::ModelBuilder">Model<wbr>Builder</a></dt><dd>A builder for a <a href="struct.Model.html" title="struct cosmic::widget::segmented_button::Model"><code>Model</code></a>.</dd><dt><a class="struct" href="struct.MultiSelect.html" title="struct cosmic::widget::segmented_button::MultiSelect">Multi<wbr>Select</a></dt><dd><a href="struct.Model.html" title="struct cosmic::widget::segmented_button::Model"><code>Model<MultiSelect></code></a> permits multiple keys to be active at a time.</dd><dt><a class="struct" href="struct.ReorderEvent.html" title="struct cosmic::widget::segmented_button::ReorderEvent">Reorder<wbr>Event</a></dt><dt><a class="struct" href="struct.SegmentedButton.html" title="struct cosmic::widget::segmented_button::SegmentedButton">Segmented<wbr>Button</a></dt><dd>A conjoined group of items that function together as a button.</dd><dt><a class="struct" href="struct.SingleSelect.html" title="struct cosmic::widget::segmented_button::SingleSelect">Single<wbr>Select</a></dt><dd><a href="struct.Model.html" title="struct cosmic::widget::segmented_button::Model"><code>Model<SingleSelect></code></a> Ensures that only one key may be selected.</dd></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.InsertPosition.html" title="enum cosmic::widget::segmented_button::InsertPosition">Insert<wbr>Position</a></dt></dl><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><dl class="item-table"><dt><a class="trait" href="trait.SegmentedVariant.html" title="trait cosmic::widget::segmented_button::SegmentedVariant">Segmented<wbr>Variant</a></dt><dd>Isolates variant-specific behaviors from <a href="struct.SegmentedButton.html" title="struct cosmic::widget::segmented_button::SegmentedButton"><code>SegmentedButton</code></a>.</dd><dt><a class="trait" href="trait.Selectable.html" title="trait cosmic::widget::segmented_button::Selectable">Selectable</a></dt><dd>Describes a type that has selectable items.</dd><dt><a class="trait" href="trait.Styl
|