Skip to main content

LayoutCallbackInfo

Struct LayoutCallbackInfo 

Source
pub struct LayoutCallbackInfo {
    pub window_size: WindowSize,
    pub theme: WindowTheme,
    pub relayout_reason: RelayoutReason,
    /* private fields */
}

Fields§

§window_size: WindowSize

Window size (so that apps can return a different UI depending on the window size - mobile / desktop view). Should be later removed in favor of “resize” handlers and @media queries.

§theme: WindowTheme

Registers whether the UI is dependent on the window theme

§relayout_reason: RelayoutReason

What triggered this layout() call. Read via relayout_reason().

Implementations§

Source§

impl LayoutCallbackInfo

Source

pub const fn new<'a>( ref_data: &'a LayoutCallbackInfoRefData<'a>, window_size: WindowSize, theme: WindowTheme, ) -> Self

Source

pub const fn new_with_reason<'a>( ref_data: &'a LayoutCallbackInfoRefData<'a>, window_size: WindowSize, theme: WindowTheme, relayout_reason: RelayoutReason, ) -> Self

Source

pub const fn relayout_reason(&self) -> RelayoutReason

Returns what triggered the current layout() invocation.

Source

pub fn viewport_bigger_than(&self, width_px: f32) -> bool

Is the window’s LOGICAL viewport wider than width_px?

The structural-breakpoint helper: branch on this in layout() to return an entirely different DOM per form factor (ribbon.dom_desktop() vs ribbon.dom_mobile()), instead of emitting both trees and toggling visibility with @media rules.

CONTRACT: the framework re-invokes layout() on every window resize (RelayoutReason::Resize - the regenerate path never takes the layout-equivalence shortcut when the window size changed), so the answer cannot go stale: crossing the breakpoint in either direction re-runs layout() and the callback returns the other tree. If a future optimization ever skips DOM regeneration on resize, it must register the thresholds queried here and force a rebuild when one is crossed - grep for this comment.

Source

pub fn get_safe_area_insets(&self) -> SafeAreaInsets

Safe-area insets in logical px: system bars, notch / cutout, and the on-screen keyboard.

The same values CallbackInfo::get_safe_area_insets returns, made reachable from layout(). They were only available from EVENT callbacks, which is the wrong half: an app could read the notch from a click handler but not from the function that decides where to draw.

keyboard is kept separate from bottom deliberately. The bar is fixed and the keyboard moves, so a layout that must stay above the IME adds them, and one that only wants to avoid the home indicator does not.

Source

pub const fn set_callable_ptr(&mut self, callable: &OptionRefAny)

Set the callable pointer for FFI language bindings

Source

pub fn get_ctx(&self) -> OptionRefAny

Get the callable for FFI language bindings (Python, etc.)

Source

pub fn depends_on_system_style(&self, dep: SystemStyleDependency)

Declare that the DOM this callback returns depends on dep.

THE seam between “the OS appearance changed” and “this app’s DOM is now wrong”. A theme switch, an accent-colour change, a UI-font resize all arrive as the same kind of event, and the engine has no way to see which of them can change what layout() builds — only the callback knows.

Declare narrowly and a change outside what you declared costs a RESTYLE (the cascade re-resolves system-* colours and @theme conditions against the new style, warm layout caches intact) instead of a full Update::RefreshDom (re-invoke layout(), rebuild the StyledDom, re-cascade, re-shape every run of text).

// "I mirror light/dark and nothing else": switching between two
// light colour schemes cannot change my DOM.
info.depends_on_system_style(SystemStyleDependency::Theme);
let dark = info.get_theme() == WindowTheme::DarkMode;

// "I paint my own buttons from the OS palette": ANY palette move
// invalidates my DOM, light-to-light included.
info.depends_on_system_style(SystemStyleDependency::Colors);

Declarations UNION over the whole callback, widgets included, and the union is conservative: one widget calling Self::get_system_style declares SystemStyleDependency::Everything for the entire tree, because a whole-struct read is opaque.

Declaring NOTHING is not “depends on nothing” — an undeclared callback is rebuilt on every system-style change, exactly as before this API existed. Reading the theme field directly (info.theme) declares nothing either: the engine cannot see a field read, the same way it cannot see info.window_size being used to branch the DOM.

Source

pub fn get_theme(&self) -> WindowTheme

The window’s light/dark polarity, declaring SystemStyleDependency::Theme.

The tracked way to read what the theme field also holds. Use this and a change that leaves the polarity alone — a new accent colour, a different light scheme — will not rebuild the DOM.

Source

pub fn get_system_style(&self) -> Arc<SystemStyle>

Get a clone of the system style Arc.

Declares SystemStyleDependency::Everything: handing out the whole struct makes the read opaque, so the honest answer is that any part of it may have reached the DOM. A callback that only wants the palette or the fonts should say so with Self::depends_on_system_style and reach for Self::get_system_style_untracked.

Source

pub fn get_system_style_untracked(&self) -> Arc<SystemStyle>

The system style WITHOUT declaring a dependency on all of it.

For a callback that has already declared what it actually reads, and for engine-internal readers (CSD, menus) whose output is rebuilt by the engine itself rather than by the app’s layout().

Source

pub fn get_monitors(&self) -> MonitorVec

#28 (d): snapshot of the system’s monitors, taken by the caller right before this layout pass. Empty when the platform hasn’t populated monitor info (headless, web, very early startup).

Source

pub fn get_max_monitor_size(&self) -> OptionLayoutSize

#28 (d): the LARGEST monitor size in physical px — the safe upper bound for “how much content could possibly be visible at once” when the window’s own monitor is not yet known at first layout. Apps use it to bound how much content the first layout() builds (e.g. at most monitor-height text lines, or monitor-width × monitor-height characters for a single unbroken line), so opening a huge file never builds an unbounded DOM. None when no monitor info is available.

Source

pub fn get_gl_context(&self) -> OptionGlContextPtr

Source

pub fn get_system_fonts(&self) -> Vec<AzStringPair>

Source

pub fn get_font_cache(&self) -> FcFontCache

The window’s ALREADY-BUILT system font cache.

get_system_fonts only hands back stringified name/path pairs, which is useless to a layout callback that wants to run engine layout of its own (paginating a document, measuring for an export). Such an app had to call build_font_cache() and re-scan every font on the machine — measured at ~5 SECONDS on the first frame, during which the client cannot answer the compositor’s configure/ping handshake and loses its surface.

The cache is internally Arc<RwLock<_>> (rust-fontconfig 4.1+), so this clone is a handle, not a copy: the caller sees the same fonts the window already resolved, including builder-thread additions.

Source

pub fn get_image(&self, image_id: &AzString) -> Option<ImageRef>

Source

pub const fn get_active_route(&self) -> Option<&RouteMatch>

Get the active route match (pattern + extracted parameters).

Returns None if no routes are configured or no route is active.

Source

pub fn get_route_param(&self, key: &str) -> Option<&AzString>

Get a route parameter by key (e.g. get_route_param("id") for /user/:id).

Returns None if no route is active or the parameter doesn’t exist.

Source

pub fn get_route_pattern(&self) -> AzString

The pattern of the route this layout callback is rendering, e.g. "/user/:id".

"/" when the app configured no routes: an app without routing is on the default route, so a callback that branches on the pattern always has one string to branch on rather than an empty one.

§C API
AzString pattern = AzLayoutCallbackInfo_getRoutePattern(&info);
Source

pub fn get_route_param_or_empty(&self, key: AzString) -> AzString

A route parameter by key, empty when the parameter or the route is absent. The owned-key, owned-return form the FFI needs; Self::get_route_param is the borrowing Rust one.

§C API
AzString id = AzLayoutCallbackInfo_getRouteParamOrEmpty(&info,
    AzString_fromConstStr("id"));
Source

pub fn window_width_less_than(&self, px: f32) -> bool

Returns true if the window width is less than the given pixel value. Recorded — see the note above these helpers.

Source

pub fn window_width_greater_than(&self, px: f32) -> bool

Returns true if the window width is greater than the given pixel value. Recorded — see the note above these helpers.

Source

pub fn window_width_between(&self, min_px: f32, max_px: f32) -> bool

Returns true if the window width is between min and max (inclusive). Recorded as its two bounds — see the note above these helpers.

Source

pub fn window_height_less_than(&self, px: f32) -> bool

Returns true if the window height is less than the given pixel value. Recorded — see the note above these helpers.

Source

pub fn window_height_greater_than(&self, px: f32) -> bool

Returns true if the window height is greater than the given pixel value. Recorded — see the note above these helpers.

Source

pub fn window_height_between(&self, min_px: f32, max_px: f32) -> bool

Returns true if the window height is between min and max (inclusive). Recorded as its two bounds — see the note above these helpers.

Source

pub const fn get_window_width(&self) -> f32

Returns the current window width in pixels

Source

pub const fn get_window_height(&self) -> f32

Returns the current window height in pixels

Source

pub fn get_dpi_factor(&self) -> f32

Returns the current window DPI scale factor (1.0 = 96 DPI, 2.0 = 192 DPI)

Trait Implementations§

Source§

impl Clone for LayoutCallbackInfo

Source§

fn clone(&self) -> Self

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 Debug for LayoutCallbackInfo

Source§

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

Formats the value using the given formatter. 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
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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.