Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent pane grid title bar content and controls from overlapping #1361

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 47 additions & 24 deletions native/src/widget/pane_grid/title_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,17 @@ where

let mut children = padded.children();
let title_layout = children.next().unwrap();

self.content.draw(
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 show_controls || self.always_show_controls {
if title_layout.bounds().width + controls_layout.bounds().width
> padded.bounds().width
{
show_title = false;
}
controls.draw(
renderer,
&inherited_style,
Expand All @@ -127,6 +125,16 @@ where
);
}
}

if show_title {
self.content.draw(
renderer,
&inherited_style,
title_layout,
cursor_position,
viewport,
);
}
}

/// Returns whether the mouse cursor is over the pick area of the
Expand Down Expand Up @@ -214,9 +222,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.on_event(
event.clone(),
Expand All @@ -230,14 +244,18 @@ where
event::Status::Ignored
};

let title_status = self.content.on_event(
event,
title_layout,
cursor_position,
renderer,
clipboard,
shell,
);
let title_status = if show_title {
self.content.on_event(
event,
title_layout,
cursor_position,
renderer,
clipboard,
shell,
)
} else {
event::Status::Ignored
};

control_status.merge(title_status)
}
Expand All @@ -264,15 +282,20 @@ where

if let Some(controls) = &self.controls {
let controls_layout = children.next().unwrap();
let controls_interaction = controls.mouse_interaction(
controls_layout,
cursor_position,
viewport,
renderer,
);

controls
.mouse_interaction(
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
}
Expand Down
78 changes: 50 additions & 28 deletions pure/src/widget/pane_grid/title_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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],
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down