diff options
author | 2022-06-07 07:30:44 +0800 | |
---|---|---|
committer | 2022-06-07 07:30:44 +0800 | |
commit | 20780f36d1c00666140b31e8192e74e1cf36570c (patch) | |
tree | 885a0df6ff97be019ad72b481ee3f35eb638d970 /pure | |
parent | 260bbc5690b921e678d02eeb7a558c48874544d0 (diff) | |
download | iced-20780f36d1c00666140b31e8192e74e1cf36570c.tar.gz iced-20780f36d1c00666140b31e8192e74e1cf36570c.tar.bz2 iced-20780f36d1c00666140b31e8192e74e1cf36570c.zip |
Prevent pane grid title bar content and controls from overlapping
Diffstat (limited to 'pure')
-rw-r--r-- | pure/src/widget/pane_grid/title_bar.rs | 78 |
1 files changed, 50 insertions, 28 deletions
diff --git a/pure/src/widget/pane_grid/title_bar.rs b/pure/src/widget/pane_grid/title_bar.rs index 4a7c8c17..af71dc43 100644 --- a/pure/src/widget/pane_grid/title_bar.rs +++ b/pure/src/widget/pane_grid/title_bar.rs @@ -132,18 +132,15 @@ where let mut children = padded.children(); let title_layout = children.next().unwrap(); - - self.content.as_widget().draw( - &tree.children[0], - renderer, - &inherited_style, - title_layout, - cursor_position, - viewport, - ); + let mut show_title = true; if let Some(controls) = &self.controls { let controls_layout = children.next().unwrap(); + if title_layout.bounds().width + controls_layout.bounds().width + > padded.bounds().width + { + show_title = false; + } if show_controls || self.always_show_controls { controls.as_widget().draw( @@ -156,6 +153,17 @@ where ); } } + + if show_title { + self.content.as_widget().draw( + &tree.children[0], + renderer, + &inherited_style, + title_layout, + cursor_position, + viewport, + ); + } } /// Returns whether the mouse cursor is over the pick area of the @@ -247,9 +255,15 @@ where let mut children = padded.children(); let title_layout = children.next().unwrap(); + let mut show_title = true; let control_status = if let Some(controls) = &mut self.controls { let controls_layout = children.next().unwrap(); + if title_layout.bounds().width + controls_layout.bounds().width + > padded.bounds().width + { + show_title = false; + } controls.as_widget_mut().on_event( &mut tree.children[1], @@ -264,15 +278,19 @@ where event::Status::Ignored }; - let title_status = self.content.as_widget_mut().on_event( - &mut tree.children[0], - event, - title_layout, - cursor_position, - renderer, - clipboard, - shell, - ); + let title_status = if show_title { + self.content.as_widget_mut().on_event( + &mut tree.children[0], + event, + title_layout, + cursor_position, + renderer, + clipboard, + shell, + ) + } else { + event::Status::Ignored + }; control_status.merge(title_status) } @@ -301,17 +319,21 @@ where if let Some(controls) = &self.controls { let controls_layout = children.next().unwrap(); + let controls_interaction = controls.as_widget().mouse_interaction( + &tree.children[1], + controls_layout, + cursor_position, + viewport, + renderer, + ); - controls - .as_widget() - .mouse_interaction( - &tree.children[1], - controls_layout, - cursor_position, - viewport, - renderer, - ) - .max(title_interaction) + if title_layout.bounds().width + controls_layout.bounds().width + > padded.bounds().width + { + controls_interaction + } else { + controls_interaction.max(title_interaction) + } } else { title_interaction } |