diff --git a/Cargo.toml b/Cargo.toml index fd26207..4f5c510 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ description = "A cli presentation system" [dependencies] clap = { version = "4.5.20", features = ["debug", "derive"] } +libcosmic = { git = "https://github.com/pop-os/libcosmic", default-features = false, features = ["debug", "winit", "desktop", "winit_wgpu", "winit_tokio", "tokio", "rfd", "dbus-config", "a11y", "wgpu", "multi-window"] } lexpr = "0.2.7" miette = { version = "7.2.0", features = ["fancy"] } pretty_assertions = "1.4.1" @@ -38,11 +39,6 @@ rayon = "1.11.0" # mupdf = "0.5.0" # rfd = { version = "0.12.1", features = ["xdg-portal"], default-features = false } -[dependencies.libcosmic] -git = "https://github.com/pop-os/libcosmic" -default-features = false -features = ["debug", "winit", "desktop", "winit_wgpu", "winit_tokio", "tokio", "rfd", "dbus-config", "a11y", "wgpu", "multi-window"] - [dependencies.iced_video_player] git = "https://github.com/jackpot51/iced_video_player.git" branch = "cosmic" diff --git a/src/main.rs b/src/main.rs index dfa0858..9d1cd41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -235,155 +235,155 @@ impl cosmic::Application for App { (app, batch) } - // /// Allows COSMIC to integrate with your application's [`nav_bar::Model`]. - // fn nav_model(&self) -> Option<&nav_bar::Model> { - // Some(&self.nav_model) - // } + /// Allows COSMIC to integrate with your application's [`nav_bar::Model`]. + fn nav_model(&self) -> Option<&nav_bar::Model> { + Some(&self.nav_model) + } - // fn nav_bar(&self) -> Option>> { - // if !self.core().nav_bar_active() { - // return None; - // } + fn nav_bar(&self) -> Option>> { + if !self.core().nav_bar_active() { + return None; + } - // // let nav_model = self.nav_model()?; + // let nav_model = self.nav_model()?; - // // let mut nav = cosmic::widget::nav_bar(nav_model, |id| { - // // cosmic::Action::Cosmic(cosmic::app::Action::NavBar(id)) - // // }) - // // .on_dnd_drop::(|entity, data, action| { - // // debug!(?entity); - // // debug!(?data); - // // debug!(?action); - // // cosmic::Action::App(Message::DndDrop) - // // }) - // // .on_dnd_enter(|entity, data| { - // // debug!("entered"); - // // cosmic::Action::App(Message::DndEnter(entity, data)) - // // }) - // // .on_dnd_leave(|entity| { - // // debug!("left"); - // // cosmic::Action::App(Message::DndLeave(entity)) - // // }) - // // .drag_id(DragId::new()) - // // .on_context(|id| { - // // cosmic::Action::Cosmic( - // // cosmic::app::Action::NavBarContext(id), - // // ) - // // }) - // // .context_menu(None) - // // .into_container() - // // // XXX both must be shrink to avoid flex layout from ignoring it - // // .width(Length::Shrink) - // // .height(Length::Shrink); + // let mut nav = cosmic::widget::nav_bar(nav_model, |id| { + // cosmic::Action::Cosmic(cosmic::app::Action::NavBar(id)) + // }) + // .on_dnd_drop::(|entity, data, action| { + // debug!(?entity); + // debug!(?data); + // debug!(?action); + // cosmic::Action::App(Message::DndDrop) + // }) + // .on_dnd_enter(|entity, data| { + // debug!("entered"); + // cosmic::Action::App(Message::DndEnter(entity, data)) + // }) + // .on_dnd_leave(|entity| { + // debug!("left"); + // cosmic::Action::App(Message::DndLeave(entity)) + // }) + // .drag_id(DragId::new()) + // .on_context(|id| { + // cosmic::Action::Cosmic( + // cosmic::app::Action::NavBarContext(id), + // ) + // }) + // .context_menu(None) + // .into_container() + // // XXX both must be shrink to avoid flex layout from ignoring it + // .width(Length::Shrink) + // .height(Length::Shrink); - // let list = self - // .service - // .iter() - // .enumerate() - // .map(|(index, item)| { - // let button = button::standard(item.title.clone()) - // .leading_icon({ - // match item.kind { - // core::kinds::ServiceItemKind::Song(_) => { - // icon::from_name("folder-music-symbolic") - // }, - // core::kinds::ServiceItemKind::Video(_) => { - // icon::from_name("folder-videos-symbolic") - // }, - // core::kinds::ServiceItemKind::Image(_) => { - // icon::from_name("folder-pictures-symbolic") - // }, - // core::kinds::ServiceItemKind::Presentation(_) => { - // icon::from_name("x-office-presentation-symbolic") - // }, - // core::kinds::ServiceItemKind::Content(_) => { - // icon::from_name("x-office-presentation-symbolic") - // }, - // } - // }) - // .class(cosmic::theme::style::Button::HeaderBar) - // .padding(5) - // .width(Length::Fill) - // .on_press(cosmic::Action::App(Message::ChangeServiceItem(index))); - // let tooltip = tooltip(button, - // text::body(item.kind.to_string()), - // TPosition::Right); - // dnd_destination(tooltip, vec!["application/service-item".into()]) - // .data_received_for::( move |item| { - // if let Some(item) = item { - // cosmic::Action::App(Message::AddServiceItem(index, item)) - // } else { - // cosmic::Action::None - // } - // }).on_drop(move |x, y| { - // debug!(x, y); - // cosmic::Action::App(Message::AddServiceItemDrop(index)) - // }).on_finish(move |mime, data, action, x, y| { - // debug!(mime, ?data, ?action, x, y); - // let Ok(item) = ServiceItem::try_from((data, mime)) else { - // return cosmic::Action::None; - // }; - // debug!(?item); - // cosmic::Action::App(Message::AddServiceItem(index, item)) - // }) - // .into() - // }); + let list = self + .service + .iter() + .enumerate() + .map(|(index, item)| { + let button = button::standard(item.title.clone()) + .leading_icon({ + match item.kind { + core::kinds::ServiceItemKind::Song(_) => { + icon::from_name("folder-music-symbolic") + }, + core::kinds::ServiceItemKind::Video(_) => { + icon::from_name("folder-videos-symbolic") + }, + core::kinds::ServiceItemKind::Image(_) => { + icon::from_name("folder-pictures-symbolic") + }, + core::kinds::ServiceItemKind::Presentation(_) => { + icon::from_name("x-office-presentation-symbolic") + }, + core::kinds::ServiceItemKind::Content(_) => { + icon::from_name("x-office-presentation-symbolic") + }, + } + }) + .class(cosmic::theme::style::Button::HeaderBar) + .padding(5) + .width(Length::Fill) + .on_press(cosmic::Action::App(Message::ChangeServiceItem(index))); + let tooltip = tooltip(button, + text::body(item.kind.to_string()), + TPosition::Right); + dnd_destination(tooltip, vec!["application/service-item".into()]) + .data_received_for::( move |item| { + if let Some(item) = item { + cosmic::Action::App(Message::AddServiceItem(index, item)) + } else { + cosmic::Action::None + } + }).on_drop(move |x, y| { + debug!(x, y); + cosmic::Action::App(Message::AddServiceItemDrop(index)) + }).on_finish(move |mime, data, action, x, y| { + debug!(mime, ?data, ?action, x, y); + let Ok(item) = ServiceItem::try_from((data, mime)) else { + return cosmic::Action::None; + }; + debug!(?item); + cosmic::Action::App(Message::AddServiceItem(index, item)) + }) + .into() + }); - // let end_index = self.service.len(); - // let column = column![ - // text::heading("Service List").center().width(280), - // column(list).spacing(10), - // dnd_destination( - // vertical_space(), - // vec!["application/service-item".into()] - // ) - // .data_received_for::(|item| { - // if let Some(item) = item { - // cosmic::Action::App(Message::AppendServiceItem( - // item, - // )) - // } else { - // cosmic::Action::None - // } - // }) - // .on_finish( - // move |mime, data, action, x, y| { - // debug!(mime, ?data, ?action, x, y); - // let Ok(item) = - // ServiceItem::try_from((data, mime)) - // else { - // return cosmic::Action::None; - // }; - // debug!(?item); - // cosmic::Action::App(Message::AddServiceItem( - // end_index, item, - // )) - // } - // ) - // ] - // .padding(10) - // .spacing(10); - // let padding = Padding::new(0.0).top(20); - // let mut container = Container::new(column) - // // .height(Length::Fill) - // .style(nav_bar_style) - // .padding(padding); + let end_index = self.service.len(); + let column = column![ + text::heading("Service List").center().width(280), + column(list).spacing(10), + dnd_destination( + vertical_space(), + vec!["application/service-item".into()] + ) + .data_received_for::(|item| { + if let Some(item) = item { + cosmic::Action::App(Message::AppendServiceItem( + item, + )) + } else { + cosmic::Action::None + } + }) + .on_finish( + move |mime, data, action, x, y| { + debug!(mime, ?data, ?action, x, y); + let Ok(item) = + ServiceItem::try_from((data, mime)) + else { + return cosmic::Action::None; + }; + debug!(?item); + cosmic::Action::App(Message::AddServiceItem( + end_index, item, + )) + } + ) + ] + .padding(10) + .spacing(10); + let padding = Padding::new(0.0).top(20); + let mut container = Container::new(column) + // .height(Length::Fill) + .style(nav_bar_style) + .padding(padding); - // if !self.core().is_condensed() { - // container = container.max_width(280); - // } - // Some(container.into()) - // } + if !self.core().is_condensed() { + container = container.max_width(280); + } + Some(container.into()) + } /// Called when a navigation item is selected. - // fn on_nav_select( - // &mut self, - // id: nav_bar::Id, - // ) -> Task { - // self.nav_model.activate(id); - // // debug!(?id); - // self.update_title() - // } + fn on_nav_select( + &mut self, + id: nav_bar::Id, + ) -> Task { + self.nav_model.activate(id); + // debug!(?id); + self.update_title() + } fn header_start(&self) -> Vec> { vec![] @@ -998,9 +998,6 @@ impl cosmic::Application for App { )) }; - let service_list = - Container::new(self.service_list()).padding(5); - let slide_preview = column![ Space::with_height(Length::Fill), Container::new( @@ -1051,7 +1048,6 @@ impl cosmic::Application for App { self.song_editor.view().map(Message::SongEditor); let row = row![ - service_list, Container::new( button::icon(icon_left) .icon_size(128) @@ -1216,101 +1212,6 @@ where _ => Task::none(), } } - - fn service_list(&self) -> Element { - let list = self - .service - .iter() - .enumerate() - .map(|(index, item)| { - let button = button::standard(item.title.clone()) - .leading_icon({ - match item.kind { - core::kinds::ServiceItemKind::Song(_) => { - icon::from_name("folder-music-symbolic") - }, - core::kinds::ServiceItemKind::Video(_) => { - icon::from_name("folder-videos-symbolic") - }, - core::kinds::ServiceItemKind::Image(_) => { - icon::from_name("folder-pictures-symbolic") - }, - core::kinds::ServiceItemKind::Presentation(_) => { - icon::from_name("x-office-presentation-symbolic") - }, - core::kinds::ServiceItemKind::Content(_) => { - icon::from_name("x-office-presentation-symbolic") - }, - } - }) - .class(cosmic::theme::style::Button::HeaderBar) - .padding(5) - .width(Length::Fill) - .on_press(Message::ChangeServiceItem(index)); - let tooltip = tooltip(button, - text::body(item.kind.to_string()), - TPosition::Right); - dnd_destination(tooltip, vec!["application/service-item".into()]) - .data_received_for::( move |item| { - if let Some(item) = item { - Message::AddServiceItem(index, item) - } else { - Message::None - } - }).on_drop(move |x, y| { - debug!(x, y); - Message::AddServiceItemDrop(index) - }).on_finish(move |mime, data, action, x, y| { - debug!(mime, ?data, ?action, x, y); - let Ok(item) = ServiceItem::try_from((data, mime)) else { - return Message::None; - }; - debug!(?item); - Message::AddServiceItem(index, item) - }) - .into() - }); - - let end_index = self.service.len(); - let column = column![ - text::heading("Service List").center().width(280), - iced::widget::horizontal_rule(1), - column(list).spacing(10), - dnd_destination( - vertical_space(), - vec!["application/service-item".into()] - ) - .data_received_for::(|item| { - if let Some(item) = item { - Message::AppendServiceItem(item) - } else { - Message::None - } - }) - .on_finish( - move |mime, data, action, x, y| { - debug!(mime, ?data, ?action, x, y); - let Ok(item) = - ServiceItem::try_from((data, mime)) - else { - return Message::None; - }; - debug!(?item); - Message::AddServiceItem(end_index, item) - } - ) - ] - .padding(10) - .spacing(10); - let mut container = Container::new(column) - // .height(Length::Fill) - .style(nav_bar_style); - - if !self.core().is_condensed() { - container = container.max_width(280); - } - container.into() - } } #[cfg(test)]