summaryrefslogtreecommitdiffstats
path: root/wgpu/src/renderer
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-03-10 06:47:32 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-03-10 06:47:32 +0100
commiteb070b965294707100b16472980f4794162cbc36 (patch)
treec7ff97406f2b31f7b39982b0b458d20c78a1b3a5 /wgpu/src/renderer
parented7c327b488da471dab6df210254d45983890cdf (diff)
downloadiced-eb070b965294707100b16472980f4794162cbc36.tar.gz
iced-eb070b965294707100b16472980f4794162cbc36.tar.bz2
iced-eb070b965294707100b16472980f4794162cbc36.zip
Draft drag and drop support for `PaneGrid`
Diffstat (limited to 'wgpu/src/renderer')
-rw-r--r--wgpu/src/renderer/widget/pane_grid.rs80
1 files changed, 62 insertions, 18 deletions
diff --git a/wgpu/src/renderer/widget/pane_grid.rs b/wgpu/src/renderer/widget/pane_grid.rs
index 022fea70..8fb4a1a9 100644
--- a/wgpu/src/renderer/widget/pane_grid.rs
+++ b/wgpu/src/renderer/widget/pane_grid.rs
@@ -1,34 +1,78 @@
use crate::{Primitive, Renderer};
-use iced_native::{pane_grid, Element, Layout, MouseCursor, Point};
+use iced_native::{
+ pane_grid::{self, Pane},
+ Element, Layout, MouseCursor, Point, Rectangle, Vector,
+};
impl pane_grid::Renderer for Renderer {
fn draw<Message>(
&mut self,
defaults: &Self::Defaults,
- content: &[(pane_grid::Pane, Element<'_, Message, Self>)],
+ content: &[(Pane, Element<'_, Message, Self>)],
+ dragging: Option<Pane>,
layout: Layout<'_>,
cursor_position: Point,
) -> Self::Output {
let mut mouse_cursor = MouseCursor::OutOfBounds;
+ let mut dragged_pane = None;
+
+ let mut panes: Vec<_> = content
+ .iter()
+ .zip(layout.children())
+ .enumerate()
+ .map(|(i, ((id, pane), layout))| {
+ let (primitive, new_mouse_cursor) =
+ pane.draw(self, defaults, layout, cursor_position);
+
+ if new_mouse_cursor > mouse_cursor {
+ mouse_cursor = new_mouse_cursor;
+ }
+
+ if Some(*id) == dragging {
+ dragged_pane = Some((i, layout));
+ }
+
+ primitive
+ })
+ .collect();
+
+ let primitives = if let Some((index, layout)) = dragged_pane {
+ let pane = panes.remove(index);
+ let bounds = layout.bounds();
+
+ // TODO: Fix once proper layering is implemented.
+ // This is a pretty hacky way to achieve layering.
+ let clip = Primitive::Clip {
+ bounds: Rectangle {
+ x: cursor_position.x - bounds.width / 2.0,
+ y: cursor_position.y - bounds.height / 2.0,
+ width: bounds.width + 0.5,
+ height: bounds.height + 0.5,
+ },
+ offset: Vector::new(0, 0),
+ content: Box::new(Primitive::Cached {
+ origin: Point::new(
+ cursor_position.x - bounds.x - bounds.width / 2.0,
+ cursor_position.y - bounds.y - bounds.height / 2.0,
+ ),
+ cache: std::sync::Arc::new(pane),
+ }),
+ };
+
+ panes.push(clip);
+
+ panes
+ } else {
+ panes
+ };
(
- Primitive::Group {
- primitives: content
- .iter()
- .zip(layout.children())
- .map(|((_, pane), layout)| {
- let (primitive, new_mouse_cursor) =
- pane.draw(self, defaults, layout, cursor_position);
-
- if new_mouse_cursor > mouse_cursor {
- mouse_cursor = new_mouse_cursor;
- }
-
- primitive
- })
- .collect(),
+ Primitive::Group { primitives },
+ if dragging.is_some() {
+ MouseCursor::Grabbing
+ } else {
+ mouse_cursor
},
- mouse_cursor,
)
}
}