pub struct BuildCx<'a> { /* private fields */ }Expand description
What a View uses to describe itself during a build: theme access,
interaction state, child building, layout boxes, painting and behavior.
Implementations§
Source§impl<'a> BuildCx<'a>
impl<'a> BuildCx<'a>
Sourcepub fn foreground(&self) -> Option<Color>
pub fn foreground(&self) -> Option<Color>
The text color of the view being built, if a view around it set one with
Self::with_foreground. Colors do not cascade by themselves, so this is how
a Kbd inside a filled button reads as part of the button.
Sourcepub fn with_foreground<R>(
&mut self,
color: Color,
build: impl FnOnce(&mut Self) -> R,
) -> R
pub fn with_foreground<R>( &mut self, color: Color, build: impl FnOnce(&mut Self) -> R, ) -> R
Builds what build builds with color as its Self::foreground. Layers opened
inside it start without one, since they are not painted over this view.
Sourcepub fn ui_waker(&self) -> UiWaker
pub fn ui_waker(&self) -> UiWaker
A handle that asks for a rebuild from another thread; see UiWaker.
Sourcepub fn theme_state(&self) -> State<Theme>
pub fn theme_state(&self) -> State<Theme>
The app-wide theme as state: set it to switch themes at runtime.
Sourcepub fn links(&self) -> Links
pub fn links(&self) -> Links
Opens addresses: in the browser it navigates, on the desktop the system’s
browser opens them. #name scrolls to the anchor of that name instead.
Sourcepub fn full_screen(&self) -> FullScreen
pub fn full_screen(&self) -> FullScreen
Puts the app in full screen and takes it out: the page’s full screen in the browser, a borderless full screen window on the desktop.
Sourcepub fn anchor(&mut self, node: NodeId, name: &str, offset: f32)
pub fn anchor(&mut self, node: NodeId, name: &str, offset: f32)
Marks the node as the place #name links scroll to, landing offset pixels
below the top of its scroll container (the height of a bar pinned over it).
Sourcepub fn on_appear(&mut self, node: NodeId, handler: Rc<dyn Fn()>)
pub fn on_appear(&mut self, node: NodeId, handler: Rc<dyn Fn()>)
Calls handler once, after the first frame in which the node shows inside its
scroll container: counters that start when they are seen, content loaded when
it is reached. The handler runs outside the build, so it may set state.
Sourcepub fn time_linked(&mut self, node: NodeId, link: TimeLink)
pub fn time_linked(&mut self, node: NodeId, link: TimeLink)
Paints the node and its subtree with the effect link gives for the clock and
the node’s frame, on every frame while it shows: a strip that keeps moving, a
gentle float. It neither rebuilds nor lays out. With reduced motion the clock
stands at zero.
Sourcepub fn scroll_progress(
&mut self,
node: NodeId,
range: ScrollRange,
progress: Rc<Cell<f32>>,
)
pub fn scroll_progress( &mut self, node: NodeId, range: ScrollRange, progress: Rc<Cell<f32>>, )
Writes into progress, before each paint of the node, how far the scroll is along
range from 0 to 1, for drawing that follows the scroll itself, such as a
crate::QuadField. Effects that only move, fade or scale use
Self::scroll_linked instead.
Sourcepub fn file_picker(&self) -> FilePicker
pub fn file_picker(&self) -> FilePicker
The system’s chooser of files.
Sourcepub fn files_over(&self) -> bool
pub fn files_over(&self) -> bool
Whether files are being dragged over the window, for places that take them to show it.
Sourcepub fn on_file_drop(
&mut self,
node: NodeId,
handler: Rc<dyn Fn(Vec<PickedFile>)>,
)
pub fn on_file_drop( &mut self, node: NodeId, handler: Rc<dyn Fn(Vec<PickedFile>)>, )
Makes the node take files dropped on it.
Sourcepub fn is_hovered(&self) -> bool
pub fn is_hovered(&self) -> bool
The pointer is over this view’s interactive element.
Sourcepub fn is_hover_within(&self) -> bool
pub fn is_hover_within(&self) -> bool
The pointer is over this view or over any interactive element inside it.
Sourcepub fn use_state<T: 'static>(&mut self, init: impl FnOnce() -> T) -> State<T>
pub fn use_state<T: 'static>(&mut self, init: impl FnOnce() -> T) -> State<T>
State owned by this view instance that survives rebuilds, like SwiftUI’s
@State. Call it unconditionally and in the same order on every build;
init runs only the first time. The state is dropped when the view stops
being built.
Sourcepub fn is_pressed(&self) -> bool
pub fn is_pressed(&self) -> bool
The primary button went down on this view and has not been released.
Sourcepub fn is_focused(&self) -> bool
pub fn is_focused(&self) -> bool
Keyboard focus is on this view.
Sourcepub fn is_focus_visible(&self) -> bool
pub fn is_focus_visible(&self) -> bool
Focus is on this view and came from the keyboard.
Sourcepub fn child(&mut self, view: &dyn View) -> NodeId
pub fn child(&mut self, view: &dyn View) -> NodeId
Builds a child view; its identity comes from its position among this view’s children.
Sourcepub fn keyed_child(&mut self, key: u64, view: &dyn View) -> NodeId
pub fn keyed_child(&mut self, key: u64, view: &dyn View) -> NodeId
Builds a child with an explicit key, so it keeps its hover/focus state when siblings are inserted or removed (use it for dynamic lists).
Sourcepub fn children(&mut self, seq: &dyn ViewSeq) -> Vec<NodeId>
pub fn children(&mut self, seq: &dyn ViewSeq) -> Vec<NodeId>
Builds every view of a sequence as children.
Sourcepub fn container(
&mut self,
style: LayoutStyle,
children: &[NodeId],
paint: Paint,
) -> NodeId
pub fn container( &mut self, style: LayoutStyle, children: &[NodeId], paint: Paint, ) -> NodeId
Creates a box that lays out children and paints paint behind them.
Sourcepub fn text(
&mut self,
text: &str,
attrs: &TextAttrs,
color: Color,
style: LayoutStyle,
) -> NodeId
pub fn text( &mut self, text: &str, attrs: &TextAttrs, color: Color, style: LayoutStyle, ) -> NodeId
Creates a text leaf that wraps to the width its parent offers.
Sourcepub fn text_truncated(
&mut self,
text: &str,
attrs: &TextAttrs,
color: Color,
style: LayoutStyle,
) -> NodeId
pub fn text_truncated( &mut self, text: &str, attrs: &TextAttrs, color: Color, style: LayoutStyle, ) -> NodeId
Like Self::text, on one line that ends with … when it does not fit.
Screen readers still get the whole text.
Sourcepub fn measure_text(&mut self, text: &str, attrs: &TextAttrs) -> Size
pub fn measure_text(&mut self, text: &str, attrs: &TextAttrs) -> Size
Measures text without creating a node, e.g. to place a caret.
Sourcepub fn on_click(&mut self, node: NodeId, handler: Rc<dyn Fn()>)
pub fn on_click(&mut self, node: NodeId, handler: Rc<dyn Fn()>)
Calls handler when the node is clicked, or activated with Enter/Space while focused.
Sourcepub fn semantics(&mut self, node: NodeId, semantics: Semantics)
pub fn semantics(&mut self, node: NodeId, semantics: Semantics)
Describes the node to screen readers; see Semantics.
Sourcepub fn focusable(&mut self, node: NodeId, corner_radius: f32)
pub fn focusable(&mut self, node: NodeId, corner_radius: f32)
Makes the node reachable with Tab; the focus ring uses corner_radius.
Sourcepub fn cursor(&mut self, node: NodeId, icon: CursorIcon)
pub fn cursor(&mut self, node: NodeId, icon: CursorIcon)
Shows icon while the pointer is over the node, and makes it hoverable.
Sourcepub fn on_key(&mut self, node: NodeId, handler: KeyHandler)
pub fn on_key(&mut self, node: NodeId, handler: KeyHandler)
Receives key presses while the node is focused (make it Self::focusable).
Return true from the handler to stop the default handling (Tab, Enter…).
Sourcepub fn on_drag(&mut self, node: NodeId, handler: DragHandler)
pub fn on_drag(&mut self, node: NodeId, handler: DragHandler)
Receives pointer drags that start on the node (sliders, splitters…).
Sourcepub fn scroll_offset(&self) -> Point
pub fn scroll_offset(&self) -> Point
This widget’s scroll offset (for its scrollable element), as of this build.
Sourcepub fn scroll_viewport(&self) -> Option<Size>
pub fn scroll_viewport(&self) -> Option<Size>
The visible size of this widget’s scroll container in the last layout,
or None before its first layout. Virtualized views use it with
Self::scroll_offset to build only the visible rows.
Sourcepub fn keyed_child_frame(&self, key: u64) -> Option<Size>
pub fn keyed_child_frame(&self, key: u64) -> Option<Size>
The size that the keyed child built with key ended up with in the last layout, if
it asked with Self::report_frame: for a view that places its children by how much
room each one took, before building them again.
Sourcepub fn set_scroll_offset(&mut self, offset: Point)
pub fn set_scroll_offset(&mut self, offset: Point)
Scrolls this widget’s scroll container to offset after the build
(clamped to its content), e.g. to keep a selected row visible.
Sourcepub fn now(&self) -> f64
pub fn now(&self) -> f64
Seconds since the app started, as of this build. Reading it does not
schedule anything; use Self::wake_at to be rebuilt later.
Sourcepub fn observe_activity(&mut self, observer: ActivityObserver)
pub fn observe_activity(&mut self, observer: ActivityObserver)
Watches the whole UI while this view is built: each painted frame, the pointer and clicks. For recording what happens, as a flight recorder does. It runs on every frame, so it has to be quick. The last call of a build wins.
Sourcepub fn ask_for_access_tree(&mut self)
pub fn ask_for_access_tree(&mut self)
Asks that Self::observe_activity be told what is on screen once this frame
is painted, as UiActivity::Described. Building that description costs more
than a frame should, so it comes only when asked for.
Sourcepub fn wake_at(&mut self, time: f64)
pub fn wake_at(&mut self, time: f64)
Asks for a rebuild at time (seconds, the same clock as Self::now):
toasts that expire, carousels that advance, spinners that turn.
Sourcepub fn motion(&mut self, node: NodeId, motion: Motion)
pub fn motion(&mut self, node: NodeId, motion: Motion)
Declares how node animates; see Motion. Call it in the same order on
every build, or give the motion a Motion::key.
Sourcepub fn animated<T: Animatable + 'static>(
&mut self,
target: T,
transition: Transition,
) -> T
pub fn animated<T: Animatable + 'static>( &mut self, target: T, transition: Transition, ) -> T
Sourcepub fn animated_numbers(
&mut self,
target: &[f64],
transition: Transition,
) -> Vec<f64>
pub fn animated_numbers( &mut self, target: &[f64], transition: Transition, ) -> Vec<f64>
Numbers that go from where they are to target along a tween, in full f64
precision: a counter, or a chart’s data changing. A new target while they move
starts from where they are, with no jump. When the count of numbers changes, or
under reduced motion, or for a spring, they take the target at once. Call it in
the same order on every build, as with Self::animated.
Sourcepub fn appear(&mut self, key: u64, transition: Transition) -> f32
pub fn appear(&mut self, key: u64, transition: Transition) -> f32
How far a view has appeared, from 0 to 1, since it was first built: for
content that draws itself in, such as a chart’s data. A new key starts it
over. Under reduced motion, or with motion off, it is 1 from the start. Call
it in the same order on every build, as with Self::animated.
Sourcepub fn reduced_motion(&self) -> bool
pub fn reduced_motion(&self) -> bool
The user asked for less motion, in the system settings or in the theme.
Motion already respects this; check it for motion you draw yourself.
Sourcepub fn measure_content(&mut self, node: NodeId)
pub fn measure_content(&mut self, node: NodeId)
Asks the runtime to report the size of the content of node, read back
with Self::measured_content on the next build.
Sourcepub fn report_frame(&mut self, node: NodeId)
pub fn report_frame(&mut self, node: NodeId)
Makes the size this node ended up with readable on the next build, with
Self::scroll_viewport, and builds again when it changes: for a view that
arranges itself by the room it got.
Sourcepub fn measured_content(&self) -> Option<Size>
pub fn measured_content(&self) -> Option<Size>
The size of the content of this view’s measured node in the last layout.
Sourcepub fn shortcut(&mut self, key: Key, command: bool, handler: Rc<dyn Fn()>)
pub fn shortcut(&mut self, key: Key, command: bool, handler: Rc<dyn Fn()>)
Registers an app-wide keyboard shortcut for as long as this view is built.
With command, it needs Cmd (macOS) or Ctrl held, e.g. Cmd/Ctrl+K.
Sourcepub fn scroll_with_widget(&mut self, node: NodeId)
pub fn scroll_with_widget(&mut self, node: NodeId)
Makes the wheel over node move what this widget scrolls, for a part that
follows the scroll without being inside it, such as frozen row names.
Sourcepub fn shortcut_with_shift(
&mut self,
key: Key,
command: bool,
handler: Rc<dyn Fn()>,
)
pub fn shortcut_with_shift( &mut self, key: Key, command: bool, handler: Rc<dyn Fn()>, )
Like Self::shortcut, for a key that also needs Shift. Register it before the
same key without Shift, which would otherwise answer first.
Calls handler with the pointer position on a secondary (right) click.
The same, also saying the element’s absolute frame, for a menu that depends on where inside the element it was opened.
Sourcepub fn on_pointer_move(
&mut self,
node: NodeId,
handler: Rc<dyn Fn(Point, Rect)>,
)
pub fn on_pointer_move( &mut self, node: NodeId, handler: Rc<dyn Fn(Point, Rect)>, )
Calls handler with the pointer position and the element’s absolute frame
whenever the pointer moves over it, for something that depends on where inside
it the pointer is. is_hover_within says when it left.
Sourcepub fn request_focus(&mut self)
pub fn request_focus(&mut self)
Moves keyboard focus to this widget’s focusable element after the build, scrolling the containers around it until it shows.
Sourcepub fn modifiers(&self) -> Rc<Cell<Modifiers>>
pub fn modifiers(&self) -> Rc<Cell<Modifiers>>
Keyboard modifiers as of the latest input event, readable from click handlers (e.g. Shift-click to extend a selection).
Sourcepub fn scrollable_virtual(&mut self, node: NodeId, horizontal: bool)
pub fn scrollable_virtual(&mut self, node: NodeId, horizontal: bool)
A scroll container in both directions whose content is rebuilt on every
scroll (see Self::scroll_viewport).
Sourcepub fn wheel_scrolls_sideways(&mut self, node: NodeId)
pub fn wheel_scrolls_sideways(&mut self, node: NodeId)
Makes a wheel that only turns up and down move this scroll container sideways, for a strip with nothing to scroll in the other direction.
Sourcepub fn scroll_horizontally(&mut self, node: NodeId)
pub fn scroll_horizontally(&mut self, node: NodeId)
Lets a scroll container (see Self::scrollable) scroll sideways too.
Sourcepub fn translate(&mut self, node: NodeId, offset: Point)
pub fn translate(&mut self, node: NodeId, offset: Point)
Moves the node’s children by offset when painting (e.g. a header that
follows a body’s horizontal scroll).
Sourcepub fn pin(&mut self, node: NodeId, top: f32)
pub fn pin(&mut self, node: NodeId, top: f32)
Keeps the node on screen while its parent scrolls past, top pixels below the
top of the scroll container around it, and lets it leave with the bottom of the
parent: CSS position: sticky. It is moved when frames are placed, so clicks,
focus and assistive technology find it where it shows. See crate::Sticky.
Sourcepub fn scroll_track(&mut self, node: NodeId, top: f32, length: f32)
pub fn scroll_track(&mut self, node: NodeId, top: f32, length: f32)
Marks the node as the track of a scroll scene: content pinned top pixels
below the top of the scroll container for length pixels of scrolling. Links
inside it that measure crate::ScrollRange::Scene run from 0 to 1 over that
length. See crate::ScrollScene.
Sourcepub fn scroll_linked(&mut self, node: NodeId, link: ScrollLink)
pub fn scroll_linked(&mut self, node: NodeId, link: ScrollLink)
Paints the node and its subtree with the effect link gives for the current
scroll position, worked out on every paint without rebuilding. Layout and hit
testing are unaffected. See crate::ScrollLinked.
Sourcepub fn on_pinch(&mut self, node: NodeId, handler: Rc<dyn Fn(f32)>)
pub fn on_pinch(&mut self, node: NodeId, handler: Rc<dyn Fn(f32)>)
Calls handler on a zoom gesture over the node, with how much larger was
asked for relative to now: 0.02 is 2% larger, and a negative value is smaller.
Sourcepub fn on_double_click(&mut self, node: NodeId, handler: Rc<dyn Fn()>)
pub fn on_double_click(&mut self, node: NodeId, handler: Rc<dyn Fn()>)
Calls handler on a double click on the node.
Sourcepub fn scrollable(&mut self, node: NodeId)
pub fn scrollable(&mut self, node: NodeId)
Makes the node a vertical scroll container: its children scroll with the
wheel or trackpad, are clipped, and a scrollbar shows while they move.
Give the node LayoutStyle::overflow_hidden so it does not grow to fit.
Sourcepub fn scrollbar_outside(&mut self, node: NodeId, by: f32)
pub fn scrollbar_outside(&mut self, node: NodeId, by: f32)
Puts this scroll container’s scrollbar by past its right edge, in the room around it.
Sourcepub fn overlay(
&mut self,
anchor: NodeId,
placement: Placement,
view: &dyn View,
on_dismiss: Option<Rc<dyn Fn()>>,
)
pub fn overlay( &mut self, anchor: NodeId, placement: Placement, view: &dyn View, on_dismiss: Option<Rc<dyn Fn()>>, )
Builds view as a floating layer above the rest of the UI, placed relative
to anchor. on_dismiss is called on a click outside the layer and its
anchor, or on Escape.
Sourcepub fn keyed_overlay(
&mut self,
key: u64,
anchor: NodeId,
placement: Placement,
view: &dyn View,
on_dismiss: Option<Rc<dyn Fn()>>,
)
pub fn keyed_overlay( &mut self, key: u64, anchor: NodeId, placement: Placement, view: &dyn View, on_dismiss: Option<Rc<dyn Fn()>>, )
Like Self::overlay, for a layer that must stay the same one when other
layers before it come and go. A plain overlay is told apart by its place among
them, so a new one before it makes it start over, and animate in again.
Sourcepub fn floating_overlay(
&mut self,
anchor: NodeId,
placement: Placement,
view: &dyn View,
)
pub fn floating_overlay( &mut self, anchor: NodeId, placement: Placement, view: &dyn View, )
Builds view as a layer that stays open beside the UI, like a chat in a
corner: it is under every menu and dialog, wherever it is built, keeps its state
when they open, and is not closed by a click outside it.