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

View file

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