File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed
Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ You can find its changes [documented below](#070---2021-01-01).
3434 context-methods to implement disabled ([ #1632 ] by [ @xarvic ] )
3535- ` LifeCycle::BuildFocusChain ` to update the focus-chain ([ #1632 ] by [ @xarvic ] )
3636- ` DisabledIf ` widget wrapper to disable based on the state of Data and Env ([ #1702 ] by [ @xarvic ] )
37+ - GTK: added support for ` content_insets ` ([ #1722 ] by [ @jneem ] )
38+
3739### Changed
3840
3941- Warn on unhandled Commands ([ #1533 ] by [ @Maan2003 ] )
@@ -685,6 +687,7 @@ Last release without a changelog :(
685687[ #1702 ] : https://github.com/linebender/druid/pull/1702
686688[ #1713 ] : https://github.com/linebender/druid/pull/1713
687689[ #1715 ] : https://github.com/linebender/druid/pull/1715
690+ [ #1722 ] : https://github.com/linebender/druid/pull/1722
688691[ #1724 ] : https://github.com/linebender/druid/pull/1724
689692[ #1730 ] : https://github.com/linebender/druid/pull/1730
690693
Original file line number Diff line number Diff line change @@ -875,9 +875,28 @@ impl WindowHandle {
875875 }
876876 }
877877
878+ /// The GTK implementation of content_insets differs from, e.g., the Windows one in that it
879+ /// doesn't try to account for window decorations. Depending on the platform, GTK might not
880+ /// even be aware of the size of the window decorations. And anyway, GTK's `Window::resize`
881+ /// function [tries not to include] the window decorations, so it makes sense not to include
882+ /// them here either.
883+ ///
884+ /// [tries not to include]: https://developer.gnome.org/gtk3/stable/GtkWidget.html#geometry-management
878885 pub fn content_insets ( & self ) -> Insets {
879- warn ! ( "WindowHandle::content_insets unimplemented for GTK platforms." ) ;
880- Insets :: ZERO
886+ if let Some ( state) = self . state . upgrade ( ) {
887+ let scale = state. scale . get ( ) ;
888+ let ( width_px, height_px) = state. window . get_size ( ) ;
889+ let alloc_px = state. drawing_area . get_allocation ( ) ;
890+ let window = Size :: new ( width_px as f64 , height_px as f64 ) . to_dp ( scale) ;
891+ let alloc = Rect :: from_origin_size (
892+ ( alloc_px. x as f64 , alloc_px. y as f64 ) ,
893+ ( alloc_px. width as f64 , alloc_px. height as f64 ) ,
894+ )
895+ . to_dp ( scale) ;
896+ window. to_rect ( ) - alloc
897+ } else {
898+ Insets :: ZERO
899+ }
881900 }
882901
883902 pub fn set_level ( & self , level : WindowLevel ) {
Original file line number Diff line number Diff line change @@ -232,7 +232,15 @@ impl WindowHandle {
232232
233233 /// Returns the insets of the window content from its position and size in [display points].
234234 ///
235- /// This is to account for any window system provided chrome, eg. title bars.
235+ /// This is to account for any window system provided chrome, e.g. title bars. For example, if
236+ /// you want your window to have room for contents of size `contents`, then you should call
237+ /// [`WindowHandle::get_size`] with an argument of `(contents.to_rect() + insets).size()`,
238+ /// where `insets` is the return value of this function.
239+ ///
240+ /// The details of this function are somewhat platform-dependent. For example, on Windows both
241+ /// the insets and the window size include the space taken up by the title bar and window
242+ /// decorations; on GTK neither the insets nor the window size include the title bar or window
243+ /// decorations.
236244 ///
237245 /// [display points]: crate::Scale
238246 pub fn content_insets ( & self ) -> Insets {
You can’t perform that action at this time.
0 commit comments