pub struct Label { /* private fields */ }Implementations§
Source§impl Label
impl Label
Sourcepub fn single_line(self) -> Self
pub fn single_line(self) -> Self
Keep plain text on one line. UIKit, Android, GTK, AppKit and DOM truncate with an ellipsis.
Sourcepub fn max_lines(self, lines: u32) -> Self
pub fn max_lines(self, lines: u32) -> Self
Limit a plain label to this many lines, truncating the last line on native Apple backends. Zero means unlimited. Rebuild the label to change its line limit.
Sourcepub fn font(self, f: Font) -> Self
pub fn font(self, f: Font) -> Self
The semantic text style (Font::Title, Font::Footnote, …) or a custom Font::System(pt).
Backends render it with the platform’s native style + accessibility text scaling.
Sourcepub fn font_scale(self, scale: f64) -> Self
pub fn font_scale(self, scale: f64) -> Self
Scale the resolved native font, preserving its semantic style and accessibility size. Applies to the label’s base font; explicit styled runs retain their own descriptors.
Sourcepub fn weight(self, w: FontWeight) -> Self
pub fn weight(self, w: FontWeight) -> Self
Override the font weight (e.g. FontWeight::Semibold). See also Label::bold.
Sourcepub fn secondary(self) -> Self
pub fn secondary(self) -> Self
De-emphasize the text: the platform’s secondary label color, whatever that is here
(secondaryLabelColor on Apple, ?android:textColorSecondary, a dim label on GTK).
Semantic rather than a literal grey, for the reason a literal grey cannot solve: one that reads well on white is wrong on black, so an app that hard-codes it gets a label that is either washed out or nearly invisible in the other appearance. This is what an empty state’s “nothing selected”, a hint under a field, or a caption should wear.
Sourcepub fn tabular(self) -> Self
pub fn tabular(self) -> Self
Ask for tabular (monospaced) figures, so a changing number stops changing width.
Pair it with Decorate::reserving for a readout beside a slider: reserving stops the box
resizing when the digit count changes, tabular stops the digits shifting inside it because
1 is narrower than 8. See day_spec::FontSpec::tabular.
Sourcepub fn monospace(self) -> Self
pub fn monospace(self) -> Self
Ask for the platform’s monospaced face at this style’s size, which is what inline code wants.
Sourcepub fn runs(self, runs: Vec<TextRun>) -> Self
pub fn runs(self, runs: Vec<TextRun>) -> Self
Style spans within this label’s text (docs/text-runs.md): one wrapping paragraph with emphasis, color, code or a link inside it, rather than several labels in a row.
Ranges are byte offsets into the label’s text, ascending and non-overlapping; text not
covered by a run draws with the label’s own font. Invalid runs are REJECTED at build time
with a warning and the label renders plain, because the alternative is eight different
wrong renderings (and a panic on the backends that slice str).
TextBuilder is the ergonomic way in; this is the direct one.
Sourcepub fn runs_from(self, b: TextBuilder) -> Self
pub fn runs_from(self, b: TextBuilder) -> Self
Take both the text and its runs from a TextBuilder, replacing whatever text the label
was built with. This is the intended entry point: the builder guarantees the ranges match
the string, which is the invariant hand-written runs get wrong.
Sourcepub fn align(self, align: TextAlign) -> Self
pub fn align(self, align: TextAlign) -> Self
Read the label’s text as inline Markdown (docs/markdown.md): **bold**, *italic*,
`code`, ~~strike~~ and [text](url) become styled runs, and the markers themselves
are stripped.
The parse happens at run time, on every change, so it works on a translated string chosen from the locale bundle, a value off the network, or text a user is typing, none of which a compile-time macro can see. The cost is a parse per update of a string that is a label’s worth of text.
label(tr("release-note")).markdown()
label(move || draft.get()).markdown() // live as the user typesUnrecognized markup stays literal, so a half-typed ** reads as two asterisks rather than
flickering. Block constructs (headings, lists, quotes) are not parsed: they are layout,
which is column/form/list.
Center (or trail) this label’s lines within its own width, for the short wrapped block
a welcome screen or an empty state uses. Only observable on a label that wraps, since a
single line already fills its box.
pub fn markdown(self) -> Self
Sourcepub fn on_link(self, f: impl Fn(&str) + 'static) -> Self
pub fn on_link(self, f: impl Fn(&str) + 'static) -> Self
Handle a tapped link run yourself instead of opening its target.
Without this, a #route target navigates in-app and other targets open in the platform’s
default handler, the same as the link piece. This handler overrides both behaviors;
call open_link to delegate targets you do not handle back to the default.
Activation is Cap::TextLinks, which is narrower than run rendering: on a backend
without it the link still draws, and nothing calls this (docs/text-runs.md).
Sourcepub fn color<M>(self, c: impl IntoReactive<Color, M>) -> Self
pub fn color<M>(self, c: impl IntoReactive<Color, M>) -> Self
The text color: a constant, a Signal<Color>, or a Fn() -> Color. A reactive
source recolors the native label when it changes (theme systems ride this).
Sourcepub fn preset(self, preset: &TextPreset) -> Self
pub fn preset(self, preset: &TextPreset) -> Self
Apply a named TextPreset: the font, weight, scale, emphasis and
color an app defined once (label(t).preset(&CAPTION)).
Trait Implementations§
Source§impl LabelBuilder for Label
impl LabelBuilder for Label
Source§fn single_line(self) -> Self
fn single_line(self) -> Self
Source§fn max_lines(self, lines: u32) -> Self
fn max_lines(self, lines: u32) -> Self
Source§fn font(self, f: Font) -> Self
fn font(self, f: Font) -> Self
Font::Title, Font::Footnote, …) or a custom Font::System(pt).
Backends render it with the platform’s native style + accessibility text scaling.Source§fn font_scale(self, scale: f64) -> Self
fn font_scale(self, scale: f64) -> Self
Source§fn weight(self, w: FontWeight) -> Self
fn weight(self, w: FontWeight) -> Self
FontWeight::Semibold). See also Label::bold.Source§fn secondary(self) -> Self
fn secondary(self) -> Self
secondaryLabelColor on Apple, ?android:textColorSecondary, a dim label on GTK). Read moreSource§fn tabular(self) -> Self
fn tabular(self) -> Self
Source§fn monospace(self) -> Self
fn monospace(self) -> Self
Source§fn runs(self, runs: Vec<TextRun>) -> Self
fn runs(self, runs: Vec<TextRun>) -> Self
Source§fn runs_from(self, b: TextBuilder) -> Self
fn runs_from(self, b: TextBuilder) -> Self
TextBuilder, replacing whatever text the label
was built with. This is the intended entry point: the builder guarantees the ranges match
the string, which is the invariant hand-written runs get wrong.Source§fn align(self, align: TextAlign) -> Self
fn align(self, align: TextAlign) -> Self
**bold**, *italic*,
`code`, ~~strike~~ and [text](url) become styled runs, and the markers themselves
are stripped. Read morefn markdown(self) -> Self
Source§fn on_link(self, f: impl Fn(&str) + 'static) -> Self
fn on_link(self, f: impl Fn(&str) + 'static) -> Self
Source§fn color<M>(self, c: impl IntoReactive<Color, M>) -> Self
fn color<M>(self, c: impl IntoReactive<Color, M>) -> Self
Signal<Color>, or a Fn() -> Color. A reactive
source recolors the native label when it changes (theme systems ride this).Source§fn preset(self, preset: &TextPreset) -> Self
fn preset(self, preset: &TextPreset) -> Self
TextPreset: the font, weight, scale, emphasis and
color an app defined once (label(t).preset(&CAPTION)).Auto Trait Implementations§
impl !RefUnwindSafe for Label
impl !Send for Label
impl !Sync for Label
impl !UnwindSafe for Label
impl Freeze for Label
impl Unpin for Label
impl UnsafeUnpin for Label
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<P> Decorate for Pwhere
P: Piece,
impl<P> Decorate for Pwhere
P: Piece,
Source§fn id(self, id: ElementId) -> Decorated<Self>
fn id(self, id: ElementId) -> Decorated<Self>
Source§fn wrapper_id(self, id: ElementId) -> Decorated<Self>
fn wrapper_id(self, id: ElementId) -> Decorated<Self>
id.Source§fn apply_if(
self,
cond: bool,
f: impl FnOnce(Decorated<Self>) -> Decorated<Self>,
) -> Decorated<Self>
fn apply_if( self, cond: bool, f: impl FnOnce(Decorated<Self>) -> Decorated<Self>, ) -> Decorated<Self>
f to the chain when cond holds, else continue unchanged
(see Decorated::apply_if): nav(sel).apply_if(!primary, |n| n.local()). The
closure receives the decorated piece, so forwarded builder methods and modifiers both
chain inside it.Source§fn apply_some<T>(
self,
value: Option<T>,
f: impl FnOnce(Decorated<Self>, T) -> Decorated<Self>,
) -> Decorated<Self>
fn apply_some<T>( self, value: Option<T>, f: impl FnOnce(Decorated<Self>, T) -> Decorated<Self>, ) -> Decorated<Self>
f with the value when there is one, else continue unchanged
(see Decorated::apply_some): canvas(draw).apply_some(id, |c, id| c.id(id)).Source§fn id_of(self, id: impl Fn() -> ElementId + 'static) -> Decorated<Self>
fn id_of(self, id: impl Fn() -> ElementId + 'static) -> Decorated<Self>
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 || day_core::id!(row_remove, slot.key())).Source§fn tweak(self, f: impl FnOnce(RNode) + 'static) -> Decorated<Self>
fn tweak(self, f: impl FnOnce(RNode) + 'static) -> Decorated<Self>
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. Read moreSource§fn selectable(self) -> Decorated<Self>
fn selectable(self) -> Decorated<Self>
Source§fn cursor<M>(self, cursor: impl IntoReactive<Cursor, M>) -> Decorated<Self>
fn cursor<M>(self, cursor: impl IntoReactive<Cursor, M>) -> Decorated<Self>
Cursor constant, a Signal<Cursor>, or a closure, so a canvas tool or a busy state
moves the shape without rebuilding the piece. The nearest ancestor’s cursor wins, and
Cursor::Default releases the piece back to the platform. capability(Cap::Cursor)
says whether this toolkit draws the requested shapes, a nearest neighbor, or nothing;
a touch-only host never shows one, which is correct rather than a failure.Source§fn window_drag_region(self) -> Decorated<Self>
fn window_drag_region(self) -> Decorated<Self>
WindowChrome::Overlay or
WindowChrome::Frameless window needs. The piece’s own background starts the drag,
with the platform’s snapping and tiling; buttons and fields inside it keep their clicks;
a double click does what the user’s title-bar setting says (zoom, minimize, nothing).
capability(Cap::DragRegion); on a phone the piece is an ordinary view.Source§fn native_ref(self, r: &NativeRef) -> Decorated<Self>
fn native_ref(self, r: &NativeRef) -> Decorated<Self>
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.fn padding(self, insets: impl IntoInsets) -> Decorated<Self>
Source§fn max_width(self, max: f64) -> Decorated<Self>
fn max_width(self, max: f64) -> Decorated<Self>
max points: the child is never PROPOSED more, so text
wraps inside the cap (chat bubbles, readable columns) while narrower content hugs.Source§fn reserving(self, sample: impl Into<String>) -> Decorated<Self>
fn reserving(self, sample: impl Into<String>) -> Decorated<Self>
sample needs, so this piece’s size stops changing with its
content. Read morefn frame(self, width: f64, height: f64) -> Decorated<Self>
Source§fn width(self, width: f64) -> Decorated<Self>
fn width(self, width: f64) -> Decorated<Self>
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) -> Decorated<Self>
fn height(self, height: f64) -> Decorated<Self>
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.fn a11y( self, f: impl FnOnce(A11yBuilder) -> A11yBuilder + 'static, ) -> Decorated<Self>
Source§fn on_tap(self, f: impl Fn() + 'static) -> Decorated<Self>
fn on_tap(self, f: impl Fn() + 'static) -> Decorated<Self>
Source§fn focused<M>(self, binding: impl IntoFocusBinding<M>) -> Decorated<Self>
fn focused<M>(self, binding: impl IntoFocusBinding<M>) -> Decorated<Self>
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 on_key(self, f: impl Fn(&KeyEvent) + 'static) -> Decorated<Self>
fn on_key(self, f: impl Fn(&KeyEvent) + 'static) -> Decorated<Self>
Decorate::focused or with a
piece the user can click into: a canvas takes focus on a press, and only the focused
piece hears the keys, so a nudge handler can never fire while a text field, a list or a
sidebar is the one being typed into. Read moreSource§fn toolbar<M>(self, content: impl ToolbarContent<M>) -> Decorated<Self>
fn toolbar<M>(self, content: impl ToolbarContent<M>) -> Decorated<Self>
Source§fn searchable(self, search: Search) -> Decorated<Self>
fn searchable(self, search: Search) -> Decorated<Self>
UISearchController), its app bar on Android. It shows while this page does, and
its text is the app’s query both ways. For a search the server runs, act on
crate::Search::on_submit; for a local filter, read the query. Declare it on a
nav_stack destination, as .toolbar(…) is declared; a whole navigation surface takes
crate::Nav::searchable instead.Source§fn focusable(self) -> Decorated<Self>
fn focusable(self) -> Decorated<Self>
.focused(…), and hears the arrows through .on_key(…) while focused. A composed
list column is the motivating case (docs/navigation.md). On a backend without the
set_focusable duty the piece renders normally and never takes focus.Source§fn drag_source(
self,
source: impl Fn(Point) -> Option<Offer> + 'static,
) -> Decorated<Self>
fn drag_source( self, source: impl Fn(Point) -> Option<Offer> + 'static, ) -> Decorated<Self>
menu_item/sub_menu/menu_role/
menu_separator. Passing an empty Vec removes any menu.fn drop_target(self, target: Target) -> Decorated<Self>
menu_item/sub_menu entries as everywhere else. Takes a fixed list, or a closure
built when the menu is summoned (“Dynamic context menus”): with no argument, or with the
summon point in this piece’s own coordinates, so a canvas can select what is under the
pointer and offer commands for that selection. An empty result shows nothing. Read morefn on_drag(self, f: impl Fn(Drag) + 'static) -> Decorated<Self>
Source§fn on_pinch(self, f: impl Fn(Pinch) + 'static) -> Decorated<Self>
fn on_pinch(self, f: impl Fn(Pinch) + 'static) -> Decorated<Self>
Source§fn on_pan(self, f: impl Fn(Pan) + 'static) -> Decorated<Self>
fn on_pan(self, f: impl Fn(Pan) + 'static) -> Decorated<Self>
delta is incremental; apply it
as it arrives.Source§fn on_hover(self, f: impl Fn(Option<Point>) + 'static) -> Decorated<Self>
fn on_hover(self, f: impl Fn(Option<Point>) + 'static) -> Decorated<Self>
Some(point) in its own coordinates while inside,
None when it leaves (docs/canvas.md “Interaction”). Pointer-only; wire on_tap_at
alongside it so a touch-only device can reach the same thing.Source§fn card(self) -> Decorated<Self>
fn card(self) -> Decorated<Self>
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.
The platform’s card around this piece: the grouped-content surface with rounded
corners and a Space::M inset (see Decorated::card).fn background<M>(self, color: impl IntoReactive<Color, M>) -> Decorated<Self>
Source§fn corner_radius(self, radius: f64) -> Decorated<Self>
fn corner_radius(self, radius: f64) -> Decorated<Self>
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>) -> Decorated<Self>
fn opacity<M>(self, opacity: impl IntoReactive<f64, M>) -> Decorated<Self>
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>) -> Decorated<Self>
fn transform<M>(self, t: impl IntoReactive<Transform, M>) -> Decorated<Self>
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>) -> Decorated<Self>
fn scale<M>(self, factor: impl IntoReactive<f64, M>) -> Decorated<Self>
factor about its center (animatable). Convenience over
Self::transform.Source§fn rotation<M>(self, degrees: impl IntoReactive<f64, M>) -> Decorated<Self>
fn rotation<M>(self, degrees: impl IntoReactive<f64, M>) -> Decorated<Self>
degrees clockwise about its center (animatable).Source§fn translation<Mx, My>(
self,
x: impl IntoReactive<f64, Mx>,
y: impl IntoReactive<f64, My>,
) -> Decorated<Self>
fn translation<Mx, My>( self, x: impl IntoReactive<f64, Mx>, y: impl IntoReactive<f64, My>, ) -> Decorated<Self>
x, y) points without relayout (animatable): the
animation-friendly sibling of .offset.Source§fn animation(self, anim: AnimSpec) -> Decorated<Self>
fn animation(self, anim: AnimSpec) -> Decorated<Self>
anim even outside a with_animation. SwiftUI’s
.animation. The ambient with_animation takes precedence when both apply.Source§fn overlay(self, over: impl Piece) -> Decorated<Self>
fn overlay(self, over: impl Piece) -> Decorated<Self>
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) -> Decorated<Self>
fn overlay_aligned(self, align: Alignment, over: impl Piece) -> Decorated<Self>
Self::overlay with an explicit Alignment for the annotation (e.g. a corner badge with
Alignment::TopTrailing).Source§fn aspect_ratio(self, ratio: f64) -> Decorated<Self>
fn aspect_ratio(self, ratio: f64) -> Decorated<Self>
width / height ratio: the largest box of that shape which
fits whatever the parent offers (SwiftUI’s .aspectRatio(_:contentMode: .fit)). Read moreSource§fn grow(self) -> Decorated<Self>
fn grow(self) -> Decorated<Self>
Flex: the stack
offers it the space and it fills; no native backing, so this is a pure layout change.Source§fn grid_align(self, a: Alignment) -> Decorated<Self>
fn grid_align(self, a: Alignment) -> Decorated<Self>
grid
(docs/grid.md). Apply last (outermost), like Decorated::grid_span.Source§fn defers_system_gestures(self, edges: Edges) -> Decorated<Self>
fn defers_system_gestures(self, edges: Edges) -> Decorated<Self>
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.hidden is true, hide the system status bar, the
SwiftUI statusBarHidden(_:) analogue (docs/cover.md). hidden is a constant, a
Signal, or a closure, so a setting can turn it on and off in place. Put it on a page
that wants the whole screen (a reader, a game, a photo viewer); the bar returns when
the page unmounts. Any mounted request that answers true hides the bar. iOS, Android and
HarmonyOS hide it (Cap::StatusBarHidden); desktop and web have none and ignore it.Source§fn interactive_dismiss_disabled(self) -> Decorated<Self>
fn interactive_dismiss_disabled(self) -> Decorated<Self>
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.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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