From cd4bb0da3dfa95ed64e5c30242e91b904c5316d1 Mon Sep 17 00:00:00 2001 From: casey langen Date: Sat, 2 Jul 2022 13:42:31 -0700 Subject: [PATCH] Some UI scaffolding to support category filtering in browse view. --- src/musikcube/app/layout/BrowseLayout.cpp | 50 +++++++++++++++++++++-- src/musikcube/app/layout/BrowseLayout.h | 5 ++- src/musikcube/app/util/Hotkeys.cpp | 4 ++ src/musikcube/app/util/Hotkeys.h | 3 ++ src/musikcube/app/util/Messages.h | 1 + 5 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/musikcube/app/layout/BrowseLayout.cpp b/src/musikcube/app/layout/BrowseLayout.cpp index c887d5e1f..34fa8a937 100755 --- a/src/musikcube/app/layout/BrowseLayout.cpp +++ b/src/musikcube/app/layout/BrowseLayout.cpp @@ -129,6 +129,7 @@ BrowseLayout::~BrowseLayout() { } void BrowseLayout::OnLayout() { + const bool showFilter = this->showCategoryListFilter; const int cx = this->GetWidth(); const int x = 0; int cy = this->GetHeight(); @@ -136,7 +137,22 @@ void BrowseLayout::OnLayout() { const int categoryWidth = std::min(kMaxCategoryWidth, cx / 4); - this->categoryList->MoveAndResize(x, y, categoryWidth, cy); + const int categoryListBottomMargin = showFilter ? 1 : 0; + this->categoryList->MoveAndResize(x, y, categoryWidth, cy - categoryListBottomMargin); + + if (showFilter) { + bool refocusFilter = !this->categoryListFilter->IsVisible(); + this->categoryListFilter->Show(); + this->categoryListFilter->MoveAndResize(x + 1, cy - 1, categoryWidth - 2, 1); + if (refocusFilter) { + /* needs to be done during a subsequent tick in the event loop, as the + widget isn't yet visible so can't receive focus. */ + this->Post(cube::message::FocusBrowseFilter); + } + } + else { + this->categoryListFilter->Hide(); + } if (this->playlistModified) { this->modifiedLabel->Show(); @@ -151,7 +167,8 @@ void BrowseLayout::OnLayout() { this->trackList->MoveAndResize(x + categoryWidth, y, cx - categoryWidth, cy); this->categoryList->SetFocusOrder(0); - this->trackList->SetFocusOrder(1); + this->categoryListFilter->SetFocusOrder(1); + this->trackList->SetFocusOrder(2); } void BrowseLayout::InitializeWindows() { @@ -159,6 +176,9 @@ void BrowseLayout::InitializeWindows() { this->categoryList->MouseEvent.connect(this, &BrowseLayout::OnWindowMouseEvent); this->categoryList->SetFrameTitle(_TSTR(DEFAULT_CATEGORY_NAME)); + this->categoryListFilter = std::make_shared(TextInput::StyleLine); + this->categoryListFilter->SetHint("filter"); + this->trackList = std::make_shared(this->playback, this->library); this->trackList->MouseEvent.connect(this, &BrowseLayout::OnWindowMouseEvent); this->trackList->Requeried.connect(this, &BrowseLayout::OnRequeried); @@ -169,6 +189,7 @@ void BrowseLayout::InitializeWindows() { this->modifiedLabel->Hide(); this->AddWindow(this->categoryList); + this->AddWindow(this->categoryListFilter); this->AddWindow(this->trackList); this->AddWindow(this->modifiedLabel); @@ -225,6 +246,11 @@ void BrowseLayout::ProcessMessage(musik::core::runtime::IMessage &message) { break; } + case cube::message::FocusBrowseFilter: { + this->SetFocus(this->categoryListFilter); + break; + } + default: break; } @@ -332,7 +358,16 @@ void BrowseLayout::ShowTrackSortOverlay() { } bool BrowseLayout::KeyPress(const std::string& key) { - if (key == "KEY_ENTER") { + if (key == "^[" && this->showCategoryListFilter) { + if (this->GetFocus() == this->categoryList || + this->GetFocus() == this->categoryListFilter) + { + this->showCategoryListFilter = false; + this->Layout(); + return true; + } + } + else if (key == "KEY_ENTER") { /* if the tracklist is NOT focused (i.e. the focus is on a category window), start playback from the top. */ if (this->GetFocus() != this->trackList) { @@ -343,6 +378,15 @@ bool BrowseLayout::KeyPress(const std::string& key) { } } } + else if (Hotkeys::Is(Hotkeys::BrowseCategoryFilter, key)) { + if (this->GetFocus() == this->categoryList || + this->GetFocus() == this->categoryListFilter) + { + this->showCategoryListFilter = !this->showCategoryListFilter; + this->Layout(); + return true; + } + } else if (Hotkeys::Is(Hotkeys::TrackListChangeSortOrder, key)) { this->ShowTrackSortOverlay(); return true; diff --git a/src/musikcube/app/layout/BrowseLayout.h b/src/musikcube/app/layout/BrowseLayout.h index c4bedda7d..e4b6dccb9 100755 --- a/src/musikcube/app/layout/BrowseLayout.h +++ b/src/musikcube/app/layout/BrowseLayout.h @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -104,11 +105,13 @@ namespace musik { void ShowModifiedLabel(bool show); void ShowTrackSortOverlay(); - bool playlistModified; + bool playlistModified{ false }; + bool showCategoryListFilter{ false }; musik::core::audio::PlaybackService& playback; musik::core::ILibraryPtr library; std::shared_ptr prefs; std::shared_ptr categoryList; + std::shared_ptr categoryListFilter; std::shared_ptr trackList; std::shared_ptr modifiedLabel; HeaderClickHandler categoryListHeaderClickHandler; diff --git a/src/musikcube/app/util/Hotkeys.cpp b/src/musikcube/app/util/Hotkeys.cpp index 012880461..2dcd3c742 100755 --- a/src/musikcube/app/util/Hotkeys.cpp +++ b/src/musikcube/app/util/Hotkeys.cpp @@ -96,6 +96,8 @@ static std::unordered_map NAME_TO_ID = { { "play_queue_hot_swap", Id::PlayQueueHotSwap }, { "play_queue_clear", Id::PlayQueueClear }, + { "browse_category_filter", Id::BrowseCategoryFilter }, + { "browse_playlists_new", Id::BrowsePlaylistsNew }, { "browse_playlists_save", Id::BrowsePlaylistsSave }, { "browse_playlists_rename", Id::BrowsePlaylistsRename }, @@ -187,6 +189,8 @@ static std::unordered_map ID_TO_DEFAULT = { { Id::PlayQueueHotSwap, "M-a" }, { Id::PlayQueueClear, "X" }, + { Id::BrowseCategoryFilter, "M-f" }, + { Id::BrowsePlaylistsSave, "M-s" }, { Id::BrowsePlaylistsNew, "M-n" }, { Id::BrowsePlaylistsRename, "M-r" }, diff --git a/src/musikcube/app/util/Hotkeys.h b/src/musikcube/app/util/Hotkeys.h index babc1a7ca..ed0cd93ef 100755 --- a/src/musikcube/app/util/Hotkeys.h +++ b/src/musikcube/app/util/Hotkeys.h @@ -103,6 +103,9 @@ namespace musik { PlayQueueHotSwap, PlayQueueClear, + /* browse */ + BrowseCategoryFilter, + /* browse -> playlists */ BrowsePlaylistsNew, BrowsePlaylistsSave, diff --git a/src/musikcube/app/util/Messages.h b/src/musikcube/app/util/Messages.h index 0d53dc46a..1733a4250 100644 --- a/src/musikcube/app/util/Messages.h +++ b/src/musikcube/app/util/Messages.h @@ -69,6 +69,7 @@ namespace musik { static const int UpdateEqualizer = First + 18; static const int DebugLog = First + 19; static const int LyricsLoaded = First + 20; + static const int FocusBrowseFilter = First + 21; } }