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

            
7
use alloc::collections::BTreeMap;
8

            
9
use 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
};
17
use 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

            
22
use crate::callbacks::OptionCallback;
23

            
24
/// Options for creating a new window
25
#[derive(Debug, Clone, PartialEq)]
26
#[repr(C)]
27
pub struct WindowCreateOptions {
28
    /// Initial state for the new window
29
    pub window_state: FullWindowState,
30
    /// Optional callback invoked after the window is created
31
    pub create_callback: OptionCallback,
32
    /// Optional renderer configuration (e.g., VSync, SRGB)
33
    pub renderer: azul_core::window::OptionRendererOptions,
34
    /// Optional window theme override (light/dark)
35
    pub theme: azul_core::window::OptionWindowTheme,
36
    /// If true, the window is resized to fit its content after the first layout
37
    pub size_to_content: bool,
38
    /// If true, enables hot-reloading of CSS and resources
39
    pub hot_reload: bool,
40
    /// Parent window's platform id (the window-registry key: X Window id on X11,
41
    /// wl_surface ptr on Wayland, HWND on Windows, NSWindow ptr on macOS), or 0
42
    /// for a top-level window with no parent. Child windows (menus, dropdowns,
43
    /// dialogs) set this so the backend can position them relative to the parent
44
    /// and, on X11, reuse the parent's display connection for the single shared
45
    /// event pump. 0 = no parent.
46
    pub parent_window_id: u64,
47
}
48

            
49
impl Default for WindowCreateOptions {
50
    fn default() -> Self {
51
        Self {
52
            window_state: FullWindowState::default(),
53
            create_callback: OptionCallback::None,
54
            renderer: azul_core::window::OptionRendererOptions::None,
55
            theme: azul_core::window::OptionWindowTheme::None,
56
            size_to_content: false,
57
            hot_reload: false,
58
            parent_window_id: 0,
59
        }
60
    }
61
}
62

            
63
impl WindowCreateOptions {
64
    /// Create a new WindowCreateOptions with a layout callback
65
    pub fn create(layout_callback: impl Into<azul_core::callbacks::LayoutCallback>) -> Self {
66
        let mut options = Self::default();
67
        options.window_state.layout_callback = layout_callback.into();
68
        options
69
    }
70
}
71

            
72
impl_option!(WindowCreateOptions, OptionWindowCreateOptions, copy = false, [Debug, Clone, PartialEq]);
73
impl_vec!(WindowCreateOptions, WindowCreateOptionsVec, WindowCreateOptionsVecDestructor, WindowCreateOptionsVecDestructorType, WindowCreateOptionsVecSlice, OptionWindowCreateOptions);
74
impl_vec_clone!(
75
    WindowCreateOptions,
76
    WindowCreateOptionsVec,
77
    WindowCreateOptionsVecDestructor
78
);
79
impl_vec_partialeq!(WindowCreateOptions, WindowCreateOptionsVec);
80
impl_vec_debug!(WindowCreateOptions, WindowCreateOptionsVec);
81
impl_vec_mut!(WindowCreateOptions, WindowCreateOptionsVec);
82

            
83
/// Full window state including internal fields not exposed to callbacks
84
#[derive(Debug, Clone, PartialEq)]
85
#[repr(C)]
86
pub struct FullWindowState {
87
    /// Platform-specific window options
88
    pub platform_specific_options: PlatformSpecificOptions,
89
    /// Current keyboard state (pressed keys, modifiers)
90
    pub keyboard_state: KeyboardState,
91
    /// Semantic window identifier for multi-window debugging.
92
    /// Can be set by the user to identify specific windows (e.g., "main", "settings", "popup-1")
93
    pub window_id: AzString,
94
    /// Window title bar text
95
    pub title: AzString,
96
    /// Optional callback invoked when the user requests the window to close
97
    pub close_callback: OptionCallback,
98
    /// Callback that returns the DOM for this window
99
    pub layout_callback: LayoutCallback,
100
    /// Window position on screen
101
    pub position: WindowPosition,
102
    /// Current touch/gesture input state
103
    pub touch_state: TouchState,
104
    /// Window dimensions (logical and physical)
105
    pub size: WindowSize,
106
    /// Window flags (minimized, maximized, fullscreen, etc.)
107
    pub flags: WindowFlags,
108
    /// Current mouse cursor state (position, buttons)
109
    pub mouse_state: MouseState,
110
    /// Active window theme (light/dark)
111
    pub theme: WindowTheme,
112
    /// Position of the IME candidate window
113
    pub ime_position: ImePosition,
114
    /// GPU renderer options (VSync, SRGB, hardware acceleration)
115
    pub renderer_options: RendererOptions,
116
    /// Monitor ID (not the full Monitor struct - just the identifier)
117
    pub monitor_id: OptionU32,
118
    /// Debug visualization state (layout borders, repaints, etc.)
119
    pub debug_state: DebugState,
120
    /// Window background color. If None, uses system window background color.
121
    pub background_color: OptionColorU,
122
    /// Whether this window currently has input focus
123
    pub window_focused: bool,
124
    /// Active route match (pattern + extracted parameters).
125
    /// Set by `CallbackInfo::switch_route()` or by the web server on URL match.
126
    /// Layout callbacks read this via `LayoutCallbackInfo::get_route_param()`.
127
    pub active_route: azul_core::resources::OptionRouteMatch,
128
}
129

            
130
impl_option!(
131
    FullWindowState,
132
    OptionFullWindowState,
133
    copy = false,
134
    [Debug, Clone, PartialEq]
135
);
136

            
137
impl Default for FullWindowState {
138
6939
    fn default() -> Self {
139
6939
        Self {
140
6939
            platform_specific_options: PlatformSpecificOptions::default(),
141
6939
            keyboard_state: KeyboardState::default(),
142
6939
            window_id: AzString::from_const_str("azul-window"),
143
6939
            title: AzString::from_const_str("Azul Window"),
144
6939
            close_callback: OptionCallback::None,
145
6939
            layout_callback: LayoutCallback::default(),
146
6939
            position: WindowPosition::default(),
147
6939
            touch_state: TouchState::default(),
148
6939
            size: WindowSize::default(),
149
6939
            flags: WindowFlags::default(),
150
6939
            mouse_state: MouseState::default(),
151
6939
            theme: WindowTheme::default(),
152
6939
            ime_position: ImePosition::default(),
153
6939
            renderer_options: RendererOptions::default(),
154
6939
            monitor_id: OptionU32::None,
155
6939
            debug_state: DebugState::default(),
156
6939
            background_color: OptionColorU::None,
157
6939
            window_focused: true,
158
6939
            active_route: azul_core::resources::OptionRouteMatch::None,
159
6939
        }
160
6939
    }
161
}