zng_wgt_window/
events.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//! Window events, [`on_window_open`](fn@on_window_open) and [`on_window_close_requested`](fn@on_window_close_requested).
//!
//! These events are re-exported by [`Window!`](struct@crate::Window) as `on_open` and `on_close_requested`, but you can
//! attach then in any widget inside a window using the property full name.
//!
//! There is no event property for the [`WINDOW_CLOSE_EVENT`] because that event notifies
//! after the window is deinited. You can use [`on_deinit`](fn@zng_wgt::on_deinit) in the
//! [`Window!`](struct@crate::Window) widget to handle a window closing, or create an app level handler for the
//! event using [`EVENTS`](zng_app::event::EVENTS).
//!
//! [`WINDOW_CLOSE_EVENT`]: zng_ext_window::WINDOW_CLOSE_EVENT

use zng_ext_window::*;
use zng_wgt::prelude::*;

event_property! {
    /// On window opened.
    ///
    /// This event notifies once per window, after the window content is inited.
    pub fn window_open {
        event: WINDOW_OPEN_EVENT,
        args: WindowOpenArgs,
        filter: |args| args.window_id == WINDOW.id(),
    }

    /// On window loaded.
    ///
    /// This event notifies once per window, after the first layout and all [`WindowLoadingHandle`]
    /// have expired or dropped.
    ///
    /// [`WindowLoadingHandle`]: zng_ext_window::WindowLoadingHandle
    pub fn window_load {
        event: WINDOW_LOAD_EVENT,
        args: WindowOpenArgs,
        filter: |args| args.window_id == WINDOW.id(),
    }

    /// On window moved, resized or other state changed.
    ///
    /// This event aggregates events moves, resizes and other state changes into a
    /// single event to simplify tracking composite changes, for example, the window changes size and position
    /// when maximized, this can be trivially observed with this event.
    pub fn window_changed {
        event: WINDOW_CHANGED_EVENT,
        args: WindowChangedArgs,
        filter: |args| args.window_id == WINDOW.id(),
    }

    /// On window position changed.
    pub fn window_moved {
        event: WINDOW_CHANGED_EVENT,
        args: WindowChangedArgs,
        filter: |args| args.window_id == WINDOW.id() && args.is_moved(),
    }

    /// On window size changed.
    pub fn window_resized {
        event: WINDOW_CHANGED_EVENT,
        args: WindowChangedArgs,
        filter: |args| args.window_id == WINDOW.id() && args.is_resized(),
    }

    /// On window close requested.
    ///
    /// Calling `propagation().stop()` on this event cancels the window close.
    pub fn window_close_requested {
        event: WINDOW_CLOSE_REQUESTED_EVENT,
        args: WindowCloseRequestedArgs,
        filter: |args| args.windows.contains(&WINDOW.id()),
    }

    /// On window closed.
    ///
    /// See [`WINDOW_CLOSE_EVENT`] for more details of when this event notifies.
    pub fn window_close {
        event: WINDOW_CLOSE_EVENT,
        args: WindowCloseArgs,
        filter: |args| args.windows.contains(&WINDOW.id()),
    }

    /// On window state changed.
    ///
    /// This event notifies every time the user or the app changes the [`WindowVars::state`].
    ///
    /// [`WindowVars::state`]: zng_ext_window::WindowVars
    pub fn window_state_changed {
        event: WINDOW_CHANGED_EVENT,
        args: WindowChangedArgs,
        filter: |args| args.window_id == WINDOW.id() && args.is_state_changed(),
    }

    /// On window state changed to [`WindowState::Maximized`].
    ///
    /// [`WindowState::Maximized`]: zng_ext_window::WindowState::Maximized
    pub fn window_maximized {
        event: WINDOW_CHANGED_EVENT,
        args: WindowChangedArgs,
        filter: |args| args.window_id == WINDOW.id() && args.entered_state(WindowState::Maximized),
    }

    /// On window state changed from [`WindowState::Maximized`].
    ///
    /// [`WindowState::Maximized`]: zng_ext_window::WindowState::Maximized
    pub fn window_unmaximized {
        event: WINDOW_CHANGED_EVENT,
        args: WindowChangedArgs,
        filter: |args| args.window_id == WINDOW.id() && args.exited_state(WindowState::Maximized),
    }

    /// On window state changed to [`WindowState::Minimized`].
    ///
    /// [`WindowState::Minimized`]: zng_ext_window::WindowState::Minimized
    pub fn window_minimized {
        event: WINDOW_CHANGED_EVENT,
        args: WindowChangedArgs,
        filter: |args| args.window_id == WINDOW.id() && args.entered_state(WindowState::Minimized),
    }

    /// On window state changed from [`WindowState::Minimized`].
    ///
    /// [`WindowState::Minimized`]: zng_ext_window::WindowState::Minimized
    pub fn window_unminimized {
        event: WINDOW_CHANGED_EVENT,
        args: WindowChangedArgs,
        filter: |args| args.window_id == WINDOW.id() && args.exited_state(WindowState::Minimized),
    }

    /// On window state changed to [`WindowState::Normal`].
    ///
    /// [`WindowState::Normal`]: zng_ext_window::WindowState::Normal
    pub fn window_restored {
        event: WINDOW_CHANGED_EVENT,
        args: WindowChangedArgs,
        filter: |args| args.window_id == WINDOW.id() && args.entered_state(WindowState::Normal),
    }

    /// On window state changed to [`WindowState::is_fullscreen`].
    ///
    /// [`WindowState::is_fullscreen`]: zng_ext_window::WindowState::is_fullscreen
    pub fn window_fullscreen {
        event: WINDOW_CHANGED_EVENT,
        args: WindowChangedArgs,
        filter: |args| args.window_id == WINDOW.id() && args.entered_fullscreen(),
    }

    /// On window state changed from [`WindowState::is_fullscreen`].
    ///
    /// [`WindowState::is_fullscreen`]: zng_ext_window::WindowState::is_fullscreen
    pub fn window_exited_fullscreen {
        event: WINDOW_CHANGED_EVENT,
        args: WindowChangedArgs,
        filter: |args| args.window_id == WINDOW.id() && args.exited_fullscreen(),
    }

    /// On window frame rendered.
    pub fn frame_image_ready {
        event: FRAME_IMAGE_READY_EVENT,
        args: FrameImageReadyArgs,
        filter: |args| args.window_id == WINDOW.id(),
    }

    /// On Input Method Editor event.
    pub fn ime {
        event: IME_EVENT,
        args: ImeArgs,
        filter: |args| args.target.widget_id() == WIDGET.id(),
    }
}