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