From a8f7651164dd64080d80463982d980fb0798f0ab Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sun, 23 Feb 2025 22:03:15 -0600 Subject: [PATCH] making a subtext that uses the path of the background --- src/core/content.rs | 3 +++ src/core/images.rs | 10 ++++++++++ src/core/presentations.rs | 10 ++++++++++ src/core/songs.rs | 6 +++++- src/core/videos.rs | 10 ++++++++++ src/ui/library.rs | 18 +++++++++++++++++- 6 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/core/content.rs b/src/core/content.rs index 45c6e21..b117c5e 100644 --- a/src/core/content.rs +++ b/src/core/content.rs @@ -1,7 +1,10 @@ +use crate::Background; + use super::{kinds::ServiceItemKind, service_items::ServiceItem}; pub trait Content { fn title(&self) -> String; fn kind(&self) -> ServiceItemKind; fn to_service_item(&self) -> ServiceItem; + fn background(&self) -> Option; } diff --git a/src/core/images.rs b/src/core/images.rs index a03281f..9e45df4 100644 --- a/src/core/images.rs +++ b/src/core/images.rs @@ -40,6 +40,16 @@ impl Content for Image { fn to_service_item(&self) -> super::service_items::ServiceItem { self.into() } + + fn background(&self) -> Option { + if let Ok(background) = + Background::try_from(self.path.clone()) + { + Some(background) + } else { + None + } + } } impl From for Image { diff --git a/src/core/presentations.rs b/src/core/presentations.rs index a99c9f4..a991404 100644 --- a/src/core/presentations.rs +++ b/src/core/presentations.rs @@ -54,6 +54,16 @@ impl Content for Presentation { fn to_service_item(&self) -> super::service_items::ServiceItem { self.into() } + + fn background(&self) -> Option { + if let Ok(background) = + Background::try_from(self.path.clone()) + { + Some(background) + } else { + None + } + } } impl From for Presentation { diff --git a/src/core/songs.rs b/src/core/songs.rs index fb133a5..31f5513 100644 --- a/src/core/songs.rs +++ b/src/core/songs.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, path::PathBuf}; +use std::{collections::HashMap, option::Option, path::PathBuf}; use cosmic::iced::Executor; use crisp::types::{Keyword, Symbol, Value}; @@ -54,6 +54,10 @@ impl Content for Song { fn to_service_item(&self) -> super::service_items::ServiceItem { self.into() } + + fn background(&self) -> Option { + self.background.clone() + } } impl ServiceTrait for Song { diff --git a/src/core/videos.rs b/src/core/videos.rs index 5b321b4..dd36300 100644 --- a/src/core/videos.rs +++ b/src/core/videos.rs @@ -45,6 +45,16 @@ impl Content for Video { fn to_service_item(&self) -> super::service_items::ServiceItem { self.into() } + + fn background(&self) -> Option { + if let Ok(background) = + Background::try_from(self.path.clone()) + { + Some(background) + } else { + None + } + } } impl From for Video { diff --git a/src/ui/library.rs b/src/ui/library.rs index 22340a2..581d28f 100644 --- a/src/ui/library.rs +++ b/src/ui/library.rs @@ -265,8 +265,24 @@ impl Library { } } }); + let subtext = container(responsive(|size| { + let background = if let Some(text) = item.background() { + text.path.to_string_lossy().to_string() + } else { + "Background does not exist...".to_string() + }; + text::body(elide_text(background, size.width)) + .center() + .wrapping(textm::Wrapping::None) + .into() + })) + .center_y(25) + .center_x(Length::Fill); + + let texts = column([text.into(), subtext.into()]); + Container::new( - rowm![horizontal_space().width(0), icon, text] + rowm![horizontal_space().width(0), icon, texts] .spacing(10) .align_y(Vertical::Center), )