making the text in the library smarter
This commit is contained in:
parent
40065d2c5a
commit
9b9c337c1b
|
@ -7,4 +7,5 @@ pub trait Content {
|
||||||
fn kind(&self) -> ServiceItemKind;
|
fn kind(&self) -> ServiceItemKind;
|
||||||
fn to_service_item(&self) -> ServiceItem;
|
fn to_service_item(&self) -> ServiceItem;
|
||||||
fn background(&self) -> Option<Background>;
|
fn background(&self) -> Option<Background>;
|
||||||
|
fn subtext(&self) -> String;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,17 @@ impl Content for Image {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn subtext(&self) -> String {
|
||||||
|
if self.path.exists() {
|
||||||
|
self.path
|
||||||
|
.file_name()
|
||||||
|
.map(|f| f.to_string_lossy().to_string())
|
||||||
|
.unwrap_or("Missing image".into())
|
||||||
|
} else {
|
||||||
|
"Missing image".into()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Value> for Image {
|
impl From<Value> for Image {
|
||||||
|
|
|
@ -65,6 +65,17 @@ impl Content for Presentation {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn subtext(&self) -> String {
|
||||||
|
if self.path.exists() {
|
||||||
|
self.path
|
||||||
|
.file_name()
|
||||||
|
.map(|f| f.to_string_lossy().to_string())
|
||||||
|
.unwrap_or("Missing presentation".into())
|
||||||
|
} else {
|
||||||
|
"Missing presentation".into()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Value> for Presentation {
|
impl From<Value> for Presentation {
|
||||||
|
|
|
@ -59,6 +59,10 @@ impl Content for Song {
|
||||||
fn background(&self) -> Option<Background> {
|
fn background(&self) -> Option<Background> {
|
||||||
self.background.clone()
|
self.background.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn subtext(&self) -> String {
|
||||||
|
self.author.clone().unwrap_or("Author missing".into())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServiceTrait for Song {
|
impl ServiceTrait for Song {
|
||||||
|
|
|
@ -58,6 +58,17 @@ impl Content for Video {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn subtext(&self) -> String {
|
||||||
|
if self.path.exists() {
|
||||||
|
self.path
|
||||||
|
.file_name()
|
||||||
|
.map(|f| f.to_string_lossy().to_string())
|
||||||
|
.unwrap_or("Missing video".into())
|
||||||
|
} else {
|
||||||
|
"Missing video".into()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Value> for Video {
|
impl From<Value> for Video {
|
||||||
|
|
|
@ -690,7 +690,7 @@ impl cosmic::Application for App {
|
||||||
)
|
)
|
||||||
.center_y(Length::Fill)
|
.center_y(Length::Fill)
|
||||||
.align_right(Length::Fill)
|
.align_right(Length::Fill)
|
||||||
.width(Length::FillPortion(2)),
|
.width(Length::FillPortion(1)),
|
||||||
Container::new(slide_preview)
|
Container::new(slide_preview)
|
||||||
.center_y(Length::Fill)
|
.center_y(Length::Fill)
|
||||||
.width(Length::FillPortion(3)),
|
.width(Length::FillPortion(3)),
|
||||||
|
@ -705,7 +705,7 @@ impl cosmic::Application for App {
|
||||||
)
|
)
|
||||||
.center_y(Length::Fill)
|
.center_y(Length::Fill)
|
||||||
.align_left(Length::Fill)
|
.align_left(Length::Fill)
|
||||||
.width(Length::FillPortion(2)),
|
.width(Length::FillPortion(1)),
|
||||||
library.width(Length::FillPortion(2))
|
library.width(Length::FillPortion(2))
|
||||||
]
|
]
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
iced::{
|
iced::{
|
||||||
alignment::Vertical, futures::FutureExt, Background, Border,
|
alignment::Vertical, futures::FutureExt, Background, Border,
|
||||||
Length,
|
Color, Length,
|
||||||
},
|
},
|
||||||
iced_widget::{column, row as rowm, text as textm},
|
iced_widget::{column, row as rowm, text as textm},
|
||||||
|
theme,
|
||||||
widget::{
|
widget::{
|
||||||
button, container, horizontal_space, icon, mouse_area,
|
button, container, horizontal_space, icon, mouse_area,
|
||||||
responsive, row, scrollable, text, text_input, Container,
|
responsive, row, scrollable, text, text_input, Container,
|
||||||
|
@ -275,18 +276,28 @@ impl<'a> Library {
|
||||||
let mut row = row::<Message>().spacing(5);
|
let mut row = row::<Message>().spacing(5);
|
||||||
match &model.kind {
|
match &model.kind {
|
||||||
LibraryKind::Song => {
|
LibraryKind::Song => {
|
||||||
|
row = row
|
||||||
|
.push(icon::from_name("folder-music-symbolic"));
|
||||||
row = row
|
row = row
|
||||||
.push(textm!("Songs").align_y(Vertical::Center));
|
.push(textm!("Songs").align_y(Vertical::Center));
|
||||||
}
|
}
|
||||||
LibraryKind::Video => {
|
LibraryKind::Video => {
|
||||||
|
row = row
|
||||||
|
.push(icon::from_name("folder-videos-symbolic"));
|
||||||
row = row
|
row = row
|
||||||
.push(textm!("Videos").align_y(Vertical::Center));
|
.push(textm!("Videos").align_y(Vertical::Center));
|
||||||
}
|
}
|
||||||
LibraryKind::Image => {
|
LibraryKind::Image => {
|
||||||
|
row = row.push(icon::from_name(
|
||||||
|
"folder-pictures-symbolic",
|
||||||
|
));
|
||||||
row = row
|
row = row
|
||||||
.push(textm!("Images").align_y(Vertical::Center));
|
.push(textm!("Images").align_y(Vertical::Center));
|
||||||
}
|
}
|
||||||
LibraryKind::Presentation => {
|
LibraryKind::Presentation => {
|
||||||
|
row = row.push(icon::from_name(
|
||||||
|
"x-office-presentation-symbolic",
|
||||||
|
));
|
||||||
row = row.push(
|
row = row.push(
|
||||||
textm!("Presentations").align_y(Vertical::Center),
|
textm!("Presentations").align_y(Vertical::Center),
|
||||||
);
|
);
|
||||||
|
@ -431,25 +442,19 @@ impl<'a> Library {
|
||||||
}))
|
}))
|
||||||
.center_y(20)
|
.center_y(20)
|
||||||
.center_x(Length::Fill);
|
.center_x(Length::Fill);
|
||||||
let icon = icon::from_name({
|
|
||||||
match model.kind {
|
|
||||||
LibraryKind::Song => "folder-music-symbolic",
|
|
||||||
LibraryKind::Video => "folder-videos-symbolic",
|
|
||||||
LibraryKind::Image => "folder-pictures-symbolic",
|
|
||||||
LibraryKind::Presentation => {
|
|
||||||
"x-office-presentation-symbolic"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let subtext = container(responsive(|size| {
|
let subtext = container(responsive(|size| {
|
||||||
let background = if let Some(text) = item.background() {
|
let color: Color = if item.background().is_some() {
|
||||||
text.path.to_string_lossy().to_string()
|
theme::active().cosmic().accent_text_color().into()
|
||||||
} else {
|
} else {
|
||||||
"Background does not exist...".to_string()
|
theme::active()
|
||||||
|
.cosmic()
|
||||||
|
.destructive_text_color()
|
||||||
|
.into()
|
||||||
};
|
};
|
||||||
text::body(elide_text(background, size.width))
|
text::body(elide_text(item.subtext(), size.width))
|
||||||
.center()
|
.center()
|
||||||
.wrapping(textm::Wrapping::None)
|
.wrapping(textm::Wrapping::None)
|
||||||
|
.class(color)
|
||||||
.into()
|
.into()
|
||||||
}))
|
}))
|
||||||
.center_y(20)
|
.center_y(20)
|
||||||
|
@ -458,7 +463,7 @@ impl<'a> Library {
|
||||||
let texts = column([text.into(), subtext.into()]);
|
let texts = column([text.into(), subtext.into()]);
|
||||||
|
|
||||||
Container::new(
|
Container::new(
|
||||||
rowm![horizontal_space().width(0), icon, texts]
|
rowm![horizontal_space().width(0), texts]
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.align_y(Vertical::Center),
|
.align_y(Vertical::Center),
|
||||||
)
|
)
|
||||||
|
@ -561,8 +566,9 @@ async fn add_db() -> Result<SqlitePool> {
|
||||||
SqlitePool::connect(&db_url).await.into_diagnostic()
|
SqlitePool::connect(&db_url).await.into_diagnostic()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn elide_text(text: String, width: f32) -> String {
|
fn elide_text(text: impl AsRef<str>, width: f32) -> String {
|
||||||
const CHAR_SIZE: f32 = 8.0;
|
const CHAR_SIZE: f32 = 8.0;
|
||||||
|
let text: String = text.as_ref().to_owned();
|
||||||
let text_length = text.len() as f32 * CHAR_SIZE;
|
let text_length = text.len() as f32 * CHAR_SIZE;
|
||||||
if text_length > width {
|
if text_length > width {
|
||||||
format!(
|
format!(
|
||||||
|
|
|
@ -11,9 +11,8 @@ use cosmic::{
|
||||||
theme,
|
theme,
|
||||||
widget::{
|
widget::{
|
||||||
button, column, combo_box, container, dropdown,
|
button, column, combo_box, container, dropdown,
|
||||||
horizontal_space, icon, scrollable,
|
horizontal_space, icon, scrollable, svg::Handle, text,
|
||||||
svg::{self, Handle},
|
text_editor, text_input, Svg,
|
||||||
text, text_editor, text_input, Svg,
|
|
||||||
},
|
},
|
||||||
Element, Task,
|
Element, Task,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue