Skip to main content

TextItem

Struct TextItem 

Source
pub struct TextItem { /* private fields */ }
Expand description

Text in a local-coord rectangle, with optional alignment and rotation.

Text wraps within the local_bounds rectangle; the caller is responsible for sizing the rect so all text is visible. Content is either a static localized string (see TextItem::new) or a reactive Signal<String> (see TextItem::with_signal_text). Both sources trigger a repaint on change without rebuilding the scene.

Implementations§

Source§

impl TextItem

Source

pub fn new(text: impl Into<LocalizedString>, local_bounds: Rect) -> Self

A static-text item in local coordinates. The text is resolved eagerly via LocalizedString::resolve_now at construction; locale changes rebuild the composite parent, which re-creates this TextItem with a fresh translation.

Source

pub fn with_signal_text(text: Signal<String>, local_bounds: Rect) -> Self

A text item whose content is driven by a Signal<String>. register_bindings ties the signal to the SceneView at BindingLevel::RepaintOnly so changes dirty paint and the next walk reads the current value.

Source

pub fn draggable(self, draggable: bool) -> Self

Opt the text into drag-to-move.

Source

pub fn color(self, color: impl Into<ColorProp>) -> Self

Override the foreground colour. Accepts a plain [Color], a theme role, a Signal<Color>, or a Signal<Role> — resolved against the active theme at paint time.

Source

pub fn align(self, align: TextAlign) -> Self

Horizontal alignment within local_bounds. Default TextAlign::Leading. Needs a text backend to measure the text width; a headless canvas with no backend renders leading-aligned.

Source

pub fn rotation(self, radians: f32) -> Self

Rotate the text about the item’s centre by radians. Default 0.0 (upright). Pair with Signal::animate_to on a driving signal for animated rotation, or set a fixed angle for a vertical axis title.

Source

pub fn follow_text_scale(self, follow: bool) -> Self

Opt this text into the global accessibility text scale, so it grows with the app-wide “grow all text” setting. Off by default — the scene’s own pan/zoom usually governs scene text size.

Source

pub fn label(self, label: impl Into<LocalizedString>) -> Self

Override the AT label (defaults to the current text content).

Source

pub fn measure(&self, backend: &mut dyn TextBackend) -> Size

Measure the current text’s single-line intrinsic size against backend at the authored TextStyle. Lets a consumer size a slot around a label (axis labels, value tags) before placing it. Does not apply the global text scale — measure at the authored size.

Source

pub fn access_label(self, label: impl Into<LocalizedString>) -> Self

Override the AT name announced for this item. Accepts anything convertible into LocalizedString — most commonly tr!(...) for translated labels, or any plain string (which auto-converts via From<String>).

Source

pub fn access_description(self, description: impl Into<LocalizedString>) -> Self

Long-form context appended to the item’s announcement.

Source

pub fn access_role(self, role: Role) -> Self

Override the AccessKit role for this item.

Source

pub fn access_hidden(self, hidden: bool) -> Self

Hide this item from the AT tree.

Source

pub fn access_subtree(self, mode: AccessSubtreeMode) -> Self

Set the AT subtree mode. Merge collapses descendants into this item’s AT node; Exclude prunes them; the default Inherit lets them emit normally.

Source

pub fn access_merge_subtree(self) -> Self

Convenience: collapse all descendants into this item’s AT node so the subtree reads as one element.

Source

pub fn access_exclude_subtree(self) -> Self

Convenience: prune all descendants from the AT tree.

Source

pub fn access_value(self, value: impl Into<LocalizedString>) -> Self

Announce a string value for this item (e.g. a formatted data reading like "42 %"). Mirrors the widget-tier .access_value.

Source

pub fn access_numeric_value(self, value: f64) -> Self

Announce a numeric value for this item, for slider/gauge-like data marks whose magnitude assistive tech should describe. Pair with access_numeric_range / access_numeric_step for full range semantics.

Source

pub fn access_numeric_range(self, min: f64, max: f64) -> Self

Announce the numeric min/max bounds for this item.

Source

pub fn access_numeric_step(self, step: f64) -> Self

Announce the numeric step (per-arrow increment) for this item.

Trait Implementations§

Source§

impl Debug for TextItem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl SceneItem for TextItem

Source§

fn local_bounds(&self) -> Rect

AABB in local item coordinates (origin at the item’s anchor). The Scene composes this with the item’s scene_transform to compute its scene-space AABB for the spatial index.
Source§

fn set_local_bounds(&mut self, bounds: Rect)

Write back new bounds. Called by Scene::set_local_bounds when the bounds change. Implementations update their stored bounds field; geometry-bearing items (e.g. crate::PathItem) must keep their geometry consistent with the new bounds.
Source§

fn paint(&self, canvas: &mut Canvas, ctx: &SceneItemPaintContext<'_>)

Paint the item into the canvas. The canvas already has this item’s scene_transform (parent chain × view) pushed, so coordinates are in local item space — (0, 0) is the item’s anchor. Read more
Source§

fn set_fill(&mut self, fill: Option<ColorProp>) -> bool

Replace the primary fill colour, returning true if this item kind has a fill slot that accepted the change. Backs SceneModel::set_item_fill / clear_item_fill. Rectangles, paths, and groups set their fill; text items map it onto their foreground colour (so a None is rejected — text always has a colour); image items have no fill and return false. Default: no-op.
Source§

fn label(&self) -> Option<String>

Optional human-readable label, surfaced in debug introspection and used by the default SceneItem::accessibility impl as the AT name when an item author hasn’t overridden it via the per-item .access_label(...) chain.
Source§

fn initial_flags(&self) -> ItemFlags

The flags this item should carry into the Scene at insert time. Default: ItemFlags::default() — visible, enabled, selectable. Built-ins read their accumulated builder state (e.g. .draggable(true) flips IS_DRAGGABLE); custom items override this to opt into hover acceptance, focus, clipping, or IGNORES_TRANSFORMATIONS. Read more
Source§

fn access_subtree_mode(&self) -> AccessSubtreeMode

AT subtree treatment for descendants. Read more
Source§

fn accessibility( &self, builder: &mut AccessNodeBuilder, _ctx: &SceneItemA11yContext, )

Populate the AccessKit node for this item. Default: role [Role::GraphicsObject] plus the SceneItem::label as the AT name if set. The per-item .access_* builder chain layers overrides on top of whatever this method writes.
Source§

fn register_bindings(&self, ctx: &mut BuildContext<'_>, view_id: WidgetId)

Register reactive bindings the item depends on. Called once per SceneView::build for every item in the scene, with the SceneView’s WidgetId as view_id. Items with signal-bound state bind their signals here at the appropriate BindingLevel.
Source§

fn set_stroke(&mut self, stroke: Option<(ColorProp, StrokeStyle)>) -> bool

Replace the stroke (colour + [StrokeStyle]), returning true if this item kind has a stroke slot that accepted the change. Backs SceneModel::set_item_stroke / clear_item_stroke. Rectangles, paths, and groups accept it; text and image items return false. Default: no-op.
Source§

fn shape_contains(&self, local_pt: Point) -> bool

Exact-shape hit-test in local coordinates. Default: AABB containment via SceneItem::local_bounds. Path-based items override this to do per-segment distance checks so users can click along a stroke even when the AABB is huge.
Source§

fn clone_shape_test(&self) -> Box<dyn Fn(Point, f32) -> bool + 'static>

Produce a stand-alone Fn(Point, f32) -> bool that closes over whatever state this item needs to answer shape_contains without retaining a borrow on self. The SceneView snapshots one of these for every item at layout time and consults it on every pointer event — direct calls to shape_contains(&self, ...) can’t be cached because &dyn SceneItem is not Clone. Read more
Source§

fn thumbnail_color(&self) -> Color

Dominant color to draw as the item’s representation in minimap-style thumbnails. Default: an opaque mid-grey, which gives a recognisable but neutral marker for any item. Built-in items override: RectItem returns its fill, PathItem returns stroke or fill, ImageItem returns the image’s dominant tint placeholder. Read more
Source§

fn cache_mode(&self) -> CacheMode

Per-item paint caching strategy. Default CacheMode::None: the item’s paint runs every frame. Read more

Auto Trait Implementations§

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more