uzor 1.2.1

Core UI engine — geometry, interaction, input state
//! Multi-window primitives for the L4 framework.

use crate::core::types::Rect;
use crate::layout::LayoutManager;
use crate::layout::docking::DockPanel;
use super::builder::RgbaIcon;
use crate::platform::types::CornerStyle;

// `WindowKey` lives in `uzor::layout::window` — the layout manager owns
// the window registry, so its key type is the canonical one.  Re-exported
// here for back-compat with framework callers.
pub use crate::layout::window::WindowKey;

/// Declarative description of a window the runtime should create.
#[derive(Debug, Clone)]
pub struct WindowSpec {
    pub key:          WindowKey,
    pub title:        String,
    pub size:         (u32, u32),
    pub min_size:     Option<(u32, u32)>,
    pub decorations:  bool,
    pub background:   u32,
    pub icon:         Option<RgbaIcon>,
    /// Preferred OS corner-rounding style. Default: let the OS decide.
    pub corner_style: CornerStyle,
    /// Override the OS border accent colour (`0x00RRGGBB` ARGB). `None` = OS default.
    pub border_color: Option<u32>,
    /// Override the OS drop-shadow. `None` = OS default.
    pub shadow:       Option<bool>,
    /// Baseline repaint cadence — independent of input events.  See
    /// [`crate::render::TickRate`].  `None` = inherit from
    /// `AppConfig::default_tick_rate` (or the parent window when
    /// spawned via `on_chrome_new_window`).
    pub tick_rate:    Option<crate::render::TickRate>,
}

impl WindowSpec {
    pub fn new(key: impl Into<WindowKey>, title: impl Into<String>) -> Self {
        Self {
            key:          key.into(),
            title:        title.into(),
            size:         (1280, 800),
            min_size:     Some((400, 300)),
            decorations:  false,
            background:   0xFF_FF_FF_FF,
            icon:         None,
            corner_style: CornerStyle::Default,
            border_color: None,
            shadow:       None,
            tick_rate:    None,
        }
    }

    /// Set the baseline repaint cadence for this window.  Pass
    /// [`crate::render::TickRate::Dirty`] to opt out of the default
    /// heartbeat.
    pub fn tick_rate(mut self, rate: crate::render::TickRate) -> Self {
        self.tick_rate = Some(rate);
        self
    }

    pub fn size(mut self, w: u32, h: u32) -> Self { self.size = (w, h); self }
    pub fn min_size(mut self, w: u32, h: u32) -> Self { self.min_size = Some((w, h)); self }
    pub fn decorations(mut self, on: bool) -> Self { self.decorations = on; self }
    pub fn background(mut self, argb: u32) -> Self { self.background = argb; self }
    pub fn icon(mut self, icon: RgbaIcon) -> Self { self.icon = Some(icon); self }

    /// Set the preferred corner-rounding style.
    pub fn corner_style(mut self, style: CornerStyle) -> Self {
        self.corner_style = style;
        self
    }

    /// Override the OS border accent colour (`0x00RRGGBB`). Pass `None` to clear.
    pub fn border_color(mut self, color: u32) -> Self {
        self.border_color = Some(color);
        self
    }

    /// Override the OS drop-shadow.
    pub fn shadow(mut self, on: bool) -> Self {
        self.shadow = Some(on);
        self
    }
}

/// Per-window context handed to `App::ui` for each open window in turn.
pub struct WindowCtx<'a, P: DockPanel> {
    pub key:            &'a WindowKey,
    pub layout:         &'a mut LayoutManager<P>,
    pub render:         &'a mut dyn crate::render::RenderContext,
    /// Window content rect in window-local coordinates.
    pub rect:           Rect,
    /// Runtime render-backend / performance control.
    pub render_control: &'a mut dyn super::render_control::RenderControl,
}