Skip to main content

azul_layout/
window_state.rs

1//! Window state types for azul-layout
2//!
3//! These types are defined here (rather than azul-core) because CallbackInfo
4//! needs to reference them, and CallbackInfo must live in azul-layout (since
5//! it requires LayoutWindow).
6
7use alloc::collections::BTreeMap;
8
9use azul_core::{
10    callbacks::LayoutCallback,
11    dom::DomId,
12    window::{
13        DebugState, ImePosition, KeyboardState, Monitor, MouseState, PlatformSpecificOptions,
14        RendererOptions, TouchState, WindowFlags, WindowPosition, WindowSize, WindowTheme,
15    },
16};
17use azul_css::{
18    corety::OptionU32, impl_option, impl_option_inner, impl_vec, impl_vec_clone, impl_vec_debug,
19    impl_vec_mut, impl_vec_partialeq, props::basic::OptionColorU, AzString,
20};
21
22use crate::callbacks::OptionCallback;
23
24/// Options for creating a new window
25#[derive(Debug, Clone, PartialEq)]
26#[repr(C)]
27pub struct WindowCreateOptions {
28    pub window_state: FullWindowState,
29    pub size_to_content: bool,
30    pub renderer: azul_core::window::OptionRendererOptions,
31    pub theme: azul_core::window::OptionWindowTheme,
32    pub create_callback: OptionCallback,
33    pub hot_reload: bool,
34}
35
36impl Default for WindowCreateOptions {
37    fn default() -> Self {
38        Self {
39            window_state: FullWindowState::default(),
40            size_to_content: false,
41            renderer: azul_core::window::OptionRendererOptions::None,
42            theme: azul_core::window::OptionWindowTheme::None,
43            create_callback: OptionCallback::None,
44            hot_reload: false,
45        }
46    }
47}
48
49impl WindowCreateOptions {
50    /// Create a new WindowCreateOptions with a layout callback
51    pub fn create(layout_callback: impl Into<azul_core::callbacks::LayoutCallback>) -> Self {
52        let mut options = Self::default();
53        options.window_state.layout_callback = layout_callback.into();
54        options
55    }
56}
57
58impl_option!(WindowCreateOptions, OptionWindowCreateOptions, copy = false, [Debug, Clone, PartialEq]);
59impl_vec!(WindowCreateOptions, WindowCreateOptionsVec, WindowCreateOptionsVecDestructor, WindowCreateOptionsVecDestructorType, WindowCreateOptionsVecSlice, OptionWindowCreateOptions);
60impl_vec_clone!(
61    WindowCreateOptions,
62    WindowCreateOptionsVec,
63    WindowCreateOptionsVecDestructor
64);
65impl_vec_partialeq!(WindowCreateOptions, WindowCreateOptionsVec);
66impl_vec_debug!(WindowCreateOptions, WindowCreateOptionsVec);
67impl_vec_mut!(WindowCreateOptions, WindowCreateOptionsVec);
68
69/// Full window state including internal fields not exposed to callbacks
70#[derive(Debug, Clone, PartialEq)]
71#[repr(C)]
72pub struct FullWindowState {
73    /// Semantic window identifier for multi-window debugging
74    /// Can be set by the user to identify specific windows (e.g., "main", "settings", "popup-1")
75    pub window_id: AzString,
76    pub theme: WindowTheme,
77    pub title: AzString,
78    pub size: WindowSize,
79    pub position: WindowPosition,
80    pub flags: WindowFlags,
81    pub debug_state: DebugState,
82    pub keyboard_state: KeyboardState,
83    pub mouse_state: MouseState,
84    pub touch_state: TouchState,
85    pub ime_position: ImePosition,
86    pub platform_specific_options: PlatformSpecificOptions,
87    pub renderer_options: RendererOptions,
88    /// Window background color. If None, uses system window background color.
89    pub background_color: OptionColorU,
90    pub layout_callback: LayoutCallback,
91    pub close_callback: OptionCallback,
92    /// Monitor ID (not the full Monitor struct - just the identifier)
93    pub monitor_id: OptionU32,
94    pub window_focused: bool,
95}
96
97impl_option!(
98    FullWindowState,
99    OptionFullWindowState,
100    copy = false,
101    [Debug, Clone, PartialEq]
102);
103
104impl Default for FullWindowState {
105    fn default() -> Self {
106        Self {
107            window_id: AzString::from_const_str("azul-window"),
108            theme: WindowTheme::default(),
109            title: AzString::from_const_str("Azul Window"),
110            size: WindowSize::default(),
111            position: WindowPosition::default(),
112            flags: WindowFlags::default(),
113            debug_state: DebugState::default(),
114            keyboard_state: KeyboardState::default(),
115            mouse_state: MouseState::default(),
116            touch_state: TouchState::default(),
117            ime_position: ImePosition::default(),
118            platform_specific_options: PlatformSpecificOptions::default(),
119            background_color: OptionColorU::None,
120            layout_callback: LayoutCallback::default(),
121            close_callback: OptionCallback::None,
122            renderer_options: RendererOptions::default(),
123            monitor_id: OptionU32::None,
124            window_focused: true,
125        }
126    }
127}