Skip to main content

BuildCx

Struct BuildCx 

Source
pub struct BuildCx<'a> { /* private fields */ }
Expand description

Per-frame, read-only context for App::build.

The runner snapshots the app’s crate::Theme before calling build and exposes it through cx.theme() / cx.palette() so app code can branch on the active palette (a custom widget that picks between two non-token colors based on dark vs. light, for instance). BuildCx is the explicit handle for this — token references inside widgets resolve through the palette automatically and don’t need it.

Future fields like viewport metrics or frame phase will live here so the API stays additive: adding a new accessor on BuildCx doesn’t break apps that ignore the context.

Implementations§

Source§

impl<'a> BuildCx<'a>

Source

pub fn new(theme: &'a Theme) -> Self

Construct a BuildCx borrowing the supplied theme. Hosts call this once per frame after App::theme and before App::build. Hosts that own a crate::state::UiState should chain Self::with_ui_state so the app can read interaction state (hover) during build via Self::hovered_key / Self::is_hovering_within.

Source

pub fn with_ui_state(self, ui_state: &'a UiState) -> Self

Attach the runtime’s crate::state::UiState so build-time accessors (hovered_key, is_hovering_within) can answer. When omitted, those accessors return None / false — useful for headless rendering paths that don’t track interaction state.

Source

pub fn with_diagnostics(self, diagnostics: &'a HostDiagnostics) -> Self

Attach a HostDiagnostics snapshot for this frame. Hosts call this when they want apps to surface debug overlays (e.g. the showcase status block); apps that don’t read diagnostics() pay nothing for it. Headless render paths leave it None.

Source

pub fn with_viewport(self, width: f32, height: f32) -> Self

Attach the logical-pixel viewport size for this frame. Hosts chain this so apps can branch on viewport metrics during build (responsive layout, phone-vs-desktop splits) without threading surface size through their own state. Headless render paths without a meaningful viewport leave it unset.

Source

pub fn with_safe_area(self, sides: Sides) -> Self

Attach the host’s reported safe-area insets in logical pixels. Hosts chain this when platform chrome (on-screen keyboard, notch, status bar, home indicator) is obscuring some band of the viewport. Apps read it via Self::safe_area / Self::safe_area_bottom and inset their interactive content accordingly. Hosts that don’t report safe-area metrics omit this; apps see Sides::zero() from the read accessors.

Source

pub fn diagnostics(&self) -> Option<&HostDiagnostics>

Per-frame diagnostic snapshot from the host (backend, frame cadence, trigger reason, etc.), or None when the host did not attach one. Apps display this in optional debug overlays.

Source

pub fn theme(&self) -> &Theme

The active runtime theme for this frame.

Source

pub fn palette(&self) -> &Palette

Shorthand for self.theme().palette().

Source

pub fn viewport(&self) -> Option<(f32, f32)>

Logical-pixel viewport (width, height) the host attached for this frame, or None for headless render paths. Apps use this to branch layout on viewport metrics — see Self::viewport_below for the common phone-vs-desktop breakpoint case.

Source

pub fn viewport_width(&self) -> Option<f32>

Logical-pixel viewport width the host attached for this frame, or None when no viewport is available. Convenience for the common single-axis branch (cx.viewport_width().map_or(false, |w| w < 600.0)).

Source

pub fn viewport_height(&self) -> Option<f32>

Logical-pixel viewport height the host attached for this frame, or None when no viewport is available.

Source

pub fn viewport_below(&self, threshold: f32) -> bool

True iff the attached viewport’s width is strictly less than threshold logical pixels. Returns false when no viewport is attached so headless / desktop-default paths fall through to the wider branch — apps that want the opposite default can match on Self::viewport_width directly.

Use for the common breakpoint split:

if cx.viewport_below(600.0) {
    phone_layout()
} else {
    desktop_layout()
}
Source

pub fn safe_area(&self) -> Sides

Logical-pixel safe-area insets the host reports for this frame (Sides::zero() when nothing was attached). Today this is populated only by damascene-web when the on-screen keyboard shrinks the visual viewport — bottom carries the keyboard height; future native mobile hosts will additionally populate top for status-bar / notch and bottom for home-indicator.

Apps inset their root layout (or just the focused-input region) by these amounts so interactive content doesn’t sit underneath platform chrome. The runtime does not auto-apply this — apps decide where the inset matters.

Source

pub fn safe_area_bottom(&self) -> f32

Convenience: just the bottom inset, in logical pixels. Most commonly the soft-keyboard height.

Source

pub fn hovered_key(&self) -> Option<&str>

Key of the leaf node currently under the pointer, or None when nothing is hovered or this BuildCx was built without a UiState (headless rendering paths).

Use for branching the build output on hover state without mirroring it via App::on_event handlers — e.g., a sidebar row that previews details in a side pane based on what’s currently hovered.

For region-aware queries (parent stays “hot” while a child is hovered), prefer Self::is_hovering_within.

Source

pub fn is_hovering_within(&self, key: &str) -> bool

True iff key’s node — or any descendant of it — is the current hover target. Subtree-aware, matching the semantics of crate::tree::El::hover_alpha. Returns false when this BuildCx has no attached UiState or when key isn’t in the current tree.

Reads the underlying tracker, not the eased subtree envelope — the boolean flips immediately on hit-test identity change.

Source

pub fn hovered_scene_point(&self) -> Option<&ScenePointPick>

The scatter point currently under the cursor in a chart3d scene, if any — the 3D analogue of hovered_key.

Scene points aren’t Els, so they can’t emit PointerEnter/Leave like 2D widgets; this surfaces the same hover pick that draws the built-in tooltip chip (ScenePointPick carries the scene id + mark + point index). Use it to drive a detail panel / highlight / linked view on hover — branch the build on cx.hovered_scene_point() without an on_event handler. Picked a frame late (fine for hover UI) and honours the chip’s depth-occlusion + behind-camera culling.

Trait Implementations§

Source§

impl<'a> Clone for BuildCx<'a>

Source§

fn clone(&self) -> BuildCx<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for BuildCx<'a>

Source§

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

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

impl<'a> Copy for BuildCx<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for BuildCx<'a>

§

impl<'a> !RefUnwindSafe for BuildCx<'a>

§

impl<'a> Send for BuildCx<'a>

§

impl<'a> Sync for BuildCx<'a>

§

impl<'a> Unpin for BuildCx<'a>

§

impl<'a> UnsafeUnpin for BuildCx<'a>

§

impl<'a> !UnwindSafe for BuildCx<'a>

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.