updating the drag system to use a more efficient process
Some checks are pending
/ test (push) Waiting to run
Some checks are pending
/ test (push) Waiting to run
This commit is contained in:
parent
75ff187505
commit
085c8244f9
3 changed files with 52 additions and 29 deletions
|
|
@ -18,6 +18,20 @@ pub enum ServiceItemKind {
|
||||||
Content(Slide),
|
Content(Slide),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ServiceItemKind {
|
||||||
|
pub fn title(&self) -> String {
|
||||||
|
match self {
|
||||||
|
ServiceItemKind::Song(song) => song.title.to_string(),
|
||||||
|
ServiceItemKind::Video(video) => video.title.to_string(),
|
||||||
|
ServiceItemKind::Image(image) => image.title.to_string(),
|
||||||
|
ServiceItemKind::Presentation(presentation) => {
|
||||||
|
presentation.title.to_string()
|
||||||
|
}
|
||||||
|
ServiceItemKind::Content(slide) => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for ServiceItemKind {
|
impl std::fmt::Display for ServiceItemKind {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
let s = match self {
|
let s = match self {
|
||||||
|
|
|
||||||
19
src/main.rs
19
src/main.rs
|
|
@ -16,6 +16,7 @@ use cosmic::iced_core::text::Wrapping;
|
||||||
use cosmic::iced_futures::Subscription;
|
use cosmic::iced_futures::Subscription;
|
||||||
use cosmic::iced_widget::{column, row, stack};
|
use cosmic::iced_widget::{column, row, stack};
|
||||||
use cosmic::theme;
|
use cosmic::theme;
|
||||||
|
use cosmic::widget::button::Catalog;
|
||||||
use cosmic::widget::dnd_destination::dnd_destination;
|
use cosmic::widget::dnd_destination::dnd_destination;
|
||||||
use cosmic::widget::menu::key_bind::Modifier;
|
use cosmic::widget::menu::key_bind::Modifier;
|
||||||
use cosmic::widget::menu::{ItemWidth, KeyBind};
|
use cosmic::widget::menu::{ItemWidth, KeyBind};
|
||||||
|
|
@ -735,7 +736,7 @@ impl cosmic::Application for App {
|
||||||
]
|
]
|
||||||
.spacing(cosmic::theme::active().cosmic().space_s()),
|
.spacing(cosmic::theme::active().cosmic().space_s()),
|
||||||
)
|
)
|
||||||
.padding(cosmic::theme::active().cosmic().space_xxxl())
|
.padding(cosmic::theme::active().cosmic().space_xl())
|
||||||
.style(nav_bar_style);
|
.style(nav_bar_style);
|
||||||
let modal = Container::new(modal)
|
let modal = Container::new(modal)
|
||||||
.padding([
|
.padding([
|
||||||
|
|
@ -745,8 +746,18 @@ impl cosmic::Application for App {
|
||||||
.center_x(Length::Fill)
|
.center_x(Length::Fill)
|
||||||
.align_top(Length::Fill);
|
.align_top(Length::Fill);
|
||||||
let mouse_stack = stack!(
|
let mouse_stack = stack!(
|
||||||
mouse_area(Space::new(Length::Fill, Length::Fill))
|
mouse_area(
|
||||||
.on_press(Message::CloseSearch),
|
container(Space::new(Length::Fill, Length::Fill))
|
||||||
|
.style(|_| {
|
||||||
|
container::background(
|
||||||
|
cosmic::iced::Background::Color(
|
||||||
|
Color::BLACK,
|
||||||
|
)
|
||||||
|
.scale_alpha(0.3),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.on_press(Message::CloseSearch),
|
||||||
modal
|
modal
|
||||||
);
|
);
|
||||||
Some(mouse_stack.into())
|
Some(mouse_stack.into())
|
||||||
|
|
@ -1167,7 +1178,7 @@ impl cosmic::Application for App {
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.find(|(id, _)| index == *id)
|
.find(|(id, _)| index == *id)
|
||||||
&& let Some(slide) = item.slides.first()
|
&& let Some(_slide) = item.slides.first()
|
||||||
{
|
{
|
||||||
self.current_item = (index, 0);
|
self.current_item = (index, 0);
|
||||||
self.presenter.update(
|
self.presenter.update(
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ use cosmic::{
|
||||||
dialog::file_chooser::open::Dialog,
|
dialog::file_chooser::open::Dialog,
|
||||||
iced::{
|
iced::{
|
||||||
alignment::Vertical, clipboard::dnd::DndAction,
|
alignment::Vertical, clipboard::dnd::DndAction,
|
||||||
keyboard::Modifiers, Background, Border, Color, Length,
|
keyboard::Modifiers, wgpu::core::command::DynComputePass,
|
||||||
|
Background, Border, Color, Length,
|
||||||
},
|
},
|
||||||
iced_core::widget::tree::State,
|
iced_core::widget::tree::State,
|
||||||
iced_widget::{column, row as rowm, text as textm},
|
iced_widget::{column, row as rowm, text as textm},
|
||||||
|
|
@ -26,12 +27,13 @@ use tracing::{debug, error, warn};
|
||||||
use crate::core::{
|
use crate::core::{
|
||||||
content::Content,
|
content::Content,
|
||||||
images::{self, update_image_in_db, Image},
|
images::{self, update_image_in_db, Image},
|
||||||
|
kinds::ServiceItemKind,
|
||||||
model::{KindWrapper, LibraryKind, Model},
|
model::{KindWrapper, LibraryKind, Model},
|
||||||
presentations::{
|
presentations::{
|
||||||
self, add_presentation_to_db, update_presentation_in_db,
|
self, add_presentation_to_db, update_presentation_in_db,
|
||||||
Presentation,
|
Presentation,
|
||||||
},
|
},
|
||||||
service_items::ServiceItem,
|
service_items::{ServiceItem, ServiceTrait},
|
||||||
songs::{self, update_song_in_db, Song},
|
songs::{self, update_song_in_db, Song},
|
||||||
videos::{self, update_video_in_db, Video},
|
videos::{self, update_video_in_db, Video},
|
||||||
};
|
};
|
||||||
|
|
@ -920,56 +922,52 @@ impl<'a> Library {
|
||||||
pub async fn search_items(
|
pub async fn search_items(
|
||||||
&self,
|
&self,
|
||||||
query: String,
|
query: String,
|
||||||
) -> Vec<ServiceItem> {
|
) -> Vec<ServiceItemKind> {
|
||||||
let query = query.to_lowercase();
|
let query = query.to_lowercase();
|
||||||
let mut items: Vec<ServiceItem> = self
|
let mut items: Vec<ServiceItemKind> = self
|
||||||
.song_library
|
.song_library
|
||||||
.items
|
.items
|
||||||
.iter()
|
.clone()
|
||||||
|
.into_iter()
|
||||||
.filter(|song| song.title.to_lowercase().contains(&query))
|
.filter(|song| song.title.to_lowercase().contains(&query))
|
||||||
.map(
|
.map(|song| ServiceItemKind::Song(song))
|
||||||
super::super::core::content::Content::to_service_item,
|
|
||||||
)
|
|
||||||
.collect();
|
.collect();
|
||||||
let videos: Vec<ServiceItem> = self
|
let videos: Vec<ServiceItemKind> = self
|
||||||
.video_library
|
.video_library
|
||||||
.items
|
.items
|
||||||
.iter()
|
.clone()
|
||||||
|
.into_iter()
|
||||||
.filter(|vid| vid.title.to_lowercase().contains(&query))
|
.filter(|vid| vid.title.to_lowercase().contains(&query))
|
||||||
.map(
|
.map(|video| ServiceItemKind::Video(video))
|
||||||
super::super::core::content::Content::to_service_item,
|
|
||||||
)
|
|
||||||
.collect();
|
.collect();
|
||||||
let images: Vec<ServiceItem> = self
|
let images: Vec<ServiceItemKind> = self
|
||||||
.image_library
|
.image_library
|
||||||
.items
|
.items
|
||||||
.iter()
|
.clone()
|
||||||
|
.into_iter()
|
||||||
.filter(|image| {
|
.filter(|image| {
|
||||||
image.title.to_lowercase().contains(&query)
|
image.title.to_lowercase().contains(&query)
|
||||||
})
|
})
|
||||||
.map(
|
.map(|image| ServiceItemKind::Image(image))
|
||||||
super::super::core::content::Content::to_service_item,
|
|
||||||
)
|
|
||||||
.collect();
|
.collect();
|
||||||
let presentations: Vec<ServiceItem> = self
|
let presentations: Vec<ServiceItemKind> = self
|
||||||
.presentation_library
|
.presentation_library
|
||||||
.items
|
.items
|
||||||
.iter()
|
.clone()
|
||||||
|
.into_iter()
|
||||||
.filter(|pres| pres.title.to_lowercase().contains(&query))
|
.filter(|pres| pres.title.to_lowercase().contains(&query))
|
||||||
.map(
|
.map(|pres| ServiceItemKind::Presentation(pres))
|
||||||
super::super::core::content::Content::to_service_item,
|
|
||||||
)
|
|
||||||
.collect();
|
.collect();
|
||||||
items.extend(videos);
|
items.extend(videos);
|
||||||
items.extend(images);
|
items.extend(images);
|
||||||
items.extend(presentations);
|
items.extend(presentations);
|
||||||
let mut items: Vec<(usize, ServiceItem)> = items
|
let mut items: Vec<(usize, ServiceItemKind)> = items
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|item| {
|
.map(|item| {
|
||||||
(
|
(
|
||||||
levenshtein::distance(
|
levenshtein::distance(
|
||||||
query.bytes(),
|
query.bytes(),
|
||||||
item.title.bytes(),
|
item.title().bytes(),
|
||||||
),
|
),
|
||||||
item,
|
item,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue