Skip to main content

vizia_winit/
window_modifiers.rs

1use vizia_core::{binding::Res, context::EventContext, localization::ToStringLocalized};
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 value or signal of any type that implements `ToString`.
9    /// Accepts a [`Localized`] value to set a localizable title that updates when the locale changes.
10    ///
11    /// # Example
12    /// ```no_run
13    /// # use vizia_core::prelude::*;
14    /// # use vizia_winit::application::Application;
15    /// # use vizia_winit::window::Window;
16    /// # use vizia_winit::window_modifiers::WindowModifiers;
17    /// Application::new(|cx| {
18    ///     Window::new(cx, |cx| {
19    ///         // Content here
20    ///     })
21    ///     .title("Vizia Application");
22    /// })
23    /// .run();
24    /// ```
25    fn title<T: ToStringLocalized>(self, title: impl Res<T> + Clone + 'static) -> Self;
26    /// Sets the inner size of the window to the given value. Accepts a value or signal that can be converted to a [`WindowSize`].
27    ///
28    /// The inner size is the window area excluding the window borders.
29    ///
30    /// # Example
31    /// ```no_run
32    /// # use vizia_core::prelude::*;
33    /// # use vizia_winit::application::Application;
34    /// # use vizia_winit::window::Window;
35    /// # use vizia_winit::window_modifiers::WindowModifiers;
36    /// Application::new(|cx| {
37    ///     Window::new(cx, |cx| {
38    ///         // Content here
39    ///     })
40    ///     .inner_size((300, 300));
41    /// })
42    /// .run();
43    /// ```
44    fn inner_size<S: Into<WindowSize>>(self, size: impl Res<S>) -> Self;
45    /// Sets the minimum inner size of the window to the given value. Accepts an optional value or signal that can be converted to a [`WindowSize`].
46    ///
47    /// Setting the minimum inner size to `None` removes the minimum inner size constraint from the window.
48    ///
49    /// # Example
50    /// ```no_run
51    /// # use vizia_core::prelude::*;
52    /// # use vizia_winit::application::Application;
53    /// # use vizia_winit::window::Window;
54    /// # use vizia_winit::window_modifiers::WindowModifiers;
55    /// Application::new(|cx| {
56    ///     Window::new(cx, |cx| {
57    ///         // Content here
58    ///     })
59    ///     .min_inner_size(Some((300, 300)));
60    /// })
61    /// .run();
62    /// ```
63    fn min_inner_size<S: Into<WindowSize>>(self, size: impl Res<Option<S>>) -> Self;
64    /// Sets the maximum inner size of the window to the given value. Accepts an optional value or signal that can be converted to a [`WindowSize`].
65    ///
66    /// Setting the maximum inner size to `None` removes the maximum inner size constraint from the window.
67    ///
68    /// # Example
69    /// ```no_run
70    /// # use vizia_core::prelude::*;
71    /// # use vizia_winit::application::Application;
72    /// # use vizia_winit::window::Window;
73    /// # use vizia_winit::window_modifiers::WindowModifiers;
74    /// Application::new(|cx| {
75    ///     Window::new(cx, |cx| {
76    ///         // Content here
77    ///     })
78    ///     .max_inner_size(Some((1000, 1000)));
79    /// })
80    /// .run();
81    /// ```
82    fn max_inner_size<S: Into<WindowSize>>(self, size: impl Res<Option<S>>) -> Self;
83    /// Sets the position of the window to the given value. Accepts a value or signal that can be converted to a [`Position`].
84    ///
85    /// # Example
86    /// ```no_run
87    /// # use vizia_core::prelude::*;
88    /// # use vizia_winit::application::Application;
89    /// # use vizia_winit::window::Window;
90    /// # use vizia_winit::window_modifiers::WindowModifiers;
91    /// Application::new(|cx| {
92    ///     Window::new(cx, |cx| {
93    ///         // Content here
94    ///     })
95    ///     .position((100, 200));
96    /// })
97    /// .run();
98    /// ```
99    fn position<P: Into<WindowPosition>>(self, position: impl Res<P>) -> Self;
100
101    fn offset<P: Into<WindowPosition>>(self, offset: impl Res<P>) -> Self;
102
103    fn anchor<P: Into<Anchor>>(self, anchor: impl Res<P>) -> Self;
104
105    fn anchor_target<P: Into<AnchorTarget>>(self, anchor_target: impl Res<P>) -> Self;
106
107    fn parent_anchor<P: Into<Anchor>>(self, anchor: impl Res<P>) -> Self;
108
109    /// Sets whether the window can be resized. Accepts a boolean value or `Res<bool>` source.
110    ///
111    /// # Example
112    /// ```no_run
113    /// # use vizia_core::prelude::*;
114    /// # use vizia_winit::application::Application;
115    /// # use vizia_winit::window::Window;
116    /// # use vizia_winit::window_modifiers::WindowModifiers;
117    /// Application::new(|cx| {
118    ///     Window::new(cx, |cx| {
119    ///         // Content here
120    ///     })
121    ///     .resizable(false);
122    /// })
123    /// .run();
124    /// ```
125    fn resizable(self, flag: impl Res<bool>) -> Self;
126    /// Sets whether the window is minimized. Accepts a boolean value or `Res<bool>` source.
127    ///
128    /// # Example
129    /// ```no_run
130    /// # use vizia_core::prelude::*;
131    /// # use vizia_winit::application::Application;
132    /// # use vizia_winit::window::Window;
133    /// # use vizia_winit::window_modifiers::WindowModifiers;
134    /// Application::new(|cx| {
135    ///     Window::new(cx, |cx| {
136    ///         // Content here
137    ///     })
138    ///     .minimized(true);
139    /// })
140    /// .run();
141    /// ```
142    fn minimized(self, flag: impl Res<bool>) -> Self;
143    /// Sets whether the window is maximized. Accepts a boolean value or `Res<bool>` source.
144    ///
145    /// # Example
146    /// ```no_run
147    /// # use vizia_core::prelude::*;
148    /// # use vizia_winit::application::Application;
149    /// # use vizia_winit::window::Window;
150    /// # use vizia_winit::window_modifiers::WindowModifiers;
151    /// Application::new(|cx| {
152    ///     Window::new(cx, |cx| {
153    ///         // Content here
154    ///     })
155    ///     .maximized(true);
156    /// })
157    /// .run();
158    /// ```
159    fn maximized(self, flag: impl Res<bool>) -> Self;
160    /// Sets whether the window is visible. Accepts a boolean value or `Res<bool>` source.
161    ///
162    /// # Example
163    /// ```no_run
164    /// # use vizia_core::prelude::*;
165    /// # use vizia_winit::application::Application;
166    /// # use vizia_winit::window::Window;
167    /// # use vizia_winit::window_modifiers::WindowModifiers;
168    /// Application::new(|cx| {
169    ///     Window::new(cx, |cx| {
170    ///         // Content here
171    ///     })
172    ///     .visible(false);
173    /// })
174    /// .run();
175    /// ```
176    fn visible(self, flag: impl Res<bool>) -> Self;
177    /// Sets whether the window is transparent.
178    ///
179    /// # Example
180    /// ```no_run
181    /// # use vizia_core::prelude::*;
182    /// # use vizia_winit::application::Application;
183    /// # use vizia_winit::window::Window;
184    /// # use vizia_winit::window_modifiers::WindowModifiers;
185    /// Application::new(|cx| {
186    ///     Window::new(cx, |cx| {
187    ///         // Content here
188    ///     })
189    ///     .transparent(true);
190    /// })
191    /// .run();
192    /// ```
193    fn transparent(self, flag: bool) -> Self;
194    /// Sets whether the window has decorations.
195    ///
196    /// # Example
197    /// ```no_run
198    /// # use vizia_core::prelude::*;
199    /// # use vizia_winit::application::Application;
200    /// # use vizia_winit::window::Window;
201    /// # use vizia_winit::window_modifiers::WindowModifiers;
202    /// Application::new(|cx| {
203    ///     Window::new(cx, |cx| {
204    ///         // Content here
205    ///     })
206    ///     .decorations(false);
207    /// })
208    /// .run();
209    /// ```
210    fn decorations(self, flag: bool) -> Self;
211    /// Sets whether the window should be on top of other windows.
212    ///
213    /// # Example
214    /// ```no_run
215    /// # use vizia_core::prelude::*;
216    /// # use vizia_winit::application::Application;
217    /// # use vizia_winit::window::Window;
218    /// # use vizia_winit::window_modifiers::WindowModifiers;
219    /// Application::new(|cx| {
220    ///     Window::new(cx, |cx| {
221    ///         // Content here
222    ///     })
223    ///     .always_on_top(true);
224    /// })
225    /// .run();
226    /// ```
227    fn always_on_top(self, flag: bool) -> Self;
228    /// Sets whether the window has vsync enabled.
229    ///
230    /// # Example
231    /// ```no_run
232    /// # use vizia_core::prelude::*;
233    /// # use vizia_winit::application::Application;
234    /// # use vizia_winit::window::Window;
235    /// # use vizia_winit::window_modifiers::WindowModifiers;
236    /// Application::new(|cx| {
237    ///     Window::new(cx, |cx| {
238    ///         // Content here
239    ///     })
240    ///     .vsync(true);
241    /// })
242    /// .run();
243    /// ```
244    fn vsync(self, flag: bool) -> Self;
245    /// Sets the maximum number of bytes Skia may use for cached GPU resources.
246    fn skia_resource_cache_limit(self, limit: usize) -> Self;
247    /// Sets the icon used for the window.
248    ///
249    /// # Example
250    /// ```no_run, ignore
251    /// # use vizia_core::prelude::*;
252    /// # use vizia_winit::application::Application;
253    /// # use vizia_winit::window::Window;
254    /// # use vizia_winit::window_modifiers::WindowModifiers;
255    ///
256    /// let icon = vizia::image::load_from_memory(include_bytes!("../icon.png"))
257    ///     .expect("Failed to load icon");
258    ///
259    /// Application::new(|cx| {
260    ///     Window::new(cx, |cx| {
261    ///         // Content here
262    ///     })
263    ///     .icon(icon.width(), icon.height(), icon.into_bytes());
264    /// })
265    /// .run();
266    /// ```
267    fn icon(self, width: u32, height: u32, image: Vec<u8>) -> Self;
268
269    fn enabled_window_buttons(self, window_buttons: WindowButtons) -> Self;
270}