From 3d6ab2e35f15a3838cdaeee7957aa928368c94e5 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Mon, 24 Feb 2025 15:31:19 -0600 Subject: [PATCH] making songs openable --- src/main.rs | 31 ++++++++++++++++++++++++++++++- src/ui/library.rs | 25 ++++++++++++++++++++----- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 11894f5..ae30cf8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use clap::{command, Parser}; +use core::model::LibraryKind; use core::service_items::{ServiceItem, ServiceItemModel}; use core::slide::*; use cosmic::app::context_drawer::ContextDrawer; @@ -297,6 +298,7 @@ impl cosmic::Application for App { .label("Editor") .spacing(10) .on_toggle(Message::EditorToggle); + let presenter_window = self.windows.get(1); let text = if self.presentation_open { text::body("Close Presentation") @@ -431,8 +433,35 @@ impl cosmic::Application for App { } Message::Library(message) => { - // debug!(?message); + debug!(?message); + let (mut kind, mut index): (LibraryKind, i32) = + (LibraryKind::Song, 0); + let mut opened_item = false; + match message { + library::Message::OpenItem(item) => { + let Some(item) = item else { + return ().into(); + }; + debug!("opening: {:?}", item); + kind = item.0; + index = item.1; + opened_item = true; + } + _ => { + debug!("none"); + } + }; if let Some(library) = &mut self.library { + if opened_item { + if let Some(song) = library.get_song(index) { + self.editor_mode = Some(EditorMode::Song); + let _ = self.song_editor.update( + song_editor::Message::ChangeSong( + song.clone(), + ), + ); + } + } library.update(message).map(|x| { debug!(?x); cosmic::app::Message::App(Message::None) diff --git a/src/ui/library.rs b/src/ui/library.rs index 581d28f..47d54da 100644 --- a/src/ui/library.rs +++ b/src/ui/library.rs @@ -2,6 +2,7 @@ use cosmic::{ iced::{alignment::Vertical, Background, Border, Length}, iced_core::widget::tree, iced_widget::{column, row as rowm, text as textm}, + theme, widget::{ container, horizontal_space, icon, mouse_area, responsive, row, scrollable, text, Container, DndSource, Space, Widget, @@ -37,7 +38,7 @@ pub(crate) struct Library { pub(crate) enum Message { AddItem, RemoveItem, - OpenItem, + OpenItem(Option<(LibraryKind, i32)>), HoverLibrary(Option), OpenLibrary(Option), HoverItem(Option<(LibraryKind, i32)>), @@ -64,12 +65,19 @@ impl Library { } } + pub fn get_song(&self, index: i32) -> Option<&Song> { + self.song_library.get_item(index) + } + pub fn update(&mut self, message: Message) -> Task { match message { Message::AddItem => Task::none(), Message::None => Task::none(), Message::RemoveItem => Task::none(), - Message::OpenItem => Task::none(), + Message::OpenItem(item) => { + debug!(?item); + Task::none() + } Message::HoverLibrary(library_kind) => { self.library_hovered = library_kind; Task::none() @@ -198,6 +206,12 @@ impl Library { index as i32, )), )) + .on_double_click( + Message::OpenItem(Some(( + model.kind, + index as i32, + ))), + ) .on_exit(Message::HoverItem(None)) .on_press(Message::SelectItem( Some(( @@ -222,7 +236,8 @@ impl Library { }) .spacing(2) .width(Length::Fill), - ); + ) + .spacing(5); Container::new(items).padding(5).style(|t| { container::Style::default() .background(Background::Color( @@ -253,7 +268,7 @@ impl Library { .wrapping(textm::Wrapping::None) .into() })) - .center_y(25) + .center_y(20) .center_x(Length::Fill); let icon = icon::from_name({ match model.kind { @@ -276,7 +291,7 @@ impl Library { .wrapping(textm::Wrapping::None) .into() })) - .center_y(25) + .center_y(20) .center_x(Length::Fill); let texts = column([text.into(), subtext.into()]);