pub struct WindowConfig {
pub kind: WindowKind,
pub size: Size,
pub activates: bool,
pub anchor: Rect,
}Expand description
What a frame says about a window it declares (Ui::window,
Core::declare_window). Plain data, no title and no callbacks, so a
WindowCommand stays Copy and two declarations of one name compare
by value.
Read on the opening edge only. The config that reaches
WindowCommand::Open is the one the declaration carried on the frame
it started; re-declaring "palette" at a new size does not resize it,
because the user owns a window’s geometry once it exists. Resize with
Core::set_window_size instead.
use kui_core::{Rect, WindowConfig, WindowKind};
let normal = WindowConfig::sized(640.0, 400.0);
let popup = WindowConfig::popup(Rect::new(0.0, 0.0, 120.0, 24.0), 120.0, 200.0);
assert!(normal.activates && !popup.activates);
assert_eq!(WindowConfig::default().size, WindowConfig::DEFAULT_SIZE);
assert_eq!(WindowKind::from_name("popup"), Some(WindowKind::Popup));Fields§
§kind: WindowKind§size: SizeInitial inner size, logical px.
activates: boolWhether opening it takes OS focus. True for a normal window;
WindowConfig::popup turns it off, so the field that opened a
dropdown keeps the ring while the list is up.
anchor: RectWindowKind::Popup only: what the popup is placed against, as a
rect in the declaring window’s logical viewport coordinates —
which is exactly the rect an onLayout node reports, so an app
needs no new geometry query to fill it. The driver resolves it to
screen coordinates against the owner’s own position and puts the
popup below it, flipping above when the display’s bottom edge is
nearer than the popup is tall.
Read on the opening edge with the rest of the config and never
again: a popup that has to follow a moving anchor stops being
declared and is declared again, which is what a dropdown does when
its field scrolls away anyway. Ignored by a Normal window.
Implementations§
Source§impl WindowConfig
impl WindowConfig
Sourcepub const DEFAULT_SIZE: Size
pub const DEFAULT_SIZE: Size
The size a declaration that names none gets.
Sourcepub fn popup(anchor: Rect, w: f32, h: f32) -> Self
pub fn popup(anchor: Rect, w: f32, h: f32) -> Self
A WindowKind::Popup of w x h logical px placed against
anchor — the rect, in the declaring window’s viewport
coordinates, that an onLayout handler reported for the field or
button the menu belongs to.
Non-activating, because a popup that takes OS focus blurs whatever
opened it. Set activates back to true afterwards for the rare
surface that should take focus.
Sourcepub fn of_kind(kind: WindowKind) -> Self
pub fn of_kind(kind: WindowKind) -> Self
The defaults for a window of kind: the one decision the kind
makes on its own is whether opening it takes OS focus (a normal
window does, a popup does not).
Sourcepub fn from_value(v: &Value) -> Result<(String, Self), String>
pub fn from_value(v: &Value) -> Result<(String, Self), String>
A declaration from plain data: a bare name (the defaults), or a map
with name, kind ("normal" | "popup"), width and height
(both and positive, or the default size), activates, and the anchor rect
({x, y, w, h}) a popup is placed against. Returns the name with
the config. An unknown kind is an error rather than a normal
window, so a typo cannot read as a popup having worked.