vizia_winit/window_modifiers.rs
1use vizia_core::{binding::Res, context::EventContext};
2use vizia_window::{Anchor, AnchorTarget, WindowButtons, WindowPosition, WindowSize};
3
4/// Modifiers for setting the properties of a window.
5pub trait WindowModifiers {
6 fn on_close(self, callback: impl Fn(&mut EventContext) + 'static) -> Self;
7 fn on_create(self, callback: impl Fn(&mut EventContext) + 'static) -> Self;
8 /// Sets the title of the window to the given value. Accepts a type, or lens to a type, which implements `ToString`.
9 ///
10 /// # Example
11 /// ```no_run
12 /// # use vizia_core::prelude::*;
13 /// # use vizia_winit::application::Application;
14 /// Application::new(|cx|{
15 /// // Content here
16 /// })
17 /// .title("Vizia Application")
18 /// .run();
19 /// ```
20 fn title<T: ToString>(self, title: impl Res<T>) -> Self;
21 /// Sets the inner size of the window to the given value. Accepts a value, or lens, which can be converted to a [`WindowSize`].
22 ///
23 /// The inner size is the window area excluding the window borders.
24 ///
25 /// # Example
26 /// ```no_run
27 /// # use vizia_core::prelude::*;
28 /// # use vizia_winit::application::Application;
29 /// Application::new(|cx|{
30 /// // Content here
31 /// })
32 /// .inner_size((300, 300))
33 /// .run();
34 /// ```
35 fn inner_size<S: Into<WindowSize>>(self, size: impl Res<S>) -> Self;
36 /// Sets the minimum inner size of the window to the given value. Accepts an optional value, or lens, which can be converted to a [`WindowSize`].
37 ///
38 /// Setting the minimum inner size to `None` removes the minimum inner size constraint from the window.
39 ///
40 /// # Example
41 /// ```no_run
42 /// # use vizia_core::prelude::*;
43 /// # use vizia_winit::application::Application;
44 /// Application::new(|cx|{
45 /// // Content here
46 /// })
47 /// .min_inner_size(Some((300, 300)))
48 /// .run();
49 /// ```
50 fn min_inner_size<S: Into<WindowSize>>(self, size: impl Res<Option<S>>) -> Self;
51 /// Sets the maximum inner size of the window to the given value. Accepts an optional value, or lens, which can be converted to a [`WindowSize`].
52 ///
53 /// Setting the maximum inner size to `None` removes the maximum inner size constraint from the window.
54 ///
55 /// # Example
56 /// ```no_run
57 /// # use vizia_core::prelude::*;
58 /// # use vizia_winit::application::Application;
59 /// Application::new(|cx|{
60 /// // Content here
61 /// })
62 /// .max_inner_size(Some((1000, 1000)))
63 /// .run();
64 /// ```
65 fn max_inner_size<S: Into<WindowSize>>(self, size: impl Res<Option<S>>) -> Self;
66 /// Sets the position of the window to the given value. Accepts a value, or lens, which can be converted to a [`Position`].
67 ///
68 /// # Example
69 /// ```no_run
70 /// # use vizia_core::prelude::*;
71 /// # use vizia_winit::application::Application;
72 /// Application::new(|cx|{
73 /// // Content here
74 /// })
75 /// .position((100, 200))
76 /// .run();
77 /// ```
78 fn position<P: Into<WindowPosition>>(self, position: impl Res<P>) -> Self;
79
80 fn offset<P: Into<WindowPosition>>(self, offset: impl Res<P>) -> Self;
81
82 fn anchor<P: Into<Anchor>>(self, anchor: impl Res<P>) -> Self;
83
84 fn anchor_target<P: Into<AnchorTarget>>(self, anchor_target: impl Res<P>) -> Self;
85
86 fn parent_anchor<P: Into<Anchor>>(self, anchor: impl Res<P>) -> Self;
87
88 /// Sets whether the window can be resized. Accepts a boolean value, or lens to a boolean value.
89 ///
90 /// # Example
91 /// ```no_run
92 /// # use vizia_core::prelude::*;
93 /// # use vizia_winit::application::Application;
94 /// Application::new(|cx|{
95 /// // Content here
96 /// })
97 /// .resizable(false)
98 /// .run();
99 /// ```
100 fn resizable(self, flag: impl Res<bool>) -> Self;
101 /// Sets whether the window is minimized. Accepts a boolean value, or lens to a boolean value.
102 ///
103 /// # Example
104 /// ```no_run
105 /// # use vizia_core::prelude::*;
106 /// # use vizia_winit::application::Application;
107 /// Application::new(|cx|{
108 /// // Content here
109 /// })
110 /// .minimized(true)
111 /// .run();
112 /// ```
113 fn minimized(self, flag: impl Res<bool>) -> Self;
114 /// Sets whether the window is maximized. Accepts a boolean value, or lens to a boolean value.
115 ///
116 /// # Example
117 /// ```no_run
118 /// # use vizia_core::prelude::*;
119 /// # use vizia_winit::application::Application;
120 /// Application::new(|cx|{
121 /// // Content here
122 /// })
123 /// .maximized(true)
124 /// .run();
125 /// ```
126 fn maximized(self, flag: impl Res<bool>) -> Self;
127 /// Sets whether the window is visible. Accepts a boolean value, or lens to a boolean value.
128 ///
129 /// # Example
130 /// ```no_run
131 /// # use vizia_core::prelude::*;
132 /// # use vizia_winit::application::Application;
133 /// Application::new(|cx|{
134 /// // Content here
135 /// })
136 /// .visible(false)
137 /// .run();
138 /// ```
139 fn visible(self, flag: impl Res<bool>) -> Self;
140 /// Sets whether the window is transparent. Accepts a boolean value, or lens to a boolean value.
141 ///
142 /// # Example
143 /// ```no_run
144 /// # use vizia_core::prelude::*;
145 /// # use vizia_winit::application::Application;
146 /// Application::new(|cx|{
147 /// // Content here
148 /// })
149 /// .transparent(true)
150 /// .run();
151 /// ```
152 fn transparent(self, flag: bool) -> Self;
153 /// Sets whether the window has decorations. Accepts a boolean value, or lens to a boolean value.
154 ///
155 /// # Example
156 /// ```no_run
157 /// # use vizia_core::prelude::*;
158 /// # use vizia_winit::application::Application;
159 /// Application::new(|cx|{
160 /// // Content here
161 /// })
162 /// .decorations(false)
163 /// .run();
164 /// ```
165 fn decorations(self, flag: bool) -> Self;
166 /// Sets whether the window should be on top of other windows. Accepts a boolean value, or lens to a boolean value.
167 ///
168 /// # Example
169 /// ```no_run
170 /// # use vizia_core::prelude::*;
171 /// # use vizia_winit::application::Application;
172 /// Application::new(|cx|{
173 /// // Content here
174 /// })
175 /// .always_on_top(true)
176 /// .run();
177 /// ```
178 fn always_on_top(self, flag: bool) -> Self;
179 /// Sets whether the window has vsync enabled.
180 ///
181 /// # Example
182 /// ```no_run
183 /// # use vizia_core::prelude::*;
184 /// # use vizia_winit::application::Application;
185 /// Application::new(|cx|{
186 /// // Content here
187 /// })
188 /// .vsync(true)
189 /// .run();
190 /// ```
191 fn vsync(self, flag: bool) -> Self;
192 /// Sets the icon used for the window.
193 ///
194 /// # Example
195 /// ```no_run, ignore
196 /// # use vizia_core::prelude::*;
197 /// # use vizia_winit::application::Application;
198 ///
199 /// let icon = vizia::image::load_from_memory(include_bytes!("../icon.png"))
200 /// .expect("Failed to load icon");
201 ///
202 /// Application::new(|cx|{
203 /// // Content here
204 /// })
205 /// .icon(icon.width(), icon.height(), icon.into_bytes())
206 /// .run();
207 /// ```
208 fn icon(self, width: u32, height: u32, image: Vec<u8>) -> Self;
209
210 fn enabled_window_buttons(self, window_buttons: WindowButtons) -> Self;
211}