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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//! Configure your application.
use baseview::{
ParentWindowHandle,
dpi::{LogicalSize, Size},
};
use raw_window_handle::HasWindowHandle;
/// Any settings specific to `iced_baseview`.
#[derive(Debug, Clone, PartialEq)]
pub struct IcedWindowSettings {
/// The window title.
pub title: String,
/// The size of the window, either in physical or logical coordinates.
pub size: Size,
/// The minimum window size. Set to `None` for no minimum size.
pub min_size: Option<Size>,
/// The maximum window size. Set to `None` for no maximum size.
pub max_size: Option<Size>,
/// Whether the window can be resized.
pub resizable: bool,
/// The amount of zoom (scaling) to apply. This is applied on top of the
/// system's native scaling factor.
pub scale_factor: f32,
/// If the window is to be embedded in a parent window, the handle to that window.
///
/// If `None`, the window will be standalone.
pub parent: Option<ParentWindowHandle>,
/// If the window expects to have a parent when first displayed.
///
/// Setting this will delay the actual creation of the window until the parent is set (unless
/// the window is shown first).
///
/// If the `parent` field is already set, this does nothing and is ignored.
pub wait_for_parent: bool,
/// Ignore key inputs, except for modifier keys such as SHIFT and ALT
pub ignore_non_modifier_keys: bool,
/// Always redraw whenever the baseview window updates instead of only when iced wants to update
/// the window. This works around a current baseview limitation where it does not support
/// trigger a redraw on window visibility change (which may cause blank windows when opening or
/// reopening the editor) and an iced limitation where it's not possible to have animations
/// without using an asynchronous timer stream to send redraw messages to the application.
pub always_redraw: bool,
/// A fallback scale factor, if Baseview couldn't get one from the platform.
///
/// If the platform does already provide an accurate scaling factor, this doesn't do anything.
///
/// If the given fallback scale factor is actually useful and different from the current one
/// (1.0 by default), this will resize and redraw the window accordingly.
///
/// # Platform compatibility notes.
///
/// On Win32, this value is used if running on early versions of Windows 10 (or earlier).
///
/// On X11, this value is used if no `Xft.dpi`setting is set.
///
/// On macOS, this function is always a no-op.
pub fallback_scale_factor: Option<f64>,
}
impl IcedWindowSettings {
#[inline]
pub fn new() -> Self {
Self::default()
}
/// The window title.
#[inline]
pub fn with_title(mut self, title: impl Into<String>) -> Self {
self.title = title.into();
self
}
/// The size of the window, in logical coordinates.
#[inline]
pub fn with_size(mut self, size: impl Into<Size>) -> Self {
self.size = size.into();
self
}
/// Sets whether the window can be resized.
///
/// Defaults to `true`.
#[inline]
pub fn with_resizable(mut self, resizable: bool) -> Self {
self.resizable = resizable;
self
}
/// The minimum window size. Set to `None` for no minimum size.
///
/// Defaults to `None`.
#[inline]
pub fn with_min_size<S: Into<Size>>(mut self, min_size: Option<S>) -> Self {
self.min_size = min_size.map(|s| s.into());
self
}
/// The maximum window size. Set to `None` for no maximum size.
///
/// Defaults to `None`.
#[inline]
pub fn with_max_size<S: Into<Size>>(mut self, max_size: Option<S>) -> Self {
self.max_size = max_size.map(|s| s.into());
self
}
/// The amount of zoom (scaling) to apply. This is applied on top of the
/// system's native scaling factor.
#[inline]
pub fn with_scale_factor(mut self, scale_factor: f32) -> Self {
self.scale_factor = scale_factor;
self
}
/// If the window is to be embedded in a parent window, the handle to that window.
///
/// If `None`, the window will be standalone.
#[inline]
pub fn with_parent<'a, P: HasWindowHandle + 'a>(
mut self,
parent: impl Into<Option<&'a P>>,
) -> Self {
self.parent = parent.into().map(ParentWindowHandle::from_window);
self
}
/// Sets [`wait_for_parent`](Self::wait_for_parent) to the given value.
pub fn with_wait_for_parent(mut self, wait_for_parent: bool) -> Self {
self.wait_for_parent = wait_for_parent;
self
}
/// Sets [`wait_for_parent`](Self::wait_for_parent) to `true`.
#[inline]
pub fn wait_for_parent(mut self) -> Self {
self.wait_for_parent = true;
self
}
/// Sets [`fallback_scale_factor`](Self::fallback_scale_factor) to the given value.
#[inline]
pub fn with_fallback_scale_factor(mut self, scale_factor: impl Into<Option<f64>>) -> Self {
self.fallback_scale_factor = scale_factor.into();
self
}
/// Ignore key inputs, except for modifier keys such as SHIFT and ALT.
///
/// This may help with misbehaving DAWs in some cases.
#[inline]
pub fn with_ignore_non_modifier_keys(mut self, ignore: bool) -> Self {
self.ignore_non_modifier_keys = ignore;
self
}
/// Always redraw whenever the baseview window updates instead of only when iced wants to update
/// the window. This works around a current baseview limitation where it does not support
/// trigger a redraw on window visibility change (which may cause blank windows when opening or
/// reopening the editor) and an iced limitation where it's not possible to have animations
/// without using an asynchronous timer stream to send redraw messages to the application.
#[inline]
pub fn with_always_redraw(mut self, always_redraw: bool) -> Self {
self.always_redraw = always_redraw;
self
}
}
impl Default for IcedWindowSettings {
fn default() -> Self {
Self {
title: String::new(),
size: Size::Logical(LogicalSize {
width: 300.0,
height: 200.0,
}),
min_size: None,
max_size: None,
resizable: true,
scale_factor: 1.0,
parent: None,
wait_for_parent: false,
ignore_non_modifier_keys: false,
always_redraw: false,
fallback_scale_factor: None,
}
}
}