moving service_list out of nav_bar
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-08-27 09:45:16 -05:00
parent 213e47bf6d
commit aa5e7420f1

View file

@ -235,155 +235,155 @@ impl cosmic::Application for App {
(app, batch) (app, batch)
} }
/// Allows COSMIC to integrate with your application's [`nav_bar::Model`]. // /// Allows COSMIC to integrate with your application's [`nav_bar::Model`].
fn nav_model(&self) -> Option<&nav_bar::Model> { // fn nav_model(&self) -> Option<&nav_bar::Model> {
Some(&self.nav_model) // Some(&self.nav_model)
} // }
fn nav_bar(&self) -> Option<Element<cosmic::Action<Message>>> { // fn nav_bar(&self) -> Option<Element<cosmic::Action<Message>>> {
if !self.core().nav_bar_active() { // if !self.core().nav_bar_active() {
return None; // return None;
} // }
// let nav_model = self.nav_model()?; // // let nav_model = self.nav_model()?;
// let mut nav = cosmic::widget::nav_bar(nav_model, |id| { // // let mut nav = cosmic::widget::nav_bar(nav_model, |id| {
// cosmic::Action::Cosmic(cosmic::app::Action::NavBar(id)) // // cosmic::Action::Cosmic(cosmic::app::Action::NavBar(id))
// }) // // })
// .on_dnd_drop::<ServiceItem>(|entity, data, action| { // // .on_dnd_drop::<ServiceItem>(|entity, data, action| {
// debug!(?entity); // // debug!(?entity);
// debug!(?data); // // debug!(?data);
// debug!(?action); // // debug!(?action);
// cosmic::Action::App(Message::DndDrop) // // cosmic::Action::App(Message::DndDrop)
// }) // // })
// .on_dnd_enter(|entity, data| { // // .on_dnd_enter(|entity, data| {
// debug!("entered"); // // debug!("entered");
// cosmic::Action::App(Message::DndEnter(entity, data)) // // cosmic::Action::App(Message::DndEnter(entity, data))
// }) // // })
// .on_dnd_leave(|entity| { // // .on_dnd_leave(|entity| {
// debug!("left"); // // debug!("left");
// cosmic::Action::App(Message::DndLeave(entity)) // // cosmic::Action::App(Message::DndLeave(entity))
// }) // // })
// .drag_id(DragId::new()) // // .drag_id(DragId::new())
// .on_context(|id| { // // .on_context(|id| {
// cosmic::Action::Cosmic( // // cosmic::Action::Cosmic(
// cosmic::app::Action::NavBarContext(id), // // cosmic::app::Action::NavBarContext(id),
// ) // // )
// }) // // })
// .context_menu(None) // // .context_menu(None)
// .into_container() // // .into_container()
// // XXX both must be shrink to avoid flex layout from ignoring it // // // XXX both must be shrink to avoid flex layout from ignoring it
// .width(Length::Shrink) // // .width(Length::Shrink)
// .height(Length::Shrink); // // .height(Length::Shrink);
let list = self // let list = self
.service // .service
.iter() // .iter()
.enumerate() // .enumerate()
.map(|(index, item)| { // .map(|(index, item)| {
let button = button::standard(item.title.clone()) // let button = button::standard(item.title.clone())
.leading_icon({ // .leading_icon({
match item.kind { // match item.kind {
core::kinds::ServiceItemKind::Song(_) => { // core::kinds::ServiceItemKind::Song(_) => {
icon::from_name("folder-music-symbolic") // icon::from_name("folder-music-symbolic")
}, // },
core::kinds::ServiceItemKind::Video(_) => { // core::kinds::ServiceItemKind::Video(_) => {
icon::from_name("folder-videos-symbolic") // icon::from_name("folder-videos-symbolic")
}, // },
core::kinds::ServiceItemKind::Image(_) => { // core::kinds::ServiceItemKind::Image(_) => {
icon::from_name("folder-pictures-symbolic") // icon::from_name("folder-pictures-symbolic")
}, // },
core::kinds::ServiceItemKind::Presentation(_) => { // core::kinds::ServiceItemKind::Presentation(_) => {
icon::from_name("x-office-presentation-symbolic") // icon::from_name("x-office-presentation-symbolic")
}, // },
core::kinds::ServiceItemKind::Content(_) => { // core::kinds::ServiceItemKind::Content(_) => {
icon::from_name("x-office-presentation-symbolic") // icon::from_name("x-office-presentation-symbolic")
}, // },
} // }
}) // })
.class(cosmic::theme::style::Button::HeaderBar) // .class(cosmic::theme::style::Button::HeaderBar)
.padding(5) // .padding(5)
.width(Length::Fill) // .width(Length::Fill)
.on_press(cosmic::Action::App(Message::ChangeServiceItem(index))); // .on_press(cosmic::Action::App(Message::ChangeServiceItem(index)));
let tooltip = tooltip(button, // let tooltip = tooltip(button,
text::body(item.kind.to_string()), // text::body(item.kind.to_string()),
TPosition::Right); // TPosition::Right);
dnd_destination(tooltip, vec!["application/service-item".into()]) // dnd_destination(tooltip, vec!["application/service-item".into()])
.data_received_for::<ServiceItem>( move |item| { // .data_received_for::<ServiceItem>( move |item| {
if let Some(item) = item { // if let Some(item) = item {
cosmic::Action::App(Message::AddServiceItem(index, item)) // cosmic::Action::App(Message::AddServiceItem(index, item))
} else { // } else {
cosmic::Action::None // cosmic::Action::None
} // }
}).on_drop(move |x, y| { // }).on_drop(move |x, y| {
debug!(x, y); // debug!(x, y);
cosmic::Action::App(Message::AddServiceItemDrop(index)) // cosmic::Action::App(Message::AddServiceItemDrop(index))
}).on_finish(move |mime, data, action, x, y| { // }).on_finish(move |mime, data, action, x, y| {
debug!(mime, ?data, ?action, x, y); // debug!(mime, ?data, ?action, x, y);
let Ok(item) = ServiceItem::try_from((data, mime)) else { // let Ok(item) = ServiceItem::try_from((data, mime)) else {
return cosmic::Action::None; // return cosmic::Action::None;
}; // };
debug!(?item); // debug!(?item);
cosmic::Action::App(Message::AddServiceItem(index, item)) // cosmic::Action::App(Message::AddServiceItem(index, item))
}) // })
.into() // .into()
}); // });
let end_index = self.service.len(); // let end_index = self.service.len();
let column = column![ // let column = column![
text::heading("Service List").center().width(280), // text::heading("Service List").center().width(280),
column(list).spacing(10), // column(list).spacing(10),
dnd_destination( // dnd_destination(
vertical_space(), // vertical_space(),
vec!["application/service-item".into()] // vec!["application/service-item".into()]
) // )
.data_received_for::<ServiceItem>(|item| { // .data_received_for::<ServiceItem>(|item| {
if let Some(item) = item { // if let Some(item) = item {
cosmic::Action::App(Message::AppendServiceItem( // cosmic::Action::App(Message::AppendServiceItem(
item, // item,
)) // ))
} else { // } else {
cosmic::Action::None // cosmic::Action::None
} // }
}) // })
.on_finish( // .on_finish(
move |mime, data, action, x, y| { // move |mime, data, action, x, y| {
debug!(mime, ?data, ?action, x, y); // debug!(mime, ?data, ?action, x, y);
let Ok(item) = // let Ok(item) =
ServiceItem::try_from((data, mime)) // ServiceItem::try_from((data, mime))
else { // else {
return cosmic::Action::None; // return cosmic::Action::None;
}; // };
debug!(?item); // debug!(?item);
cosmic::Action::App(Message::AddServiceItem( // cosmic::Action::App(Message::AddServiceItem(
end_index, item, // end_index, item,
)) // ))
} // }
) // )
] // ]
.padding(10) // .padding(10)
.spacing(10); // .spacing(10);
let padding = Padding::new(0.0).top(20); // let padding = Padding::new(0.0).top(20);
let mut container = Container::new(column) // let mut container = Container::new(column)
// .height(Length::Fill) // // .height(Length::Fill)
.style(nav_bar_style) // .style(nav_bar_style)
.padding(padding); // .padding(padding);
if !self.core().is_condensed() { // if !self.core().is_condensed() {
container = container.max_width(280); // container = container.max_width(280);
} // }
Some(container.into()) // Some(container.into())
} // }
/// Called when a navigation item is selected. /// Called when a navigation item is selected.
fn on_nav_select( // fn on_nav_select(
&mut self, // &mut self,
id: nav_bar::Id, // id: nav_bar::Id,
) -> Task<Self::Message> { // ) -> Task<Self::Message> {
self.nav_model.activate(id); // self.nav_model.activate(id);
// debug!(?id); // // debug!(?id);
self.update_title() // self.update_title()
} // }
fn header_start(&self) -> Vec<Element<Self::Message>> { fn header_start(&self) -> Vec<Element<Self::Message>> {
vec![] vec![]
@ -998,6 +998,9 @@ impl cosmic::Application for App {
)) ))
}; };
let service_list =
Container::new(self.service_list()).padding(5);
let slide_preview = column![ let slide_preview = column![
Space::with_height(Length::Fill), Space::with_height(Length::Fill),
Container::new( Container::new(
@ -1048,6 +1051,7 @@ impl cosmic::Application for App {
self.song_editor.view().map(Message::SongEditor); self.song_editor.view().map(Message::SongEditor);
let row = row![ let row = row![
service_list,
Container::new( Container::new(
button::icon(icon_left) button::icon(icon_left)
.icon_size(128) .icon_size(128)
@ -1212,6 +1216,101 @@ where
_ => Task::none(), _ => Task::none(),
} }
} }
fn service_list(&self) -> Element<Message> {
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::<ServiceItem>( 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::<ServiceItem>(|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)] #[cfg(test)]