working drag and drop
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-09-11 07:25:09 -05:00
parent 652bb431a4
commit 3913a15002
2 changed files with 26 additions and 18 deletions

View file

@ -5,8 +5,9 @@ use std::sync::{Arc, Mutex};
use cosmic::iced::clipboard::mime::{AllowedMimeTypes, AsMimeTypes}; use cosmic::iced::clipboard::mime::{AllowedMimeTypes, AsMimeTypes};
use crisp::types::{Keyword, Symbol, Value}; use crisp::types::{Keyword, Symbol, Value};
use miette::Result; use miette::{IntoDiagnostic, Result};
use resvg::usvg::fontdb; use resvg::usvg::fontdb;
use serde::{Deserialize, Serialize};
use tracing::{debug, error}; use tracing::{debug, error};
use crate::Slide; use crate::Slide;
@ -18,7 +19,7 @@ use super::videos::Video;
use super::kinds::ServiceItemKind; use super::kinds::ServiceItemKind;
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ServiceItem { pub struct ServiceItem {
pub id: i32, pub id: i32,
pub title: String, pub title: String,
@ -49,11 +50,7 @@ impl TryFrom<(Vec<u8>, String)> for ServiceItem {
value: (Vec<u8>, String), value: (Vec<u8>, String),
) -> std::result::Result<Self, Self::Error> { ) -> std::result::Result<Self, Self::Error> {
debug!(?value); debug!(?value);
let val = Value::from( ron::de::from_bytes(&value.0).into_diagnostic()
String::from_utf8(value.0)
.expect("Value couldn't be made"),
);
Ok(Self::from(&val))
} }
} }
@ -75,9 +72,9 @@ impl AsMimeTypes for ServiceItem {
) -> Option<std::borrow::Cow<'static, [u8]>> { ) -> Option<std::borrow::Cow<'static, [u8]>> {
debug!(?self); debug!(?self);
debug!(mime_type); debug!(mime_type);
let val = Value::from(self); let ron = ron::ser::to_string(self).ok()?;
let val = String::from(val); debug!(ron);
Some(Cow::from(val.into_bytes())) Some(Cow::from(ron.into_bytes()))
} }
} }

View file

@ -945,8 +945,20 @@ impl cosmic::Application for App {
} }
Task::none() Task::none()
} }
Message::AddServiceItem(index, item) => { Message::AddServiceItem(index, mut item) => {
item.slides = item
.slides
.into_par_iter()
.map(|mut slide| {
let fontdb = Arc::clone(&self.fontdb);
text_svg::text_svg_generator(
&mut slide, fontdb,
);
slide
})
.collect();
self.service.insert(index, item); self.service.insert(index, item);
self.presenter.update_items(self.service.clone());
Task::none() Task::none()
} }
Message::AddServiceItemDrop(index) => { Message::AddServiceItemDrop(index) => {
@ -1325,8 +1337,11 @@ where
}, },
} }
}) })
// .icon_size(cosmic::theme::spacing().space_l)
.class(cosmic::theme::style::Button::HeaderBar) .class(cosmic::theme::style::Button::HeaderBar)
.padding(5) // .spacing(cosmic::theme::spacing().space_l)
// .padding(cosmic::theme::spacing().space_m)
// .height(cosmic::theme::spacing().space_xxxl)
.width(Length::Fill) .width(Length::Fill)
.on_press(Message::ChangeServiceItem(index)); .on_press(Message::ChangeServiceItem(index));
let tooltip = tooltip(button, let tooltip = tooltip(button,
@ -1339,9 +1354,6 @@ where
} else { } else {
Message::None Message::None
} }
}).on_drop(move |x, y| {
debug!(x, y);
Message::AddServiceItemDrop(index)
}).on_finish(move |mime, data, action, x, y| { }).on_finish(move |mime, data, action, x, y| {
debug!(mime, ?data, ?action, x, y); debug!(mime, ?data, ?action, x, y);
let Ok(item) = ServiceItem::try_from((data, mime)) else { let Ok(item) = ServiceItem::try_from((data, mime)) else {
@ -1353,7 +1365,6 @@ where
.into() .into()
}); });
let end_index = self.service.len();
let column = column![ let column = column![
text::heading("Service List") text::heading("Service List")
.center() .center()
@ -1361,7 +1372,7 @@ where
iced::widget::horizontal_rule(1), iced::widget::horizontal_rule(1),
column(list).spacing(10), column(list).spacing(10),
dnd_destination( dnd_destination(
vertical_space(), vertical_space().width(Length::Fill),
vec!["application/service-item".into()] vec!["application/service-item".into()]
) )
.data_received_for::<ServiceItem>(|item| { .data_received_for::<ServiceItem>(|item| {
@ -1379,7 +1390,7 @@ where
return Message::None; return Message::None;
}; };
debug!(?item); debug!(?item);
Message::AddServiceItem(end_index, item) Message::AppendServiceItem(item)
} }
) )
] ]