Skip to content

Commit

Permalink
Merge pull request #444 from kas-gui/work
Browse files Browse the repository at this point in the history
Fix window sizing
  • Loading branch information
dhardy committed Feb 27, 2024
2 parents 4f37071 + 7ae183c commit 49ce75b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
25 changes: 11 additions & 14 deletions crates/kas-core/src/app/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ impl<A: AppData, G: AppGraphicsBuilder, T: Theme<G::Shared>> Window<A, G, T> {

// Now that we have a scale factor, we may need to resize:
let scale_factor = window.scale_factor();
let apply_size;
if scale_factor != 1.0 {
let sf32 = scale_factor as f32;
state.shared.theme.update_window(&mut theme_window, sf32);
Expand All @@ -142,20 +141,18 @@ impl<A: AppData, G: AppGraphicsBuilder, T: Theme<G::Shared>> Window<A, G, T> {

if let Some(size) = window.request_inner_size(ideal) {
debug_assert_eq!(size, window.inner_size());
apply_size = true;
} else {
// We will receive WindowEvent::Resized
apply_size = false;
// We will receive WindowEvent::Resized and resize then.
// Unfortunately we can't rely on this since some platforms (X11)
// don't always behave as expected, thus we must resize now.
}
} else {
apply_size = true;
}

let size: Size = window.inner_size().cast();
log::info!(
"new: constructed with physical size {:?}, scale factor {}",
"Window::resume: constructed with physical size {:?}, scale factor {}",
size,
scale_factor
scale_factor,
);

#[cfg(all(wayland_platform, feature = "clipboard"))]
Expand All @@ -174,9 +171,7 @@ impl<A: AppData, G: AppGraphicsBuilder, T: Theme<G::Shared>> Window<A, G, T> {
// NOTE: usage of Arc is inelegant, but avoids lots of unsafe code
let window = Arc::new(window);
let mut surface = G::new_surface(&mut state.shared.draw.draw, window.clone())?;
if apply_size {
surface.do_resize(&mut state.shared.draw.draw, size);
}
surface.do_resize(&mut state.shared.draw.draw, size);

let winit_id = window.id();

Expand All @@ -194,9 +189,7 @@ impl<A: AppData, G: AppGraphicsBuilder, T: Theme<G::Shared>> Window<A, G, T> {
queued_frame_time: Some(time),
});

if apply_size {
self.apply_size(state, true);
}
self.apply_size(state, true);

log::trace!(target: "kas_perf::wgpu::window", "resume: {}µs", time.elapsed().as_micros());
Ok(winit_id)
Expand All @@ -219,6 +212,7 @@ impl<A: AppData, G: AppGraphicsBuilder, T: Theme<G::Shared>> Window<A, G, T> {
let Some(ref mut window) = self.window else {
return false;
};

match event {
WindowEvent::Moved(_) | WindowEvent::Destroyed => false,
WindowEvent::Resized(size) => {
Expand Down Expand Up @@ -272,6 +266,7 @@ impl<A: AppData, G: AppGraphicsBuilder, T: Theme<G::Shared>> Window<A, G, T> {
let Some(ref window) = self.window else {
return (Action::empty(), None);
};

let mut messages = MessageStack::new();
let action = self.ev_state.flush_pending(
&mut state.shared,
Expand Down Expand Up @@ -346,6 +341,7 @@ impl<A: AppData, G: AppGraphicsBuilder, T: Theme<G::Shared>> Window<A, G, T> {
let Some(ref window) = self.window else {
return None;
};

let widget = self.widget.as_node(&state.data);
let mut messages = MessageStack::new();
self.ev_state
Expand All @@ -365,6 +361,7 @@ impl<A: AppData, G: AppGraphicsBuilder, T: Theme<G::Shared>> Window<A, G, T> {
let Some(ref window) = self.window else {
return;
};

let mut messages = MessageStack::new();
self.ev_state
.with(&mut state.shared, window, &mut messages, |cx| {
Expand Down
2 changes: 1 addition & 1 deletion crates/kas-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ pub fn collection(input: TokenStream) -> TokenStream {
///
/// For example usage, see [`Grid`](https://docs.rs/kas/latest/kas/widgets/struct.Grid.html).
///
/// [`kas::Collection`]: https://docs.rs/kas/latest/kas/trait.Collection.html
/// [`kas::CellCollection`]: https://docs.rs/kas/latest/kas/trait.CellCollection.html
#[proc_macro_error]
#[proc_macro]
pub fn cell_collection(input: TokenStream) -> TokenStream {
Expand Down

0 comments on commit 49ce75b

Please sign in to comment.