making songs openable
This commit is contained in:
parent
07a2a29097
commit
3d6ab2e35f
31
src/main.rs
31
src/main.rs
|
@ -1,4 +1,5 @@
|
||||||
use clap::{command, Parser};
|
use clap::{command, Parser};
|
||||||
|
use core::model::LibraryKind;
|
||||||
use core::service_items::{ServiceItem, ServiceItemModel};
|
use core::service_items::{ServiceItem, ServiceItemModel};
|
||||||
use core::slide::*;
|
use core::slide::*;
|
||||||
use cosmic::app::context_drawer::ContextDrawer;
|
use cosmic::app::context_drawer::ContextDrawer;
|
||||||
|
@ -297,6 +298,7 @@ impl cosmic::Application for App {
|
||||||
.label("Editor")
|
.label("Editor")
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.on_toggle(Message::EditorToggle);
|
.on_toggle(Message::EditorToggle);
|
||||||
|
|
||||||
let presenter_window = self.windows.get(1);
|
let presenter_window = self.windows.get(1);
|
||||||
let text = if self.presentation_open {
|
let text = if self.presentation_open {
|
||||||
text::body("Close Presentation")
|
text::body("Close Presentation")
|
||||||
|
@ -431,8 +433,35 @@ impl cosmic::Application for App {
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::Library(message) => {
|
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 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| {
|
library.update(message).map(|x| {
|
||||||
debug!(?x);
|
debug!(?x);
|
||||||
cosmic::app::Message::App(Message::None)
|
cosmic::app::Message::App(Message::None)
|
||||||
|
|
|
@ -2,6 +2,7 @@ use cosmic::{
|
||||||
iced::{alignment::Vertical, Background, Border, Length},
|
iced::{alignment::Vertical, Background, Border, Length},
|
||||||
iced_core::widget::tree,
|
iced_core::widget::tree,
|
||||||
iced_widget::{column, row as rowm, text as textm},
|
iced_widget::{column, row as rowm, text as textm},
|
||||||
|
theme,
|
||||||
widget::{
|
widget::{
|
||||||
container, horizontal_space, icon, mouse_area, responsive,
|
container, horizontal_space, icon, mouse_area, responsive,
|
||||||
row, scrollable, text, Container, DndSource, Space, Widget,
|
row, scrollable, text, Container, DndSource, Space, Widget,
|
||||||
|
@ -37,7 +38,7 @@ pub(crate) struct Library {
|
||||||
pub(crate) enum Message {
|
pub(crate) enum Message {
|
||||||
AddItem,
|
AddItem,
|
||||||
RemoveItem,
|
RemoveItem,
|
||||||
OpenItem,
|
OpenItem(Option<(LibraryKind, i32)>),
|
||||||
HoverLibrary(Option<LibraryKind>),
|
HoverLibrary(Option<LibraryKind>),
|
||||||
OpenLibrary(Option<LibraryKind>),
|
OpenLibrary(Option<LibraryKind>),
|
||||||
HoverItem(Option<(LibraryKind, i32)>),
|
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<Message> {
|
pub fn update(&mut self, message: Message) -> Task<Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::AddItem => Task::none(),
|
Message::AddItem => Task::none(),
|
||||||
Message::None => Task::none(),
|
Message::None => Task::none(),
|
||||||
Message::RemoveItem => Task::none(),
|
Message::RemoveItem => Task::none(),
|
||||||
Message::OpenItem => Task::none(),
|
Message::OpenItem(item) => {
|
||||||
|
debug!(?item);
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
Message::HoverLibrary(library_kind) => {
|
Message::HoverLibrary(library_kind) => {
|
||||||
self.library_hovered = library_kind;
|
self.library_hovered = library_kind;
|
||||||
Task::none()
|
Task::none()
|
||||||
|
@ -198,6 +206,12 @@ impl Library {
|
||||||
index as i32,
|
index as i32,
|
||||||
)),
|
)),
|
||||||
))
|
))
|
||||||
|
.on_double_click(
|
||||||
|
Message::OpenItem(Some((
|
||||||
|
model.kind,
|
||||||
|
index as i32,
|
||||||
|
))),
|
||||||
|
)
|
||||||
.on_exit(Message::HoverItem(None))
|
.on_exit(Message::HoverItem(None))
|
||||||
.on_press(Message::SelectItem(
|
.on_press(Message::SelectItem(
|
||||||
Some((
|
Some((
|
||||||
|
@ -222,7 +236,8 @@ impl Library {
|
||||||
})
|
})
|
||||||
.spacing(2)
|
.spacing(2)
|
||||||
.width(Length::Fill),
|
.width(Length::Fill),
|
||||||
);
|
)
|
||||||
|
.spacing(5);
|
||||||
Container::new(items).padding(5).style(|t| {
|
Container::new(items).padding(5).style(|t| {
|
||||||
container::Style::default()
|
container::Style::default()
|
||||||
.background(Background::Color(
|
.background(Background::Color(
|
||||||
|
@ -253,7 +268,7 @@ impl Library {
|
||||||
.wrapping(textm::Wrapping::None)
|
.wrapping(textm::Wrapping::None)
|
||||||
.into()
|
.into()
|
||||||
}))
|
}))
|
||||||
.center_y(25)
|
.center_y(20)
|
||||||
.center_x(Length::Fill);
|
.center_x(Length::Fill);
|
||||||
let icon = icon::from_name({
|
let icon = icon::from_name({
|
||||||
match model.kind {
|
match model.kind {
|
||||||
|
@ -276,7 +291,7 @@ impl Library {
|
||||||
.wrapping(textm::Wrapping::None)
|
.wrapping(textm::Wrapping::None)
|
||||||
.into()
|
.into()
|
||||||
}))
|
}))
|
||||||
.center_y(25)
|
.center_y(20)
|
||||||
.center_x(Length::Fill);
|
.center_x(Length::Fill);
|
||||||
|
|
||||||
let texts = column([text.into(), subtext.into()]);
|
let texts = column([text.into(), subtext.into()]);
|
||||||
|
|
Loading…
Reference in a new issue