zng_wgt_window/events.rs
1//! Window events, [`on_window_open`](fn@on_window_open) and [`on_window_close_requested`](fn@on_window_close_requested).
2//!
3//! These events are re-exported by [`Window!`](struct@crate::Window) as `on_open` and `on_close_requested`, but you can
4//! attach then in any widget inside a window using the property full name.
5//!
6//! There is no event property for the [`WINDOW_CLOSE_EVENT`] because that event notifies
7//! after the window is deinited. You can use [`on_deinit`](fn@zng_wgt::on_deinit) in the
8//! [`Window!`](struct@crate::Window) widget to handle a window closing, or create an app level handler for the
9//! event using [`EVENTS`](zng_app::event::EVENTS).
10//!
11//! [`WINDOW_CLOSE_EVENT`]: zng_ext_window::WINDOW_CLOSE_EVENT
12
13use zng_ext_window::*;
14use zng_wgt::prelude::*;
15
16event_property! {
17 /// On window opened.
18 ///
19 /// This event notifies once per window, after the window content is inited.
20 pub fn window_open {
21 event: WINDOW_OPEN_EVENT,
22 args: WindowOpenArgs,
23 filter: |args| args.window_id == WINDOW.id(),
24 }
25
26 /// On window loaded.
27 ///
28 /// This event notifies once per window, after the first layout and all [`WindowLoadingHandle`]
29 /// have expired or dropped.
30 ///
31 /// [`WindowLoadingHandle`]: zng_ext_window::WindowLoadingHandle
32 pub fn window_load {
33 event: WINDOW_LOAD_EVENT,
34 args: WindowOpenArgs,
35 filter: |args| args.window_id == WINDOW.id(),
36 }
37
38 /// On window moved, resized or other state changed.
39 ///
40 /// This event aggregates events moves, resizes and other state changes into a
41 /// single event to simplify tracking composite changes, for example, the window changes size and position
42 /// when maximized, this can be trivially observed with this event.
43 pub fn window_changed {
44 event: WINDOW_CHANGED_EVENT,
45 args: WindowChangedArgs,
46 filter: |args| args.window_id == WINDOW.id(),
47 }
48
49 /// On window position changed.
50 pub fn window_moved {
51 event: WINDOW_CHANGED_EVENT,
52 args: WindowChangedArgs,
53 filter: |args| args.window_id == WINDOW.id() && args.is_moved(),
54 }
55
56 /// On window size changed.
57 pub fn window_resized {
58 event: WINDOW_CHANGED_EVENT,
59 args: WindowChangedArgs,
60 filter: |args| args.window_id == WINDOW.id() && args.is_resized(),
61 }
62
63 /// On window close requested.
64 ///
65 /// Calling `propagation().stop()` on this event cancels the window close.
66 pub fn window_close_requested {
67 event: WINDOW_CLOSE_REQUESTED_EVENT,
68 args: WindowCloseRequestedArgs,
69 filter: |args| args.windows.contains(&WINDOW.id()),
70 }
71
72 /// On window closed.
73 ///
74 /// See [`WINDOW_CLOSE_EVENT`] for more details of when this event notifies.
75 pub fn window_close {
76 event: WINDOW_CLOSE_EVENT,
77 args: WindowCloseArgs,
78 filter: |args| args.windows.contains(&WINDOW.id()),
79 }
80
81 /// On window state changed.
82 ///
83 /// This event notifies every time the user or the app changes the [`WindowVars::state`].
84 ///
85 /// [`WindowVars::state`]: zng_ext_window::WindowVars
86 pub fn window_state_changed {
87 event: WINDOW_CHANGED_EVENT,
88 args: WindowChangedArgs,
89 filter: |args| args.window_id == WINDOW.id() && args.is_state_changed(),
90 }
91
92 /// On window state changed to [`WindowState::Maximized`].
93 ///
94 /// [`WindowState::Maximized`]: zng_ext_window::WindowState::Maximized
95 pub fn window_maximized {
96 event: WINDOW_CHANGED_EVENT,
97 args: WindowChangedArgs,
98 filter: |args| args.window_id == WINDOW.id() && args.entered_state(WindowState::Maximized),
99 }
100
101 /// On window state changed from [`WindowState::Maximized`].
102 ///
103 /// [`WindowState::Maximized`]: zng_ext_window::WindowState::Maximized
104 pub fn window_unmaximized {
105 event: WINDOW_CHANGED_EVENT,
106 args: WindowChangedArgs,
107 filter: |args| args.window_id == WINDOW.id() && args.exited_state(WindowState::Maximized),
108 }
109
110 /// On window state changed to [`WindowState::Minimized`].
111 ///
112 /// [`WindowState::Minimized`]: zng_ext_window::WindowState::Minimized
113 pub fn window_minimized {
114 event: WINDOW_CHANGED_EVENT,
115 args: WindowChangedArgs,
116 filter: |args| args.window_id == WINDOW.id() && args.entered_state(WindowState::Minimized),
117 }
118
119 /// On window state changed from [`WindowState::Minimized`].
120 ///
121 /// [`WindowState::Minimized`]: zng_ext_window::WindowState::Minimized
122 pub fn window_unminimized {
123 event: WINDOW_CHANGED_EVENT,
124 args: WindowChangedArgs,
125 filter: |args| args.window_id == WINDOW.id() && args.exited_state(WindowState::Minimized),
126 }
127
128 /// On window state changed to [`WindowState::Normal`].
129 ///
130 /// [`WindowState::Normal`]: zng_ext_window::WindowState::Normal
131 pub fn window_restored {
132 event: WINDOW_CHANGED_EVENT,
133 args: WindowChangedArgs,
134 filter: |args| args.window_id == WINDOW.id() && args.entered_state(WindowState::Normal),
135 }
136
137 /// On window state changed to [`WindowState::is_fullscreen`].
138 ///
139 /// [`WindowState::is_fullscreen`]: zng_ext_window::WindowState::is_fullscreen
140 pub fn window_fullscreen {
141 event: WINDOW_CHANGED_EVENT,
142 args: WindowChangedArgs,
143 filter: |args| args.window_id == WINDOW.id() && args.entered_fullscreen(),
144 }
145
146 /// On window state changed from [`WindowState::is_fullscreen`].
147 ///
148 /// [`WindowState::is_fullscreen`]: zng_ext_window::WindowState::is_fullscreen
149 pub fn window_exited_fullscreen {
150 event: WINDOW_CHANGED_EVENT,
151 args: WindowChangedArgs,
152 filter: |args| args.window_id == WINDOW.id() && args.exited_fullscreen(),
153 }
154
155 /// On window frame rendered.
156 pub fn frame_image_ready {
157 event: FRAME_IMAGE_READY_EVENT,
158 args: FrameImageReadyArgs,
159 filter: |args| args.window_id == WINDOW.id(),
160 }
161
162 /// On Input Method Editor event.
163 pub fn ime {
164 event: IME_EVENT,
165 args: ImeArgs,
166 filter: |args| args.target.widget_id() == WIDGET.id(),
167 }
168}