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::color::ColorU, 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_vec!(
59    WindowCreateOptions,
60    WindowCreateOptionsVec,
61    WindowCreateOptionsVecDestructor,
62    WindowCreateOptionsVecDestructorType
63);
64impl_vec_clone!(
65    WindowCreateOptions,
66    WindowCreateOptionsVec,
67    WindowCreateOptionsVecDestructor
68);
69impl_vec_partialeq!(WindowCreateOptions, WindowCreateOptionsVec);
70impl_vec_debug!(WindowCreateOptions, WindowCreateOptionsVec);
71impl_vec_mut!(WindowCreateOptions, WindowCreateOptionsVec);
72
73/// Full window state including internal fields not exposed to callbacks
74#[derive(Debug, Clone, PartialEq)]
75#[repr(C)]
76pub struct FullWindowState {
77    /// Semantic window identifier for multi-window debugging
78    /// Can be set by the user to identify specific windows (e.g., "main", "settings", "popup-1")
79    pub window_id: AzString,
80    pub theme: WindowTheme,
81    pub title: AzString,
82    pub size: WindowSize,
83    pub position: WindowPosition,
84    pub flags: WindowFlags,
85    pub debug_state: DebugState,
86    pub keyboard_state: KeyboardState,
87    pub mouse_state: MouseState,
88    pub touch_state: TouchState,
89    pub ime_position: ImePosition,
90    pub platform_specific_options: PlatformSpecificOptions,
91    pub renderer_options: RendererOptions,
92    pub background_color: ColorU,
93    pub layout_callback: LayoutCallback,
94    pub close_callback: OptionCallback,
95    /// Monitor ID (not the full Monitor struct - just the identifier)
96    pub monitor_id: OptionU32,
97    pub window_focused: bool,
98}
99
100impl_option!(
101    FullWindowState,
102    OptionFullWindowState,
103    copy = false,
104    [Debug, Clone, PartialEq]
105);
106
107impl Default for FullWindowState {
108    fn default() -> Self {
109        Self {
110            window_id: AzString::from_const_str("azul-window"),
111            theme: WindowTheme::default(),
112            title: AzString::from_const_str("Azul Window"),
113            size: WindowSize::default(),
114            position: WindowPosition::default(),
115            flags: WindowFlags::default(),
116            debug_state: DebugState::default(),
117            keyboard_state: KeyboardState::default(),
118            mouse_state: MouseState::default(),
119            touch_state: TouchState::default(),
120            ime_position: ImePosition::default(),
121            platform_specific_options: PlatformSpecificOptions::default(),
122            background_color: ColorU::WHITE,
123            layout_callback: LayoutCallback::default(),
124            close_callback: OptionCallback::None,
125            renderer_options: RendererOptions::default(),
126            monitor_id: OptionU32::None,
127            window_focused: true,
128        }
129    }
130}