fix: refactor dnd impl to support responsive widget
This commit is contained in:
parent
9af083e0c5
commit
173ddca60f
12 changed files with 61 additions and 27 deletions
2
iced
2
iced
|
|
@ -1 +1 @@
|
||||||
Subproject commit 34973a56d512d11c1c3c343e2cb5c4c979d15e9c
|
Subproject commit 9ce8c6becc655be8448bbf069421ae2ddab1a18c
|
||||||
|
|
@ -247,11 +247,15 @@ impl<'a, Message: Clone> Widget<Message, crate::Theme, Renderer> for ContextDraw
|
||||||
&self,
|
&self,
|
||||||
state: &Tree,
|
state: &Tree,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
|
renderer: &Renderer,
|
||||||
dnd_rectangles: &mut iced_core::clipboard::DndDestinationRectangles,
|
dnd_rectangles: &mut iced_core::clipboard::DndDestinationRectangles,
|
||||||
) {
|
) {
|
||||||
self.content
|
self.content.as_widget().drag_destinations(
|
||||||
.as_widget()
|
&state.children[0],
|
||||||
.drag_destinations(&state.children[0], layout, dnd_rectangles);
|
layout,
|
||||||
|
renderer,
|
||||||
|
dnd_rectangles,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id(&self) -> Option<iced_core::widget::Id> {
|
fn id(&self) -> Option<iced_core::widget::Id> {
|
||||||
|
|
|
||||||
|
|
@ -506,6 +506,7 @@ impl<'a, Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
&self,
|
&self,
|
||||||
state: &Tree,
|
state: &Tree,
|
||||||
layout: layout::Layout<'_>,
|
layout: layout::Layout<'_>,
|
||||||
|
renderer: &crate::Renderer,
|
||||||
dnd_rectangles: &mut iced_core::clipboard::DndDestinationRectangles,
|
dnd_rectangles: &mut iced_core::clipboard::DndDestinationRectangles,
|
||||||
) {
|
) {
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
|
|
@ -524,9 +525,12 @@ impl<'a, Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
};
|
};
|
||||||
dnd_rectangles.push(my_dest);
|
dnd_rectangles.push(my_dest);
|
||||||
|
|
||||||
self.container
|
self.container.as_widget().drag_destinations(
|
||||||
.as_widget()
|
&state.children[0],
|
||||||
.drag_destinations(&state.children[0], layout, dnd_rectangles);
|
layout,
|
||||||
|
renderer,
|
||||||
|
dnd_rectangles,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id(&self) -> Option<Id> {
|
fn id(&self) -> Option<Id> {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::any::Any;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
iced::{
|
iced::{
|
||||||
clipboard::dnd::{DndAction, DndEvent, SourceEvent},
|
clipboard::dnd::{DndAction, DndEvent, SourceEvent},
|
||||||
|
|
@ -167,9 +169,12 @@ impl<
|
||||||
iced_core::widget::OperationOutputWrapper<Message>,
|
iced_core::widget::OperationOutputWrapper<Message>,
|
||||||
>,
|
>,
|
||||||
) {
|
) {
|
||||||
self.container
|
operation.custom((&mut tree.state) as &mut dyn Any, Some(&self.id));
|
||||||
.as_widget()
|
operation.container(Some(&self.id), layout.bounds(), &mut |operation| {
|
||||||
.operate(&mut tree.children[0], layout, renderer, operation);
|
self.container
|
||||||
|
.as_widget()
|
||||||
|
.operate(&mut tree.children[0], layout, renderer, operation)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_event(
|
fn on_event(
|
||||||
|
|
@ -205,6 +210,7 @@ impl<
|
||||||
}
|
}
|
||||||
|
|
||||||
state.left_pressed_position = Some(position);
|
state.left_pressed_position = Some(position);
|
||||||
|
// dbg!(&state, &self.id);
|
||||||
return event::Status::Captured;
|
return event::Status::Captured;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -223,6 +229,7 @@ impl<
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if let Some(left_pressed_position) = state.left_pressed_position {
|
if let Some(left_pressed_position) = state.left_pressed_position {
|
||||||
|
// dbg!(&state);
|
||||||
if position.distance(left_pressed_position) > self.drag_threshold {
|
if position.distance(left_pressed_position) > self.drag_threshold {
|
||||||
self.start_dnd(clipboard, state.cached_bounds);
|
self.start_dnd(clipboard, state.cached_bounds);
|
||||||
state.is_dragging = true;
|
state.is_dragging = true;
|
||||||
|
|
@ -311,11 +318,15 @@ impl<
|
||||||
&self,
|
&self,
|
||||||
state: &Tree,
|
state: &Tree,
|
||||||
layout: layout::Layout<'_>,
|
layout: layout::Layout<'_>,
|
||||||
|
renderer: &crate::Renderer,
|
||||||
dnd_rectangles: &mut iced_style::core::clipboard::DndDestinationRectangles,
|
dnd_rectangles: &mut iced_style::core::clipboard::DndDestinationRectangles,
|
||||||
) {
|
) {
|
||||||
self.container
|
self.container.as_widget().drag_destinations(
|
||||||
.as_widget()
|
&state.children[0],
|
||||||
.drag_destinations(&state.children[0], layout, dnd_rectangles);
|
layout,
|
||||||
|
renderer,
|
||||||
|
dnd_rectangles,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id(&self) -> Option<Id> {
|
fn id(&self) -> Option<Id> {
|
||||||
|
|
@ -340,7 +351,7 @@ impl<
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Local state of the [`MouseListener`].
|
/// Local state of the [`MouseListener`].
|
||||||
#[derive(Default)]
|
#[derive(Debug, Default)]
|
||||||
struct State {
|
struct State {
|
||||||
hovered: bool,
|
hovered: bool,
|
||||||
left_pressed_position: Option<Point>,
|
left_pressed_position: Option<Point>,
|
||||||
|
|
|
||||||
|
|
@ -251,6 +251,7 @@ impl<'a, Message: 'static + Clone> Widget<Message, crate::Theme, Renderer>
|
||||||
&self,
|
&self,
|
||||||
state: &Tree,
|
state: &Tree,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
|
renderer: &Renderer,
|
||||||
dnd_rectangles: &mut iced_style::core::clipboard::DndDestinationRectangles,
|
dnd_rectangles: &mut iced_style::core::clipboard::DndDestinationRectangles,
|
||||||
) {
|
) {
|
||||||
for ((e, layout), state) in self
|
for ((e, layout), state) in self
|
||||||
|
|
@ -260,7 +261,7 @@ impl<'a, Message: 'static + Clone> Widget<Message, crate::Theme, Renderer>
|
||||||
.zip(state.children.iter())
|
.zip(state.children.iter())
|
||||||
{
|
{
|
||||||
e.as_widget()
|
e.as_widget()
|
||||||
.drag_destinations(state, layout, dnd_rectangles);
|
.drag_destinations(state, layout, renderer, dnd_rectangles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -273,6 +273,7 @@ impl<'a, Message: 'static + Clone> Widget<Message, crate::Theme, Renderer> for G
|
||||||
&self,
|
&self,
|
||||||
state: &Tree,
|
state: &Tree,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
|
renderer: &Renderer,
|
||||||
dnd_rectangles: &mut iced_style::core::clipboard::DndDestinationRectangles,
|
dnd_rectangles: &mut iced_style::core::clipboard::DndDestinationRectangles,
|
||||||
) {
|
) {
|
||||||
for ((e, layout), state) in self
|
for ((e, layout), state) in self
|
||||||
|
|
@ -282,7 +283,7 @@ impl<'a, Message: 'static + Clone> Widget<Message, crate::Theme, Renderer> for G
|
||||||
.zip(state.children.iter())
|
.zip(state.children.iter())
|
||||||
{
|
{
|
||||||
e.as_widget()
|
e.as_widget()
|
||||||
.drag_destinations(state, layout, dnd_rectangles);
|
.drag_destinations(state, layout, renderer, dnd_rectangles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -243,6 +243,7 @@ impl<'a, Message: Clone + 'static> Widget<Message, crate::Theme, crate::Renderer
|
||||||
&self,
|
&self,
|
||||||
state: &tree::Tree,
|
state: &tree::Tree,
|
||||||
layout: iced_core::Layout<'_>,
|
layout: iced_core::Layout<'_>,
|
||||||
|
renderer: &crate::Renderer,
|
||||||
dnd_rectangles: &mut iced_style::core::clipboard::DndDestinationRectangles,
|
dnd_rectangles: &mut iced_style::core::clipboard::DndDestinationRectangles,
|
||||||
) {
|
) {
|
||||||
if let Some((child_tree, child_layout)) =
|
if let Some((child_tree, child_layout)) =
|
||||||
|
|
@ -251,6 +252,7 @@ impl<'a, Message: Clone + 'static> Widget<Message, crate::Theme, crate::Renderer
|
||||||
self.header_bar_inner.as_widget().drag_destinations(
|
self.header_bar_inner.as_widget().drag_destinations(
|
||||||
child_tree,
|
child_tree,
|
||||||
child_layout,
|
child_layout,
|
||||||
|
renderer,
|
||||||
dnd_rectangles,
|
dnd_rectangles,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,12 +87,14 @@ where
|
||||||
iced_core::widget::OperationOutputWrapper<Message>,
|
iced_core::widget::OperationOutputWrapper<Message>,
|
||||||
>,
|
>,
|
||||||
) {
|
) {
|
||||||
self.content.as_widget().operate(
|
operation.container(Some(&self.id), layout.bounds(), &mut |operation| {
|
||||||
&mut tree.children[0],
|
self.content.as_widget().operate(
|
||||||
layout.children().next().unwrap(),
|
&mut tree.children[0],
|
||||||
renderer,
|
layout.children().next().unwrap(),
|
||||||
operation,
|
renderer,
|
||||||
);
|
operation,
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_event(
|
fn on_event(
|
||||||
|
|
@ -175,12 +177,14 @@ where
|
||||||
&self,
|
&self,
|
||||||
state: &Tree,
|
state: &Tree,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
|
renderer: &Renderer,
|
||||||
dnd_rectangles: &mut iced_style::core::clipboard::DndDestinationRectangles,
|
dnd_rectangles: &mut iced_style::core::clipboard::DndDestinationRectangles,
|
||||||
) {
|
) {
|
||||||
let content_layout = layout.children().next().unwrap();
|
let content_layout = layout.children().next().unwrap();
|
||||||
self.content.as_widget().drag_destinations(
|
self.content.as_widget().drag_destinations(
|
||||||
&state.children[0],
|
&state.children[0],
|
||||||
content_layout,
|
content_layout,
|
||||||
|
renderer,
|
||||||
dnd_rectangles,
|
dnd_rectangles,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -256,10 +256,11 @@ where
|
||||||
&self,
|
&self,
|
||||||
state: &Tree,
|
state: &Tree,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
|
renderer: &Renderer,
|
||||||
dnd_rectangles: &mut iced_style::core::clipboard::DndDestinationRectangles,
|
dnd_rectangles: &mut iced_style::core::clipboard::DndDestinationRectangles,
|
||||||
) {
|
) {
|
||||||
self.container
|
self.container
|
||||||
.drag_destinations(state, layout, dnd_rectangles);
|
.drag_destinations(state, layout, renderer, dnd_rectangles);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id(&self) -> Option<crate::widget::Id> {
|
fn id(&self) -> Option<crate::widget::Id> {
|
||||||
|
|
|
||||||
|
|
@ -247,11 +247,15 @@ where
|
||||||
&self,
|
&self,
|
||||||
tree: &Tree,
|
tree: &Tree,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
|
renderer: &Renderer,
|
||||||
dnd_rectangles: &mut iced_core::clipboard::DndDestinationRectangles,
|
dnd_rectangles: &mut iced_core::clipboard::DndDestinationRectangles,
|
||||||
) {
|
) {
|
||||||
self.content
|
self.content.as_widget().drag_destinations(
|
||||||
.as_widget()
|
&tree.children[0],
|
||||||
.drag_destinations(&tree.children[0], layout, dnd_rectangles);
|
layout,
|
||||||
|
renderer,
|
||||||
|
dnd_rectangles,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -296,10 +296,11 @@ where
|
||||||
&self,
|
&self,
|
||||||
state: &Tree,
|
state: &Tree,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
|
renderer: &Renderer,
|
||||||
dnd_rectangles: &mut iced_style::core::clipboard::DndDestinationRectangles,
|
dnd_rectangles: &mut iced_style::core::clipboard::DndDestinationRectangles,
|
||||||
) {
|
) {
|
||||||
self.container
|
self.container
|
||||||
.drag_destinations(state, layout, dnd_rectangles);
|
.drag_destinations(state, layout, renderer, dnd_rectangles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1529,6 +1529,7 @@ where
|
||||||
&self,
|
&self,
|
||||||
_state: &Tree,
|
_state: &Tree,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
|
_renderer: &Renderer,
|
||||||
dnd_rectangles: &mut iced_core::clipboard::DndDestinationRectangles,
|
dnd_rectangles: &mut iced_core::clipboard::DndDestinationRectangles,
|
||||||
) {
|
) {
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue