more things, but mostly starting to add library management
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-09-15 14:42:07 -05:00
parent 3fe77c93e2
commit 645411b59c
13 changed files with 341 additions and 260 deletions

190
flake.nix
View file

@ -8,101 +8,107 @@
fenix.url = "github:nix-community/fenix";
};
outputs = inputs: with inputs;
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [fenix.overlays.default];
# overlays = [cargo2nix.overlays.default];
};
naersk' = pkgs.callPackage naersk {};
nbi = with pkgs; [
# Rust tools
alejandra
(pkgs.fenix.stable.withComponents [
"cargo"
"clippy"
"rust-src"
"rustc"
"rustfmt"
])
rust-analyzer
vulkan-loader
wayland
wayland-protocols
libxkbcommon
pkg-config
sccache
];
outputs =
inputs:
with inputs;
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ fenix.overlays.default ];
# overlays = [cargo2nix.overlays.default];
};
naersk' = pkgs.callPackage naersk { };
nbi = with pkgs; [
# Rust tools
alejandra
(pkgs.fenix.stable.withComponents [
"cargo"
"clippy"
"rust-src"
"rustc"
"rustfmt"
])
rust-analyzer
vulkan-loader
wayland
wayland-protocols
libxkbcommon
pkg-config
sccache
];
bi = with pkgs; [
gcc
stdenv
gnumake
gdb
lldb
cmake
clang
libclang
makeWrapper
vulkan-headers
vulkan-loader
vulkan-tools
libGL
cargo-flamegraph
bi = with pkgs; [
gcc
stdenv
gnumake
gdb
lldb
cmake
clang
libclang
makeWrapper
vulkan-headers
vulkan-loader
vulkan-tools
libGL
cargo-flamegraph
bacon
fontconfig
glib
alsa-lib
gst_all_1.gst-libav
gst_all_1.gst-plugins-bad
gst_all_1.gst-plugins-good
gst_all_1.gst-plugins-ugly
gst_all_1.gst-plugins-base
gst_all_1.gst-plugins-rs
gst_all_1.gst-vaapi
gst_all_1.gstreamer
# podofo
# mpv
ffmpeg-full
mupdf
# yt-dlp
fontconfig
glib
alsa-lib
gst_all_1.gst-libav
gst_all_1.gst-plugins-bad
gst_all_1.gst-plugins-good
gst_all_1.gst-plugins-ugly
gst_all_1.gst-plugins-base
gst_all_1.gst-plugins-rs
gst_all_1.gst-vaapi
gst_all_1.gstreamer
# podofo
# mpv
ffmpeg-full
mupdf
# yt-dlp
just
sqlx-cli
cargo-watch
];
in rec
{
devShell = pkgs.mkShell.override {
# stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.clangStdenv;
} {
nativeBuildInputs = nbi;
buildInputs = bi;
LD_LIBRARY_PATH = "$LD_LIBRARY_PATH:${
with pkgs;
pkgs.lib.makeLibraryPath [
pkgs.vulkan-loader
pkgs.wayland
pkgs.wayland-protocols
pkgs.libxkbcommon
pkgs.mupdf
pkgs.libclang
]
}";
# LIBCLANG_PATH = "${pkgs.clang}";
DATABASE_URL = "sqlite:///home/chris/.local/share/lumina/library-db.sqlite3";
};
defaultPackage = naersk'.buildPackage {
just
sqlx-cli
cargo-watch
];
in
rec {
devShell =
pkgs.mkShell.override
{
# stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.clangStdenv;
}
{
nativeBuildInputs = nbi;
buildInputs = bi;
LD_LIBRARY_PATH = "$LD_LIBRARY_PATH:${
with pkgs;
pkgs.lib.makeLibraryPath [
pkgs.vulkan-loader
pkgs.wayland
pkgs.wayland-protocols
pkgs.libxkbcommon
pkgs.mupdf
pkgs.libclang
]
}";
# LIBCLANG_PATH = "${pkgs.clang}";
DATABASE_URL = "sqlite:///home/chris/.local/share/lumina/library-db.sqlite3";
};
defaultPackage = naersk'.buildPackage {
src = ./.;
};
packages = {
default = naersk'.buildPackage {
src = ./.;
};
packages = {
default = naersk'.buildPackage {
src = ./.;
};
};
}
);
};
}
);
}

View file

@ -52,7 +52,9 @@ impl Content for Image {
if self.path.exists() {
self.path
.file_name()
.map_or("Missing image".into(), |f| f.to_string_lossy().to_string())
.map_or("Missing image".into(), |f| {
f.to_string_lossy().to_string()
})
} else {
"Missing image".into()
}
@ -158,7 +160,9 @@ impl Model<Image> {
}
}
Err(e) => {
error!("There was an error in converting images: {e}");
error!(
"There was an error in converting images: {e}"
);
}
}
}

View file

@ -21,11 +21,11 @@ pub enum ServiceItemKind {
impl std::fmt::Display for ServiceItemKind {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let s = match self {
Self::Song(s) => "song".to_owned(),
Self::Image(i) => "image".to_owned(),
Self::Video(v) => "video".to_owned(),
Self::Presentation(p) => "html".to_owned(),
Self::Content(s) => "content".to_owned(),
Self::Song(_) => "song".to_owned(),
Self::Image(_) => "image".to_owned(),
Self::Video(_) => "video".to_owned(),
Self::Presentation(_) => "html".to_owned(),
Self::Content(_) => "content".to_owned(),
};
write!(f, "{s}")
}
@ -76,7 +76,9 @@ impl Display for ParseError {
f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
let message = match self {
Self::UnknownType => "The type does not exist. It needs to be one of 'song', 'video', 'image', 'presentation', or 'content'",
Self::UnknownType => {
"The type does not exist. It needs to be one of 'song', 'video', 'image', 'presentation', or 'content'"
}
};
write!(f, "Error: {message}")
}

View file

@ -1,7 +1,6 @@
use std::mem::replace;
use cosmic::iced::Executor;
use miette::{miette, Result};
use miette::{Result, miette};
use sqlx::{Connection, SqliteConnection};
#[derive(Debug, Clone)]
@ -46,7 +45,8 @@ impl<T> Model<T> {
Ok(())
}
#[must_use] pub fn get_item(&self, index: i32) -> Option<&T> {
#[must_use]
pub fn get_item(&self, index: i32) -> Option<&T> {
self.items.get(index as usize)
}

View file

@ -75,7 +75,9 @@ impl Content for Presentation {
if self.path.exists() {
self.path
.file_name()
.map_or("Missing presentation".into(), |f| f.to_string_lossy().to_string())
.map_or("Missing presentation".into(), |f| {
f.to_string_lossy().to_string()
})
} else {
"Missing presentation".into()
}
@ -189,14 +191,16 @@ impl ServiceTrait for Presentation {
}
impl Presentation {
#[must_use] pub fn new() -> Self {
#[must_use]
pub fn new() -> Self {
Self {
title: String::new(),
..Default::default()
}
}
#[must_use] pub const fn get_kind(&self) -> &PresKind {
#[must_use]
pub const fn get_kind(&self) -> &PresKind {
&self.kind
}
}

View file

@ -172,30 +172,32 @@ impl From<&Value> for ServiceItem {
} else if let Some(background) =
list.get(background_pos)
{
if let Value::List(item) = background { match &item[0] {
Value::Symbol(Symbol(s))
if s == "image" =>
{
Self::from(&Image::from(
background,
))
if let Value::List(item) = background {
match &item[0] {
Value::Symbol(Symbol(s))
if s == "image" =>
{
Self::from(&Image::from(
background,
))
}
Value::Symbol(Symbol(s))
if s == "video" =>
{
Self::from(&Video::from(
background,
))
}
Value::Symbol(Symbol(s))
if s == "presentation" =>
{
Self::from(&Presentation::from(
background,
))
}
_ => todo!(),
}
Value::Symbol(Symbol(s))
if s == "video" =>
{
Self::from(&Video::from(
background,
))
}
Value::Symbol(Symbol(s))
if s == "presentation" =>
{
Self::from(&Presentation::from(
background,
))
}
_ => todo!(),
} } else {
} else {
error!(
"There is no background here: {:?}",
background

View file

@ -1,16 +1,15 @@
use std::{collections::HashMap, option::Option, path::PathBuf};
use cosmic::iced::Executor;
use crisp::types::{Keyword, Symbol, Value};
use miette::{miette, IntoDiagnostic, Result};
use miette::{IntoDiagnostic, Result, miette};
use serde::{Deserialize, Serialize};
use sqlx::{
pool::PoolConnection, query, sqlite::SqliteRow, FromRow, Row,
Sqlite, SqliteConnection, SqlitePool,
FromRow, Row, Sqlite, SqliteConnection, SqlitePool,
pool::PoolConnection, query, sqlite::SqliteRow,
};
use tracing::error;
use crate::{core::slide, Slide, SlideBuilder};
use crate::{Slide, SlideBuilder, core::slide};
use super::{
content::Content,
@ -128,7 +127,9 @@ impl FromRow<'_, SqliteRow> for Song {
})),
verse_order: Some({
let str: &str = row.try_get(0)?;
str.split(' ').map(std::string::ToString::to_string).collect()
str.split(' ')
.map(std::string::ToString::to_string)
.collect()
}),
background: {
let string: String = row.try_get(7)?;
@ -250,8 +251,7 @@ pub fn lisp_to_song(list: Vec<Value>) -> Song {
.position(|v| v == &Value::Keyword(Keyword::from("title")))
{
let pos = key_pos + 1;
list.get(pos)
.map_or(String::from("song"), String::from)
list.get(pos).map_or(String::from("song"), String::from)
} else {
String::from("song")
};
@ -625,7 +625,27 @@ You saved my soul"
let lyrics = song.get_lyrics();
match lyrics {
Ok(lyrics) => {
assert_eq!(vec!["From the Day\nI Am They", "When You found me,\nI was so blind\nMy sin was before me,\nI was swallowed by pride", "But out of the darkness,\nYou brought me to Your light\nYou showed me new mercy\nAnd opened up my eyes", "From the day\nYou saved my soul\n'Til the very moment\nWhen I come home", "I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul", "Where brilliant light\nIs all around\nAnd endless joy\nIs the only sound", "Oh, rest my heart\nForever now\nOh, in Your arms\nI'll always be found", "From the day\nYou saved my soul\n'Til the very moment\nWhen I come home", "I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul", "My love is Yours\nMy heart is Yours\nMy life is Yours\nForever", "My love is Yours\nMy heart is Yours\nMy life is Yours\nForever", "From the day\nYou saved my soul\n'Til the very moment\nWhen I come home", "I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul", "From the day\nYou saved my soul\n'Til the very moment\nWhen I come home", "I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul", "Oh Oh Oh\nFrom the day\nYou saved my soul\n"], lyrics);
assert_eq!(
vec![
"From the Day\nI Am They",
"When You found me,\nI was so blind\nMy sin was before me,\nI was swallowed by pride",
"But out of the darkness,\nYou brought me to Your light\nYou showed me new mercy\nAnd opened up my eyes",
"From the day\nYou saved my soul\n'Til the very moment\nWhen I come home",
"I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul",
"Where brilliant light\nIs all around\nAnd endless joy\nIs the only sound",
"Oh, rest my heart\nForever now\nOh, in Your arms\nI'll always be found",
"From the day\nYou saved my soul\n'Til the very moment\nWhen I come home",
"I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul",
"My love is Yours\nMy heart is Yours\nMy life is Yours\nForever",
"My love is Yours\nMy heart is Yours\nMy life is Yours\nForever",
"From the day\nYou saved my soul\n'Til the very moment\nWhen I come home",
"I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul",
"From the day\nYou saved my soul\n'Til the very moment\nWhen I come home",
"I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul",
"Oh Oh Oh\nFrom the day\nYou saved my soul\n"
],
lyrics
);
}
Err(e) => {
assert!(false, "{:?}", e)

View file

@ -7,13 +7,12 @@ use super::{
service_items::ServiceTrait,
slide::Slide,
};
use cosmic::iced::Executor;
use crisp::types::{Keyword, Symbol, Value};
use miette::{IntoDiagnostic, Result};
use serde::{Deserialize, Serialize};
use sqlx::{
pool::PoolConnection, query, query_as, Sqlite, SqliteConnection,
SqlitePool,
Sqlite, SqliteConnection, SqlitePool, pool::PoolConnection,
query, query_as,
};
use std::path::PathBuf;
use tracing::error;
@ -57,7 +56,9 @@ impl Content for Video {
if self.path.exists() {
self.path
.file_name()
.map_or("Missing video".into(), |f| f.to_string_lossy().to_string())
.map_or("Missing video".into(), |f| {
f.to_string_lossy().to_string()
})
} else {
"Missing video".into()
}
@ -196,7 +197,9 @@ impl Model<Video> {
}
}
Err(e) => {
error!("There was an error in converting videos: {e}");
error!(
"There was an error in converting videos: {e}"
);
}
}
}

View file

@ -1,31 +1,32 @@
use clap::{command, Parser};
use clap::{Parser, command};
use core::service_items::ServiceItem;
use core::slide::{Background, Slide, SlideBuilder, TextAlignment, BackgroundKind};
use core::slide::{
Background, BackgroundKind, Slide, SlideBuilder, TextAlignment,
};
use core::songs::Song;
use cosmic::app::context_drawer::ContextDrawer;
use cosmic::app::{Core, Settings, Task};
use cosmic::iced::alignment::Vertical;
use cosmic::iced::keyboard::{Key, Modifiers};
use cosmic::iced::window::{Mode, Position};
use cosmic::iced::{self, event, window, Length, Point};
use cosmic::iced::{self, Length, Point, event, window};
use cosmic::iced_futures::Subscription;
use cosmic::iced_widget::{column, row, stack};
use cosmic::theme;
use cosmic::widget::Container;
use cosmic::widget::dnd_destination::dnd_destination;
use cosmic::widget::nav_bar::nav_bar_style;
use cosmic::widget::segmented_button::Entity;
use cosmic::widget::text;
use cosmic::widget::tooltip::Position as TPosition;
use cosmic::widget::{
button, horizontal_space, mouse_area, nav_bar, search_input,
tooltip, vertical_space, Space,
Space, button, horizontal_space, mouse_area, nav_bar,
search_input, tooltip, vertical_space,
};
use cosmic::widget::{icon, slider};
use cosmic::{executor, Application, ApplicationExt, Element};
use cosmic::{widget::Container, Theme};
use cosmic::{Application, ApplicationExt, Element, executor};
use crisp::types::Value;
use lisp::parse_lisp;
use miette::{miette, Result};
use miette::{Result, miette};
use rayon::prelude::*;
use resvg::usvg::fontdb;
use std::fs::read_to_string;
@ -34,10 +35,10 @@ use std::sync::Arc;
use tracing::{debug, level_filters::LevelFilter};
use tracing::{error, warn};
use tracing_subscriber::EnvFilter;
use ui::EditorMode;
use ui::library::{self, Library};
use ui::presenter::{self, Presenter};
use ui::song_editor::{self, SongEditor};
use ui::EditorMode;
use crate::core::kinds::ServiceItemKind;
use crate::ui::text_svg::{self};
@ -94,9 +95,9 @@ fn main() -> Result<()> {
.map_err(|e| miette!("Invalid things... {}", e))
}
fn theme(_state: &App) -> Theme {
Theme::dark()
}
// fn theme(_state: &App) -> Theme {
// Theme::dark()
// }
struct App {
core: Core,
@ -135,9 +136,6 @@ enum Message {
Quit,
Key(Key, Modifiers),
None,
DndLeave(Entity),
DndEnter(Entity, Vec<String>),
DndDrop,
EditorToggle(bool),
ChangeServiceItem(usize),
AddServiceItem(usize, ServiceItem),
@ -816,10 +814,8 @@ impl cosmic::Application for App {
});
self.windows.push(id);
_ = self.set_window_title(
format!("window_{count}"),
id,
);
_ = self
.set_window_title(format!("window_{count}"), id);
spawn_window.map(|id| {
cosmic::Action::App(Message::WindowOpened(
@ -873,34 +869,6 @@ impl cosmic::Application for App {
Task::none()
}
Message::Quit => cosmic::iced::exit(),
Message::DndEnter(entity, data) => {
debug!(?entity);
debug!(?data);
Task::none()
}
Message::DndDrop => {
// debug!(?entity);
// debug!(?action);
// debug!(?service_item);
if let Some(library) = &self.library
&& let Some((lib, item)) = library.dragged_item
{
// match lib {
// core::model::LibraryKind::Song => ,
// core::model::LibraryKind::Video => todo!(),
// core::model::LibraryKind::Image => todo!(),
// core::model::LibraryKind::Presentation => todo!(),
// }
let item = library.get_song(item).unwrap();
let item = ServiceItem::from(item);
self.nav_model
.insert()
.text(item.title.clone())
.data(item);
}
Task::none()
}
Message::AddLibrary(library) => {
self.library = Some(library);
Task::none()
@ -910,10 +878,6 @@ impl cosmic::Application for App {
Task::none()
}
Message::None => Task::none(),
Message::DndLeave(entity) => {
// debug!(?entity);
Task::none()
}
Message::EditorToggle(edit) => {
if edit {
self.editor_mode = Some(EditorMode::Song);
@ -1006,12 +970,12 @@ impl cosmic::Application for App {
song_editor::Message::ChangeSong(song),
))
}
ServiceItemKind::Video(video) => todo!(),
ServiceItemKind::Image(image) => todo!(),
ServiceItemKind::Presentation(presentation) => {
ServiceItemKind::Video(_video) => todo!(),
ServiceItemKind::Image(_image) => todo!(),
ServiceItemKind::Presentation(_presentation) => {
todo!()
}
ServiceItemKind::Content(slide) => todo!(),
ServiceItemKind::Content(_slide) => todo!(),
}
}
}
@ -1198,7 +1162,7 @@ where
})
}
fn add_library(&mut self) -> Task<Message> {
fn add_library(&self) -> Task<Message> {
Task::perform(async move { Library::new().await }, |x| {
cosmic::Action::App(Message::AddLibrary(x))
})
@ -1220,7 +1184,7 @@ where
}
fn add_service(
&mut self,
&self,
items: Vec<ServiceItem>,
fontdb: Arc<fontdb::Database>,
) -> Task<Message> {

View file

@ -1,3 +1,5 @@
use std::collections::HashMap;
use cosmic::{
iced::{
alignment::Vertical, clipboard::dnd::DndAction,
@ -7,9 +9,10 @@ use cosmic::{
iced_widget::{column, row as rowm, text as textm},
theme,
widget::{
button, container, horizontal_space, icon, mouse_area,
responsive, row, scrollable, text, text_input, Container,
DndSource, Space, Widget,
button, container, context_menu, horizontal_space, icon,
menu::{self, Action as MenuAction},
mouse_area, responsive, row, scrollable, text, text_input,
Container, DndSource, Space,
},
Element, Task,
};
@ -41,6 +44,29 @@ pub(crate) struct Library {
pub dragged_item: Option<(LibraryKind, i32)>,
editing_item: Option<(LibraryKind, i32)>,
db: SqlitePool,
menu_keys: std::collections::HashMap<menu::KeyBind, MenuMessage>,
context_menu: Option<i32>,
}
#[derive(Debug, Clone, Eq, PartialEq, Copy)]
enum MenuMessage {
Delete((LibraryKind, i32)),
Open,
None,
}
impl MenuAction for MenuMessage {
type Message = Message;
fn message(&self) -> Self::Message {
match self {
MenuMessage::Delete((kind, index)) => {
Message::DeleteItem((*kind, *index))
}
MenuMessage::Open => todo!(),
MenuMessage::None => todo!(),
}
}
}
pub(crate) enum Action {
@ -53,7 +79,7 @@ pub(crate) enum Action {
#[derive(Clone, Debug)]
pub(crate) enum Message {
AddItem,
RemoveItem,
DeleteItem((LibraryKind, i32)),
OpenItem(Option<(LibraryKind, i32)>),
HoverLibrary(Option<LibraryKind>),
OpenLibrary(Option<LibraryKind>),
@ -69,6 +95,7 @@ pub(crate) enum Message {
UpdatePresentation(Presentation),
PresentationChanged,
Error(String),
OpenContext(i32),
None,
}
@ -90,6 +117,8 @@ impl<'a> Library {
dragged_item: None,
editing_item: None,
db,
menu_keys: HashMap::new(),
context_menu: None,
}
}
@ -101,7 +130,16 @@ impl<'a> Library {
match message {
Message::AddItem => (),
Message::None => (),
Message::RemoveItem => (),
Message::DeleteItem((kind, index)) => {
match kind {
LibraryKind::Song => todo!(),
LibraryKind::Video => todo!(),
LibraryKind::Image => todo!(),
LibraryKind::Presentation => {
self.presentation_library.remove_item(index);
}
};
}
Message::OpenItem(item) => {
debug!(?item);
self.editing_item = item;
@ -144,7 +182,7 @@ impl<'a> Library {
Task::future(self.db.acquire()).and_then(
move |conn| update_in_db(&song, conn),
),
)
);
}
Err(_) => todo!(),
}
@ -181,7 +219,7 @@ impl<'a> Library {
)
},
),
)
);
}
Err(_) => todo!(),
}
@ -215,7 +253,7 @@ impl<'a> Library {
)
},
),
)
);
}
Err(_) => todo!(),
}
@ -254,6 +292,9 @@ impl<'a> Library {
}
Message::PresentationChanged => (),
Message::Error(_) => (),
Message::OpenContext(index) => {
self.context_menu = Some(index);
}
}
Action::None
}
@ -374,28 +415,46 @@ impl<'a> Library {
let visual_item = self
.single_item(index, item, model)
.map(|()| Message::None);
DndSource::<Message, ServiceItem>::new(
mouse_area(visual_item)
.on_drag(Message::DragItem(service_item.clone()))
.on_enter(Message::HoverItem(
Some((
model.kind,
index as i32,
)),
))
.on_double_click(
Message::OpenItem(Some((
model.kind,
index as i32,
))),
)
.on_exit(Message::HoverItem(None))
.on_press(Message::SelectItem(
Some((
model.kind,
index as i32,
)),
)),
DndSource::<Message, ServiceItem>::new({
let mouse_area = Element::from(mouse_area(visual_item)
.on_drag(Message::DragItem(service_item.clone()))
.on_enter(Message::HoverItem(
Some((
model.kind,
index as i32,
)),
))
.on_double_click(
Message::OpenItem(Some((
model.kind,
index as i32,
))),
)
.on_right_press(Message::OpenContext(index as i32))
.on_exit(Message::HoverItem(None))
.on_press(Message::SelectItem(
Some((
model.kind,
index as i32,
)),
)));
if let Some(context_id) = self.context_menu {
if index == context_id as usize {
let context_menu = context_menu(
mouse_area,
self.context_menu.map_or_else(|| None, |id| {
Some(menu::items(&self.menu_keys,
vec![menu::Item::Button("Delete", None, MenuMessage::Delete((model.kind, index as i32)))]))
})
);
Element::from(context_menu)
} else {
Element::from(mouse_area)
}
} else {
Element::from(mouse_area)
}
}
)
.action(DndAction::Copy)
.drag_icon({
@ -403,8 +462,8 @@ impl<'a> Library {
move |i| {
let state = State::None;
let icon = match model {
LibraryKind::Song => icon::from_name(
"folder-music-symbolic",
LibraryKind::Song => icon::from_name(
"folder-music-symbolic",
).symbolic(true)
,
LibraryKind::Video => icon::from_name("folder-videos-symbolic"),
@ -481,11 +540,10 @@ impl<'a> Library {
.accent_text_color()
.into()
}
} else if let Some((library, selected)) = self.selected_item
} else if let Some((library, selected)) =
self.selected_item
{
if model.kind == library
&& selected == index as i32
{
if model.kind == library && selected == index as i32 {
theme::active().cosmic().control_0().into()
} else {
theme::active()
@ -563,6 +621,7 @@ impl<'a> Library {
.into()
}
#[allow(clippy::unused_async)]
pub async fn search_items(
&self,
query: String,
@ -573,14 +632,18 @@ impl<'a> Library {
.items
.iter()
.filter(|song| song.title.to_lowercase().contains(&query))
.map(super::super::core::content::Content::to_service_item)
.map(
super::super::core::content::Content::to_service_item,
)
.collect();
let videos: Vec<ServiceItem> = self
.video_library
.items
.iter()
.filter(|vid| vid.title.to_lowercase().contains(&query))
.map(super::super::core::content::Content::to_service_item)
.map(
super::super::core::content::Content::to_service_item,
)
.collect();
let images: Vec<ServiceItem> = self
.image_library
@ -589,14 +652,18 @@ impl<'a> Library {
.filter(|image| {
image.title.to_lowercase().contains(&query)
})
.map(super::super::core::content::Content::to_service_item)
.map(
super::super::core::content::Content::to_service_item,
)
.collect();
let presentations: Vec<ServiceItem> = self
.presentation_library
.items
.iter()
.filter(|pres| pres.title.to_lowercase().contains(&query))
.map(super::super::core::content::Content::to_service_item)
.map(
super::super::core::content::Content::to_service_item,
)
.collect();
items.extend(videos);
items.extend(images);

View file

@ -221,7 +221,8 @@ impl Presenter {
let offset = AbsoluteOffset {
x: {
if self.current_slide_index > 2 {
(self.current_slide_index as f32).mul_add(187.5, -187.5)
(self.current_slide_index as f32)
.mul_add(187.5, -187.5)
} else {
0.0
}

View file

@ -1,30 +1,29 @@
use std::{io, path::PathBuf, sync::Arc};
use cosmic::{
Element, Task,
dialog::file_chooser::open::Dialog,
iced::{
font::{Family, Stretch, Style, Weight},
Font, Length,
font::{Family, Stretch, Style, Weight},
},
iced_wgpu::graphics::text::cosmic_text::fontdb,
iced_widget::row,
theme,
widget::{
button, column, combo_box, container, horizontal_space, icon, text, text_editor, text_input,
button, column, combo_box, container, horizontal_space, icon,
text, text_editor, text_input,
},
Element, Task,
};
use dirs::font_dir;
use iced_video_player::Video;
use tracing::{debug, error};
use crate::{
core::{service_items::ServiceTrait, songs::Song},
Background, BackgroundKind, core::songs::Song,
ui::slide_editor::SlideEditor,
Background, BackgroundKind,
};
#[derive(Debug)]
pub struct SongEditor {
pub song: Option<Song>,
@ -244,8 +243,7 @@ impl SongEditor {
Message::ChangeBackground(Ok(path)) => {
debug!(?path);
if let Some(mut song) = self.song.clone() {
let background =
Background::try_from(path).ok();
let background = Background::try_from(path).ok();
self.background_video(&background);
song.background = background;
return self.update_song(song);
@ -258,7 +256,7 @@ impl SongEditor {
return Action::Task(Task::perform(
pick_background(),
Message::ChangeBackground,
))
));
}
_ => (),
}

View file

@ -121,15 +121,18 @@ impl From<&str> for Font {
}
impl Font {
#[must_use] pub fn get_name(&self) -> String {
#[must_use]
pub fn get_name(&self) -> String {
self.name.clone()
}
#[must_use] pub const fn get_weight(&self) -> Weight {
#[must_use]
pub const fn get_weight(&self) -> Weight {
self.weight
}
#[must_use] pub const fn get_style(&self) -> Style {
#[must_use]
pub const fn get_style(&self) -> Style {
self.style
}
@ -148,7 +151,8 @@ impl Font {
self
}
#[must_use] pub const fn size(mut self, size: u8) -> Self {
#[must_use]
pub const fn size(mut self, size: u8) -> Self {
self.size = size;
self
}
@ -236,7 +240,10 @@ impl TextSvg {
self
}
pub const fn alignment(mut self, alignment: TextAlignment) -> Self {
pub const fn alignment(
mut self,
alignment: TextAlignment,
) -> Self {
self.alignment = alignment;
self
}
@ -272,8 +279,8 @@ impl TextSvg {
let middle_position = size.height / 2.0;
let line_spacing = 10.0;
let text_and_line_spacing = font_size + line_spacing;
let starting_y_position =
half_lines.mul_add(-text_and_line_spacing, middle_position);
let starting_y_position = half_lines
.mul_add(-text_and_line_spacing, middle_position);
let text_pieces: Vec<String> = self
.text
@ -282,7 +289,10 @@ impl TextSvg {
.map(|(index, text)| {
format!(
"<tspan x=\"50%\" y=\"{}\">{}</tspan>",
(index as f32).mul_add(text_and_line_spacing, starting_y_position),
(index as f32).mul_add(
text_and_line_spacing,
starting_y_position
),
text
)
})