Skip to main content

Selector

Struct Selector 

Source
pub struct Selector<S: SignalRw<K>, K: Route = String> { /* private fields */ }
Expand description

A one-of-N selector whose active key is an app-owned signal (two-way, exactly like Picker/Toggle). Deep links and dayscript address items by key (docs/navigation.md).

The key type is any Route: String for raw keys, or a typed enum — use Signal<Option<Section>> for a sidebar (None = the collapsed mobile list) and Signal<Tab> for tabs (always selected).

let section = Signal::new("home".to_string());   // or Signal::new(None::<Section>)
selector(section).style(SelectorStyle::Sidebar)
    .item("home", tr("home"), home_page)         // or .item(Section::Home, …)
    .item("settings", tr("settings"), settings_page)

Implementations§

Source§

impl<K: Route, S: SignalRw<K>> Selector<S, K>

Source

pub fn style(self, style: SelectorStyle) -> Self

Source

pub fn title<M>(self, t: impl IntoText<M>) -> Self

The sidebar / window title (Sidebar style).

Source

pub fn section<M>(self, title: impl IntoText<M>) -> Self

Open a section: the NEXT item added (static or the first row of the next .items block) carries this header. Backends without grouped rows ignore it and show one flat list, so a section is a grouping hint, never a source of items the user cannot otherwise reach.

selector(sel)
    .section(res::str::smart_feeds())
    .item_icon("today", res::str::today(), res::images::today, today_page)
    .section(res::str::feeds())
    .items(move || st.feeds.get(), |f| item(f.id, f.name))
Source

pub fn badge<M>(self, badge: impl IntoText<M>) -> Self

Attach a trailing badge — an unread count, a status — to the item just added: .item(…).badge(move || n.get().to_string()). Reactive, so a live count repaints on its own signal. An empty string draws nothing, which is the natural “zero” case.

Ignored (in release) when no static item precedes it; data-driven rows carry their own badge via NavItem::badge.

Source

pub fn header<P: Piece>(self, build: impl FnOnce() -> P + 'static) -> Self

An optional piece shown above the sidebar list (a logo, app name…).

Source

pub fn item<M, P: Piece>( self, key: impl Into<K>, title: impl IntoText<M>, build: impl Fn() -> P + 'static, ) -> Self

Add a destination. key addresses it (navigate / deep link / dayscript); title is its label; build runs when the item is first shown. For a typed selector over Option<Section> pass the bare Section::X.

Source

pub fn item_icon<M, P: Piece>( self, key: impl Into<K>, title: impl IntoText<M>, icon: impl Into<ImageName>, build: impl Fn() -> P + 'static, ) -> Self

Like item but with a native icon: icon is a bundled-image name (typed ImageName, resolved like image, e.g. res::images::nav_home) shown beside the label where the backend’s nav supports it (e.g. the Windows NavigationView, the iOS/macOS source list). Backends that can’t decorate rows ignore it.

Source

pub fn immersive(self) -> Self

Mark the LAST-added .item/.item_icon destination as an immersive-chrome page (docs/navigation.md): on backends with an immersive nav mode (android edge-to-edge today) its pushed page keeps the floating transparent bar over full-bleed content; unmarked pages get the standard opaque bar. A no-op on every other backend. For a data-driven .items block, mark individual rows with NavItem::immersive instead.

Source

pub fn items<T: Clone + 'static>( self, items: impl Fn() -> Vec<T> + 'static, map: impl Fn(&T) -> NavItem<K> + 'static, ) -> Self

A data-driven item block: .items(rooms_signal, |r| item(r.id, r.name).icon(…)) (docs/navigation.md). The block re-derives whenever the signal changes — rows are added and removed on the native sidebar/tab widget, and if the selected key disappears the selection resets (to None for an Option key). Static .items and dynamic blocks may be mixed; the final list is their declaration order. Pair with destination to build the page for a data-driven key.

Source

pub fn destination<P: Piece>(self, build: impl Fn(&K) -> P + 'static) -> Self

Build the page for a data-driven key (one added by items with no static item). Mirrors Stack::destination; unused for a purely static selector.

Source

pub fn local(self) -> Self

Use this selector as a LOCAL widget: its selection is not part of the app route, so it neither adds a segment to current_route nor intercepts navigate/deep links.

Reach for this when a page already routes and you embed a second one-of-N control in it (a filter tab strip, a secondary sidebar). Two routing selectors at the same level both feed current_route(), so you’d get section/childA/childB and navigate("childB") would be ambiguous — mark all but the primary one .local(). A selector nested one level deeper (a Tabs inside a Sidebar section) is a different case and should stay routed: that cascade is the point. In debug builds, two routed one-of-N surfaces at the same level log a warning naming this fix (docs/navigation.md).

Source

pub fn restore(self, key: impl Into<String>) -> Self

Remember the selected item across launches (docs/navigation.md). The selected key is saved under key on every change and restored at build — so the app reopens on the tab/section the user last had — unless a launch deep link is pending, which wins. Restore is a no-op until the app installs a store (e.g. day_part_prefs::install_nav_store); a stale saved key (its item no longer exists) is ignored. Works whether or not the selector is routed.

Source

pub fn bar_action<M>( self, icon: impl Into<ImageName>, label: impl IntoText<M>, action: impl Fn() + 'static, ) -> Self

Add a trailing action button to the navigation bar, for the toolkits that have no window toolbar (the phones and HarmonyOS — Cap::Toolbar is Unsupported): an upper-right bar button drawn with the bundled icon that runs action when tapped (docs/navigation.md). icon is a bundled-image name (typed ImageName, like item_icon’s); label is the button’s accessible name and tooltip.

Desktop split presentations ignore it — they have a real toolbar, so put the same command there (docs/toolbars.md). The action is app-wide: it rides the current top page’s bar, so the same handler serves every section (read current_route inside it to act on whatever is showing).

Trait Implementations§

Source§

impl<K: Route, S: SignalRw<K>> Piece for Selector<S, K>

Source§

fn build(self, cx: &mut BuildCx) -> RNode

Auto Trait Implementations§

§

impl<S, K> Freeze for Selector<S, K>
where S: Freeze,

§

impl<S, K = String> !RefUnwindSafe for Selector<S, K>

§

impl<S, K = String> !Send for Selector<S, K>

§

impl<S, K = String> !Sync for Selector<S, K>

§

impl<S, K> Unpin for Selector<S, K>
where S: Unpin, K: Unpin,

§

impl<S, K> UnsafeUnpin for Selector<S, K>
where S: UnsafeUnpin,

§

impl<S, K = String> !UnwindSafe for Selector<S, K>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<P> Decorate for P
where P: Piece,

Source§

fn id(self, id: impl Into<String>) -> AnyPiece

Stable element identifier: a11y identifier + dayscript locator + lint uniqueness (§5.5).
Source§

fn id_of(self, id: impl Fn() -> String + 'static) -> AnyPiece

Reactive element id — the id for rows inside a recycling list. A plain id is assigned once at build, but a recycled cell REBINDS to different items over its life (and drag-to-reorder rebinds eagerly), so a static item-derived id keeps naming the first-bound item. This variant re-registers whenever the closure’s value changes — read your ItemSlot inside it: .id_of(move || format!("row-remove-{}", slot.key())).
Source§

fn id_keyed(self, prefix: &'static str, key: impl Display) -> AnyPiece

Keyed id for collection items: rendered prefix:key (§5.5).
Source§

fn tweak(self, f: impl FnOnce(RNode) + 'static) -> AnyPiece

Apply a tweak: f runs once at mount, after the native widget exists, with the realized node (docs/tweaks.md). Reach the typed native handle through the compiled backend’s ext accessor (day_appkit::with_native, day_gtk::with_native, …) — or apply a packaged day-tweak-* crate’s modifier instead of calling this directly. If the native change affects the widget’s intrinsic size, follow it with day_core::invalidate_size. Day may overwrite managed properties (title, value, enabled, frame, a11y) on its next patch; unmanaged properties are stable.
Source§

fn selectable(self) -> AnyPiece

Make this piece’s text user-selectable — the reader can select and copy it (docs/text.md). Most useful on a label: text is NOT selectable by default on any backend, matching each platform’s native behavior. Applied to the piece’s own widget, so on a container it makes all the text within it selectable. Read more
Source§

fn native_ref(self, r: &NativeRef) -> AnyPiece

Capture a NativeRef to this piece’s realized node for later imperative access (docs/tweaks.md). The ref clears automatically when the piece’s scope is disposed.
Source§

fn padding(self, insets: impl IntoInsets) -> AnyPiece

Source§

fn max_width(self, max: f64) -> AnyPiece

Cap this piece’s width at max points: the child is never PROPOSED more, so text wraps inside the cap (chat bubbles, readable columns) while narrower content hugs.
Source§

fn frame(self, width: f64, height: f64) -> AnyPiece

Source§

fn width(self, width: f64) -> AnyPiece

Fix this piece’s WIDTH to width points while its height stays flexible (hugging its content or filling on the cross axis). The single-axis complement to Self::frame — e.g. a fixed-width sidebar pane in a row whose height fills the window.
Source§

fn height(self, height: f64) -> AnyPiece

Fix this piece’s HEIGHT to height points while its width stays flexible. The single-axis complement to Self::frame — e.g. a fixed-height header/toolbar bar that fills its width.
Source§

fn a11y(self, f: impl FnOnce(A11yBuilder) -> A11yBuilder + 'static) -> AnyPiece

Source§

fn on_tap(self, f: impl Fn() + 'static) -> AnyPiece

Fire when this piece is tapped (bounding-box; shapes override with path-precise testing).
Source§

fn focused<M>(self, binding: impl IntoFocusBinding<M>) -> AnyPiece

Bind this control’s keyboard focus to a signal (docs/focus.md), two-way like every other binding: native focus changes write the signal; writing the signal moves focus. Takes a Signal<bool> for one control, or (Signal<Option<K>>, K::Variant) binding one control of a group — writing false/None resigns focus (dismissing the soft keyboard on mobile). Focus applies asynchronously: a write is a request, resolved on the next turn, and the signal always ends up reflecting what the platform actually did.
Source§

fn context_menu(self, items: Vec<MenuEntry>) -> AnyPiece

Attach a context menu, shown with the platform’s native affordance on secondary-click (desktop) or long-press (mobile). Items are built with menu_item/sub_menu/menu_role/ menu_separator. Passing an empty Vec removes any menu.
Source§

fn on_drag(self, f: impl Fn(Drag) + 'static) -> AnyPiece

Fire on each phase of a drag over this piece.
Source§

fn background<M>(self, color: impl IntoReactive<Color, M>) -> AnyPiece

Fill the piece’s bounds with a solid color painted behind it — a message-bubble / card / badge surface. Accepts a constant Color, a Signal<Color>, or a Fn() -> Color; a reactive color repaints the surface when its source changes. Wraps the piece in a native container that carries the fill, so it composes with Self::corner_radius for a rounded colored surface and with Self::padding for interior inset.
Source§

fn corner_radius(self, radius: f64) -> AnyPiece

Round the piece’s corners to radius points, clipping its background and content to the rounded rectangle. Compose after Self::background for a rounded colored surface, or use alone to round a clipped child (e.g. an avatar image).
Source§

fn opacity<M>(self, opacity: impl IntoReactive<f64, M>) -> AnyPiece

Animate/set the piece’s opacity (0.0 transparent … 1.0 opaque). Wrapped in a native layer so it composes with .background; the change animates when made inside with_animation or under a .animation ancestor (§8.4).
Source§

fn transform<M>(self, t: impl IntoReactive<Transform, M>) -> AnyPiece

Apply an animatable Transform (translate/scale/rotate about the center) — the cheap movement/scaling channel that never triggers relayout (§8.4). Prefer this over .offset for animated motion.
Source§

fn scale<M>(self, factor: impl IntoReactive<f64, M>) -> AnyPiece

Uniformly scale the piece by factor about its center (animatable). Convenience over Self::transform.
Source§

fn rotation<M>(self, degrees: impl IntoReactive<f64, M>) -> AnyPiece

Rotate the piece by degrees clockwise about its center (animatable).
Source§

fn translation<Mx, My>( self, x: impl IntoReactive<f64, Mx>, y: impl IntoReactive<f64, My>, ) -> AnyPiece

Translate the piece by (x, y) points WITHOUT relayout (animatable) — the animation-friendly sibling of .offset.
Source§

fn animation(self, anim: AnimSpec) -> AnyPiece

Attach an implicit animation (§8.4): changes to this piece’s — and its descendants’ — animatable properties animate with anim even outside a with_animation. SwiftUI’s .animation. The ambient with_animation takes precedence when both apply.
Source§

fn modifier(self, m: impl Modifier) -> AnyPiece

Apply a Modifier — or, via the blanket impl, a plain FnOnce(AnyPiece) -> AnyPiece closure — to this piece. Pure composition: content.modifier(m) == m.apply(content.any()).
Source§

fn overlay(self, over: impl Piece) -> AnyPiece

Draw over on top of this piece, centered, WITHOUT affecting layout size — a badge / annotation overlay. self is the sizing content (bottom of the z-order); over is proposed self’s size and drawn on top. For an explicit alignment use Self::overlay_aligned; for a stack that sizes to the UNION of its children use zstack.
Source§

fn overlay_aligned(self, align: Alignment, over: impl Piece) -> AnyPiece

Self::overlay with an explicit Alignment for the annotation (e.g. a corner badge with Alignment::TopTrailing).
Source§

fn grow(self) -> AnyPiece

Expand to fill the available space on both axes (a filling pane / card that stretches to its container). Wraps the piece in a layout-only node carrying grow [Flex] — the stack offers it the space and it fills; no native backing, so this is a pure layout change.
Source§

fn grow_w(self) -> AnyPiece

Expand to fill the available horizontal space.
Source§

fn grow_h(self) -> AnyPiece

Expand to fill the available vertical space.
Source§

fn grid_span(self, n: usize) -> AnyPiece

Span n columns (n ≥ 1) of the enclosing grid (docs/grid.md). Grid modifiers set facts on the node the grid sees: apply them LAST (outermost), like .grow_w() — an outer wrapper would hide the facts from the grid.
Source§

fn grid_align(self, a: Alignment) -> AnyPiece

Override this cell’s alignment within its cell rect of the enclosing grid (docs/grid.md). Apply LAST (outermost), like Self::grid_span.
Source§

fn defers_system_gestures(self, edges: Edges) -> AnyPiece

While this subtree is mounted, ask the OS to require a second swipe for its edge gestures on edges (docs/cover.md) — the SwiftUI defersSystemGestures(on:) analogue. Put it on a game or drawing surface whose touches run to the screen edge, so a swipe up from the bottom doesn’t leave the app. iOS defers the chosen edges’ system gestures; Android enters swipe-to-reveal immersive mode while any subtree requests deferral; desktop backends no-op.
Source§

fn interactive_dismiss_disabled(self) -> AnyPiece

While this subtree is mounted, the enclosing cover (or other modal surface) must not be dismissed interactively — the SwiftUI interactiveDismissDisabled() analogue (docs/cover.md). System back / sheet gestures are ignored; only programmatic writes (an explicit close control) dismiss it.
Source§

fn any(self) -> AnyPiece

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> ErasedDestructor for T
where T: 'static,

Day API ↩ Guides· daybrite.dev