Skip to content

Commit

Permalink
Fix oopsie and introduce context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
SO9010 authored and SO9010 committed Jul 25, 2024
1 parent f383da8 commit b9977aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 3 additions & 1 deletion psst-core/src/player/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ impl Queue {

pub fn remove(&mut self, index: usize) {
self.user_items.remove(index);
self.user_items_position -= 1;
if self.user_items_position > 0 {
self.user_items_position -= 1;
}
}

fn handle_added_queue(&mut self) {
Expand Down
23 changes: 12 additions & 11 deletions psst-gui/src/ui/queued.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};

use druid::{
widget::{CrossAxisAlignment, Either, Flex, Label, LineBreaking, List, Scroll}, Data, Env, Lens, LensExt, Widget, WidgetExt
widget::{CrossAxisAlignment, Either, Flex, Label, LineBreaking, List, Scroll}, Data, Env, Lens, LensExt, Menu, MenuItem, Widget, WidgetExt
};
use druid_shell::Cursor;

Expand Down Expand Up @@ -55,16 +55,6 @@ fn queue_header_widget() -> impl Widget<AppState> {
.center(),
0.3,
)
.with_child(
icons::CLOSE_CIRCLE
.scale((16.0, 16.0))
.link()
.rounded(100.0)
.on_click(|ctx, _, _| {
ctx.submit_command(cmd::CLEAR_QUEUE);
})
.with_cursor(Cursor::Pointer),
)
.fix_height(32.0)
.padding(theme::grid(1.0))
.expand_width()
Expand Down Expand Up @@ -92,6 +82,7 @@ fn queue_list_widget() -> impl Widget<Vector<QueueEntryWithIndex>> {
.with_line_break_mode(LineBreaking::Clip)
.expand_width(),
)
.context_menu(|item: &QueueEntryWithIndex| queue_entry_context_menu(item.clone()))
.on_click(|ctx, data, _| {
ctx.submit_command(cmd::SKIP_TO_PLACE_IN_QUEUE.with(data.index));
}),
Expand All @@ -113,4 +104,14 @@ fn queue_list_widget() -> impl Widget<Vector<QueueEntryWithIndex>> {
.rounded(theme::BUTTON_BORDER_RADIUS)
})
.padding(theme::grid(1.0))
}

fn queue_entry_context_menu(item: QueueEntryWithIndex) -> Menu<AppState> {
Menu::new("")
.entry(MenuItem::new("Remove from Queue").on_activate(move |ctx, _, _| {
ctx.submit_command(cmd::REMOVE_FROM_QUEUE.with(item.index));
}))
.entry(MenuItem::new("Clear Queue").on_activate(move |ctx, _, _| {
ctx.submit_command(cmd::CLEAR_QUEUE);
}))
}

0 comments on commit b9977aa

Please sign in to comment.