Skip to content

Commit a9f14ea

Browse files
committed
Implement resizing for the baseview backend
Now that RustAudio/baseview#136 has been merged.
1 parent 0010cff commit a9f14ea

File tree

1 file changed

+50
-57
lines changed

1 file changed

+50
-57
lines changed

crates/vizia_baseview/src/application.rs

Lines changed: 50 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl ApplicationRunner {
187187

188188
/// Handle all reactivity within a frame. The window instance is used to resize the window when
189189
/// needed.
190-
pub fn on_frame_update(&mut self, _window: &mut Window) {
190+
pub fn on_frame_update(&mut self, window: &mut Window) {
191191
let mut cx = BackendContext::new(&mut self.context);
192192

193193
while let Some(event) = queue_get() {
@@ -200,62 +200,55 @@ impl ApplicationRunner {
200200
if *cx.window_size() != self.current_window_size
201201
|| *cx.user_scale_factor() != self.current_user_scale_factor
202202
{
203-
// TODO: This functionality has not yet been merged into baseview, so we'll just pretend
204-
// nothing happened for now to prevent widgets from relying on the wrong
205-
// information
206-
*cx.window_size() = self.current_window_size;
207-
*cx.user_scale_factor() = self.current_user_scale_factor;
208-
209-
// self.current_window_size = *cx.window_size();
210-
// self.current_user_scale_factor = *cx.user_scale_factor();
211-
212-
// // The user scale factor is not part of the HiDPI scaling, so baseview should treat it
213-
// // as part of our logical size
214-
// #[cfg(target_os = "linux")]
215-
// window.resize(baseview::Size {
216-
// width: self.current_window_size.width as f64 * self.current_user_scale_factor,
217-
// height: self.current_window_size.height as f64 * self.current_user_scale_factor,
218-
// });
219-
220-
// // TODO: These calculations are now repeated in three places, should probably be moved
221-
// // to a function
222-
// cx.style().dpi_factor = self.window_scale_factor * self.current_user_scale_factor;
223-
// cx.style()
224-
// .width
225-
// .insert(Entity::root(), Units::Pixels(self.current_window_size.width as f32));
226-
// cx.style()
227-
// .height
228-
// .insert(Entity::root(), Units::Pixels(self.current_window_size.height as f32));
229-
230-
// let new_physical_width =
231-
// self.current_window_size.width as f32 * cx.style().dpi_factor as f32;
232-
// let new_physical_height =
233-
// self.current_window_size.height as f32 * cx.style().dpi_factor as f32;
234-
// cx.cache().set_width(Entity::root(), new_physical_width);
235-
// cx.cache().set_height(Entity::root(), new_physical_height);
236-
237-
// cx.cache().set_clip_region(
238-
// Entity::root(),
239-
// BoundingBox {
240-
// w: new_physical_width,
241-
// h: new_physical_height,
242-
// ..BoundingBox::default()
243-
// },
244-
// );
245-
246-
// cx.0.need_restyle();
247-
// cx.0.need_relayout();
248-
// cx.0.need_redraw();
249-
250-
// // After the window is resized, we should let every view know about this so they can act
251-
// // accordingly
252-
// cx.0.emit_custom(
253-
// Event::new(WindowEvent::WindowResize)
254-
// .target(Entity::root())
255-
// .origin(Entity::root())
256-
// .propagate(Propagation::Subtree),
257-
// );
258-
// self.event_manager.flush_events(cx.context());
203+
self.current_window_size = *cx.window_size();
204+
self.current_user_scale_factor = *cx.user_scale_factor();
205+
206+
// The user scale factor is not part of the HiDPI scaling, so baseview should treat it
207+
// as part of our logical size
208+
window.resize(baseview::Size {
209+
width: self.current_window_size.width as f64 * self.current_user_scale_factor,
210+
height: self.current_window_size.height as f64 * self.current_user_scale_factor,
211+
});
212+
213+
// TODO: These calculations are now repeated in three places, should probably be moved
214+
// to a function
215+
cx.style().dpi_factor = self.window_scale_factor * self.current_user_scale_factor;
216+
cx.style()
217+
.width
218+
.insert(Entity::root(), Units::Pixels(self.current_window_size.width as f32));
219+
cx.style()
220+
.height
221+
.insert(Entity::root(), Units::Pixels(self.current_window_size.height as f32));
222+
223+
let new_physical_width =
224+
self.current_window_size.width as f32 * cx.style().dpi_factor as f32;
225+
let new_physical_height =
226+
self.current_window_size.height as f32 * cx.style().dpi_factor as f32;
227+
cx.cache().set_width(Entity::root(), new_physical_width);
228+
cx.cache().set_height(Entity::root(), new_physical_height);
229+
230+
cx.cache().set_clip_region(
231+
Entity::root(),
232+
BoundingBox {
233+
w: new_physical_width,
234+
h: new_physical_height,
235+
..BoundingBox::default()
236+
},
237+
);
238+
239+
cx.0.need_restyle();
240+
cx.0.need_relayout();
241+
cx.0.need_redraw();
242+
243+
// After the window is resized, we should let every view know about this so they can act
244+
// accordingly
245+
cx.0.emit_custom(
246+
Event::new(WindowEvent::WindowResize)
247+
.target(Entity::root())
248+
.origin(Entity::root())
249+
.propagate(Propagation::Subtree),
250+
);
251+
self.event_manager.flush_events(cx.context());
259252
}
260253

261254
cx.load_images();

0 commit comments

Comments
 (0)