This commit is contained in:
Ashley Wulber 2026-02-03 16:45:44 -05:00
parent a489a6b790
commit e2918e0de9
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
19 changed files with 9291 additions and 60 deletions

View file

@ -3,20 +3,20 @@ use std::{
sync::atomic::{AtomicU64, Ordering},
};
use iced::{Element, id::Id};
use iced::{
Event, Length, Rectangle,
clipboard::{
dnd::{self, DndAction, DndDestinationRectangle, DndEvent, OfferEvent},
mime::AllowedMimeTypes,
},
event,
id::Internal,
mouse, overlay, Event, Length, Rectangle,
mouse, overlay,
};
use iced::{id::Id, Element};
use iced_core::{
self, layout,
widget::{tree, Tree},
Clipboard, Layout, Shell, Widget,
self, Clipboard, Layout, Shell, Widget, layout,
widget::{Tree, tree},
};
pub fn dnd_destination<'a, Message: 'static>(
@ -318,7 +318,7 @@ impl<'a, Message: 'static> Widget<Message, iced::Theme, iced::Renderer>
}
#[allow(clippy::too_many_lines)]
fn on_event(
fn update(
&mut self,
tree: &mut Tree,
event: Event,
@ -340,7 +340,8 @@ impl<'a, Message: 'static> Widget<Message, iced::Theme, iced::Renderer>
viewport,
);
if matches!(s, event::Status::Captured) {
return event::Status::Captured;
shell.capture_event();
return;
}
let state = tree.state.downcast_mut::<State<()>>();
@ -381,7 +382,8 @@ impl<'a, Message: 'static> Widget<Message, iced::Theme, iced::Renderer>
viewport,
);
}
return event::Status::Captured;
shell.capture_event();
return;
}
Event::Dnd(DndEvent::Offer(id, OfferEvent::Leave))
if id == Some(my_id) =>
@ -404,7 +406,8 @@ impl<'a, Message: 'static> Widget<Message, iced::Theme, iced::Renderer>
viewport,
);
}
return event::Status::Captured;
shell.capture_event();
return;
}
Event::Dnd(DndEvent::Offer(id, OfferEvent::Motion { x, y }))
if id == Some(my_id) =>
@ -437,7 +440,8 @@ impl<'a, Message: 'static> Widget<Message, iced::Theme, iced::Renderer>
viewport,
);
}
return event::Status::Captured;
shell.capture_event();
return;
}
Event::Dnd(DndEvent::Offer(id, OfferEvent::LeaveDestination))
if id == Some(my_id) =>
@ -447,7 +451,8 @@ impl<'a, Message: 'static> Widget<Message, iced::Theme, iced::Renderer>
) {
shell.publish(msg);
}
return event::Status::Captured;
shell.capture_event();
return;
}
Event::Dnd(DndEvent::Offer(id, OfferEvent::Drop))
if id == Some(my_id) =>
@ -457,7 +462,8 @@ impl<'a, Message: 'static> Widget<Message, iced::Theme, iced::Renderer>
) {
shell.publish(msg);
}
return event::Status::Captured;
shell.capture_event();
return;
}
Event::Dnd(DndEvent::Offer(
id,
@ -471,7 +477,8 @@ impl<'a, Message: 'static> Widget<Message, iced::Theme, iced::Renderer>
) {
shell.publish(msg);
}
return event::Status::Captured;
shell.capture_event();
return;
}
Event::Dnd(DndEvent::Offer(
id,
@ -489,7 +496,8 @@ impl<'a, Message: 'static> Widget<Message, iced::Theme, iced::Renderer>
shell.publish(msg);
return ret;
}
return event::Status::Captured;
shell.capture_event();
return;
}
_ => {}
}

View file

@ -1,16 +1,16 @@
use std::any::Any;
use iced::Element;
use iced::id::Id;
use iced::widget::container;
use iced::Element;
use iced::{
Event, Length, Point, Rectangle,
clipboard::dnd::{DndAction, DndEvent, SourceEvent},
event, mouse, overlay, Event, Length, Point, Rectangle,
event, mouse, overlay,
};
use iced_core::{
layout, renderer,
widget::{tree, Tree},
Clipboard, Shell,
Clipboard, Shell, layout, renderer,
widget::{Tree, tree},
};
use iced_core::{Layout, Widget};
@ -37,11 +37,11 @@ pub struct DndSource<'a, Message, AppMessage, D> {
}
impl<
'a,
Message: 'static,
AppMessage: 'static,
D: iced::clipboard::mime::AsMimeTypes + std::marker::Send + 'static,
> DndSource<'a, Message, AppMessage, D>
'a,
Message: 'static,
AppMessage: 'static,
D: iced::clipboard::mime::AsMimeTypes + std::marker::Send + 'static,
> DndSource<'a, Message, AppMessage, D>
{
pub fn new(child: impl Into<Element<'a, Message>>) -> Self {
Self {
@ -119,11 +119,11 @@ impl<
}
impl<
'a,
Message: 'static,
AppMessage: 'static,
D: iced::clipboard::mime::AsMimeTypes + std::marker::Send + 'static,
> Widget<Message, iced::Theme, iced::Renderer>
'a,
Message: 'static,
AppMessage: 'static,
D: iced::clipboard::mime::AsMimeTypes + std::marker::Send + 'static,
> Widget<Message, iced::Theme, iced::Renderer>
for DndSource<'a, Message, AppMessage, D>
{
fn children(&self) -> Vec<Tree> {
@ -184,7 +184,7 @@ impl<
);
}
fn on_event(
fn update(
&mut self,
tree: &mut Tree,
event: Event,
@ -218,14 +218,16 @@ impl<
state.left_pressed_position = Some(position);
// dbg!(&state, &self.id);
return event::Status::Captured;
shell.capture_event();
return;
}
}
mouse::Event::ButtonReleased(mouse::Button::Left)
if state.left_pressed_position.is_some() =>
{
state.left_pressed_position = None;
return event::Status::Captured;
shell.capture_event();
return;
}
mouse::Event::CursorMoved { .. } => {
if let Some(position) = cursor.position() {
@ -258,7 +260,8 @@ impl<
} else if cursor.is_over(layout.bounds()) {
state.hovered = true;
}
return event::Status::Captured;
shell.capture_event();
return;
}
}
_ => return ret,
@ -268,7 +271,8 @@ impl<
)) => {
if state.is_dragging {
state.is_dragging = false;
return event::Status::Captured;
shell.capture_event();
return;
}
return ret;
}
@ -355,11 +359,11 @@ impl<
}
impl<
'a,
Message: 'static,
AppMessage: 'static,
D: iced::clipboard::mime::AsMimeTypes + std::marker::Send + 'static,
> From<DndSource<'a, Message, AppMessage, D>> for Element<'a, Message>
'a,
Message: 'static,
AppMessage: 'static,
D: iced::clipboard::mime::AsMimeTypes + std::marker::Send + 'static,
> From<DndSource<'a, Message, AppMessage, D>> for Element<'a, Message>
{
fn from(e: DndSource<'a, Message, AppMessage, D>) -> Element<'a, Message> {
Element::new(e)

View file

@ -273,7 +273,7 @@ where
});
}
fn on_event(
fn update(
&mut self,
tree: &mut Tree,
event: Event,

View file

@ -10,7 +10,7 @@ tester = ["iced/tester"]
[dependencies]
iced.workspace = true
iced.features = ["tokio", "debug", "time-travel", "winit"]
iced.features = ["tokio", "debug", "time-travel", "winit", "wgpu"]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View file

@ -452,7 +452,7 @@ fn empty_message(message: &str) -> Element<'_, Message> {
.align_x(Center)
.style(subtle),
)
.height(200)
.height(200u16)
.into()
}
@ -461,7 +461,7 @@ fn empty_message(message: &str) -> Element<'_, Message> {
fn icon(unicode: char) -> Text<'static> {
text(unicode.to_string())
.font(Font::with_name("Iced-Todos-Icons"))
.width(20)
.width(20u16)
.align_x(Center)
.shaping(text::Shaping::Basic)
}