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 sized(w: f32, h: f32) -> WindowConfig
pub fn sized(w: f32, h: f32) -> WindowConfig
A normal, activating window of w x h logical px.
Sourcepub fn popup(anchor: Rect, w: f32, h: f32) -> WindowConfig
pub fn popup(anchor: Rect, w: f32, h: f32) -> WindowConfig
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) -> WindowConfig
pub fn of_kind(kind: WindowKind) -> WindowConfig
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, WindowConfig), String>
pub fn from_value(v: &Value) -> Result<(String, WindowConfig), 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.
Trait Implementations§
Source§impl Clone for WindowConfig
impl Clone for WindowConfig
Source§fn clone(&self) -> WindowConfig
fn clone(&self) -> WindowConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for WindowConfig
Source§impl Debug for WindowConfig
impl Debug for WindowConfig
Source§impl Default for WindowConfig
impl Default for WindowConfig
Source§fn default() -> WindowConfig
fn default() -> WindowConfig
Source§impl PartialEq for WindowConfig
impl PartialEq for WindowConfig
impl StructuralPartialEq for WindowConfig
Auto Trait Implementations§
impl Freeze for WindowConfig
impl RefUnwindSafe for WindowConfig
impl Send for WindowConfig
impl Sync for WindowConfig
impl Unpin for WindowConfig
impl UnsafeUnpin for WindowConfig
impl UnwindSafe for WindowConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.