Skip to content

Commit

Permalink
fix content_insets for gtk backend
Browse files Browse the repository at this point in the history
Signed-off-by: Dietmar Maurer <[email protected]>
  • Loading branch information
maurerdietmar committed Jan 18, 2022
1 parent cb3da65 commit 30b1a71
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions druid-shell/src/backend/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,25 +1009,33 @@ impl WindowHandle {
}
}

/// The GTK implementation of content_insets differs from, e.g., the Windows one in that it
/// doesn't try to account for window decorations. Depending on the platform, GTK might not
/// even be aware of the size of the window decorations. And anyway, GTK's `Window::resize`
/// function [tries not to include] the window decorations, so it makes sense not to include
/// them here either.
///
/// [tries not to include]: https://developer.gnome.org/gtk3/stable/GtkWidget.html#geometry-management
pub fn content_insets(&self) -> Insets {
if let Some(state) = self.state.upgrade() {
let scale = state.scale.get();
let (width_px, height_px) = state.window.size();
let alloc_px = state.drawing_area.allocation();
let window = Size::new(width_px as f64, height_px as f64).to_dp(scale);
let alloc = Rect::from_origin_size(
(alloc_px.x as f64, alloc_px.y as f64),
(alloc_px.width as f64, alloc_px.height as f64),
)
.to_dp(scale);
window.to_rect() - alloc
let menu_height_px = height_px - alloc_px.height;

if let Some(window) = state.window.window() {
let frame = window.frame_extents();
let (pos_x, pos_y) = window.position();
Insets::new(
(pos_x - frame.x) as f64,
(pos_y - frame.y + menu_height_px) as f64,
(frame.x + frame.width - (pos_x + width_px)) as f64,
(frame.y + frame.height - (pos_y + height_px)) as f64,
)
.to_dp(scale)
.nonnegative()
} else {
let window = Size::new(width_px as f64, height_px as f64).to_dp(scale);
let alloc = Rect::from_origin_size(
(alloc_px.x as f64, alloc_px.y as f64),
(alloc_px.width as f64, alloc_px.height as f64),
)
.to_dp(scale);
window.to_rect() - alloc
}
} else {
Insets::ZERO
}
Expand Down

0 comments on commit 30b1a71

Please sign in to comment.