pub struct LayoutCallbackInfo {
pub window_size: WindowSize,
pub theme: WindowTheme,
pub relayout_reason: RelayoutReason,
/* private fields */
}Fields§
§window_size: WindowSizeWindow 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: WindowThemeRegisters whether the UI is dependent on the window theme
relayout_reason: RelayoutReasonWhat triggered this layout() call. Read via relayout_reason().
Implementations§
Source§impl LayoutCallbackInfo
impl LayoutCallbackInfo
pub const fn new<'a>( ref_data: &'a LayoutCallbackInfoRefData<'a>, window_size: WindowSize, theme: WindowTheme, ) -> Self
pub const fn new_with_reason<'a>( ref_data: &'a LayoutCallbackInfoRefData<'a>, window_size: WindowSize, theme: WindowTheme, relayout_reason: RelayoutReason, ) -> Self
Sourcepub const fn relayout_reason(&self) -> RelayoutReason
pub const fn relayout_reason(&self) -> RelayoutReason
Returns what triggered the current layout() invocation.
Sourcepub fn viewport_bigger_than(&self, width_px: f32) -> bool
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.
Sourcepub fn get_safe_area_insets(&self) -> SafeAreaInsets
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.
Sourcepub const fn set_callable_ptr(&mut self, callable: &OptionRefAny)
pub const fn set_callable_ptr(&mut self, callable: &OptionRefAny)
Set the callable pointer for FFI language bindings
Sourcepub fn get_ctx(&self) -> OptionRefAny
pub fn get_ctx(&self) -> OptionRefAny
Get the callable for FFI language bindings (Python, etc.)
Sourcepub fn depends_on_system_style(&self, dep: SystemStyleDependency)
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.
Sourcepub fn get_theme(&self) -> WindowTheme
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.
Sourcepub fn get_system_style(&self) -> Arc<SystemStyle> ⓘ
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.
Sourcepub fn get_system_style_untracked(&self) -> Arc<SystemStyle> ⓘ
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().
Sourcepub fn get_monitors(&self) -> MonitorVec
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).
Sourcepub fn get_max_monitor_size(&self) -> OptionLayoutSize
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.
pub fn get_gl_context(&self) -> OptionGlContextPtr
pub fn get_system_fonts(&self) -> Vec<AzStringPair>
Sourcepub fn get_font_cache(&self) -> FcFontCache
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.
pub fn get_image(&self, image_id: &AzString) -> Option<ImageRef>
Sourcepub const fn get_active_route(&self) -> Option<&RouteMatch>
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.
Sourcepub fn get_route_param(&self, key: &str) -> Option<&AzString>
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.
Sourcepub fn get_route_pattern(&self) -> AzString
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);Sourcepub fn get_route_param_or_empty(&self, key: AzString) -> AzString
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"));Sourcepub fn window_width_less_than(&self, px: f32) -> bool
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.
Sourcepub fn window_width_greater_than(&self, px: f32) -> bool
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.
Sourcepub fn window_width_between(&self, min_px: f32, max_px: f32) -> bool
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.
Sourcepub fn window_height_less_than(&self, px: f32) -> bool
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.
Sourcepub fn window_height_greater_than(&self, px: f32) -> bool
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.
Sourcepub fn window_height_between(&self, min_px: f32, max_px: f32) -> bool
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.
Sourcepub const fn get_window_width(&self) -> f32
pub const fn get_window_width(&self) -> f32
Returns the current window width in pixels
Sourcepub const fn get_window_height(&self) -> f32
pub const fn get_window_height(&self) -> f32
Returns the current window height in pixels
Sourcepub fn get_dpi_factor(&self) -> f32
pub fn get_dpi_factor(&self) -> f32
Returns the current window DPI scale factor (1.0 = 96 DPI, 2.0 = 192 DPI)