summaryrefslogtreecommitdiffstats
path: root/native/src/widget/pane_grid
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-25 16:16:35 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-25 16:35:02 +0700
commit4a11cbd99445338619dfaf1f327dbc25b2983cb7 (patch)
tree254598ff97f17cb33e44bd1402323d3b6892cb6b /native/src/widget/pane_grid
parent41394b4e90a81a43c796c070e706e6aa4d8652bc (diff)
downloadiced-4a11cbd99445338619dfaf1f327dbc25b2983cb7.tar.gz
iced-4a11cbd99445338619dfaf1f327dbc25b2983cb7.tar.bz2
iced-4a11cbd99445338619dfaf1f327dbc25b2983cb7.zip
Implement `Widget::mouse_interaction` for `PaneGrid`
... and fix rendering of drag interaction in `PaneGrid` by introducing an explicit `with_translation` method to `Renderer` and simplifying the `with_layer` and `Clip` primitive.
Diffstat (limited to 'native/src/widget/pane_grid')
-rw-r--r--native/src/widget/pane_grid/content.rs36
-rw-r--r--native/src/widget/pane_grid/title_bar.rs30
2 files changed, 66 insertions, 0 deletions
diff --git a/native/src/widget/pane_grid/content.rs b/native/src/widget/pane_grid/content.rs
index e74e3c84..ddc659cc 100644
--- a/native/src/widget/pane_grid/content.rs
+++ b/native/src/widget/pane_grid/content.rs
@@ -1,6 +1,7 @@
use crate::container;
use crate::event::{self, Event};
use crate::layout;
+use crate::mouse;
use crate::overlay;
use crate::pane_grid::TitleBar;
use crate::renderer;
@@ -194,6 +195,41 @@ where
event_status.merge(body_status)
}
+ pub(crate) fn mouse_interaction(
+ &self,
+ layout: Layout<'_>,
+ viewport: &Rectangle,
+ cursor_position: Point,
+ ) -> mouse::Interaction {
+ let mut children = layout.children();
+
+ let (body_layout, title_bar_interaction) =
+ if let Some(title_bar) = &self.title_bar {
+ let title_bar_layout = children.next().unwrap();
+
+ let is_over_pick_area = title_bar
+ .is_over_pick_area(title_bar_layout, cursor_position);
+
+ if is_over_pick_area {
+ return mouse::Interaction::Grab;
+ }
+
+ let mouse_interaction = title_bar.mouse_interaction(
+ title_bar_layout,
+ viewport,
+ cursor_position,
+ );
+
+ (children.next().unwrap(), mouse_interaction)
+ } else {
+ (children.next().unwrap(), mouse::Interaction::default())
+ };
+
+ self.body
+ .mouse_interaction(body_layout, viewport, cursor_position)
+ .max(title_bar_interaction)
+ }
+
pub(crate) fn hash_layout(&self, state: &mut Hasher) {
if let Some(title_bar) = &self.title_bar {
title_bar.hash_layout(state);
diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs
index 161eb9bc..493c74db 100644
--- a/native/src/widget/pane_grid/title_bar.rs
+++ b/native/src/widget/pane_grid/title_bar.rs
@@ -1,6 +1,7 @@
use crate::container;
use crate::event::{self, Event};
use crate::layout;
+use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::{
@@ -249,6 +250,35 @@ where
control_status.merge(title_status)
}
+ pub(crate) fn mouse_interaction(
+ &self,
+ layout: Layout<'_>,
+ viewport: &Rectangle,
+ cursor_position: Point,
+ ) -> mouse::Interaction {
+ let mut children = layout.children();
+ let padded = children.next().unwrap();
+
+ let mut children = padded.children();
+ let title_layout = children.next().unwrap();
+
+ let title_interaction = self.content.mouse_interaction(
+ title_layout,
+ viewport,
+ cursor_position,
+ );
+
+ if let Some(controls) = &self.controls {
+ let controls_layout = children.next().unwrap();
+
+ controls
+ .mouse_interaction(controls_layout, viewport, cursor_position)
+ .max(title_interaction)
+ } else {
+ title_interaction
+ }
+ }
+
pub(crate) fn overlay(
&mut self,
layout: Layout<'_>,