mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-06 03:39:50 +00:00
Add new RowDecorator
to TrackListView, with a default implementation. Added
a custom implementation to NowPlayingLayout to make sure the actively playing instance is highlighted, instead of all tracks that have the same ID.
This commit is contained in:
parent
a44c7c76a3
commit
7c800ff817
@ -521,6 +521,11 @@ IRetainedTrack* PlaybackService::GetTrack(size_t index) {
|
||||
|
||||
TrackPtr PlaybackService::GetTrackAtIndex(size_t index) {
|
||||
std::unique_lock<std::recursive_mutex> lock(this->playlistMutex);
|
||||
|
||||
if (index >= this->playlist.Count()) {
|
||||
return TrackPtr();
|
||||
}
|
||||
|
||||
return this->playlist.Get(index);
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,30 @@ NowPlayingLayout::~NowPlayingLayout() {
|
||||
|
||||
}
|
||||
|
||||
int64 NowPlayingLayout::RowDecorator(musik::core::TrackPtr track, size_t index) {
|
||||
bool selected = index == trackList->GetSelectedIndex();
|
||||
int64 attrs = selected ? COLOR_PAIR(CURSESPP_HIGHLIGHTED_LIST_ITEM) : -1LL;
|
||||
size_t playingIndex = playback.GetIndex();
|
||||
|
||||
if (index == playingIndex) {
|
||||
TrackPtr playing = playback.GetTrackAtIndex(playingIndex);
|
||||
|
||||
if (playing &&
|
||||
playing->Id() == track->Id() &&
|
||||
playing->LibraryId() == track->LibraryId())
|
||||
{
|
||||
if (selected) {
|
||||
attrs = COLOR_PAIR(CURSESPP_HIGHLIGHTED_SELECTED_LIST_ITEM);
|
||||
}
|
||||
else {
|
||||
attrs = COLOR_PAIR(CURSESPP_SELECTED_LIST_ITEM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return attrs;
|
||||
}
|
||||
|
||||
void NowPlayingLayout::OnLayout() {
|
||||
this->trackList->MoveAndResize(
|
||||
0,
|
||||
@ -94,7 +118,8 @@ void NowPlayingLayout::InitializeWindows() {
|
||||
this->trackList.reset(new TrackListView(
|
||||
this->playback,
|
||||
this->library,
|
||||
std::bind(formatWithAlbum, std::placeholders::_1, std::placeholders::_2)));
|
||||
std::bind(formatWithAlbum, std::placeholders::_1, std::placeholders::_2),
|
||||
std::bind(&NowPlayingLayout::RowDecorator, this, std::placeholders::_1, std::placeholders::_2)));
|
||||
|
||||
this->trackList->Requeried.connect(this, &NowPlayingLayout::OnTrackListRequeried);
|
||||
this->AddWindow(this->trackList);
|
||||
|
@ -73,6 +73,7 @@ namespace musik {
|
||||
void InitializeWindows();
|
||||
void RequeryTrackList();
|
||||
bool ProcessEditOperation(const std::string& key);
|
||||
int64 RowDecorator(musik::core::TrackPtr track, size_t index);
|
||||
|
||||
musik::core::audio::PlaybackService& playback;
|
||||
musik::core::LibraryPtr library;
|
||||
|
@ -74,7 +74,8 @@ static IScrollAdapter::EntryPtr MISSING_ENTRY = IScrollAdapter::EntryPtr();
|
||||
TrackListView::TrackListView(
|
||||
PlaybackService& playback,
|
||||
LibraryPtr library,
|
||||
RowFormatter formatter)
|
||||
RowFormatter formatter,
|
||||
RowDecorator decorator)
|
||||
: ListWindow(nullptr)
|
||||
, playback(playback) {
|
||||
this->library = library;
|
||||
@ -84,6 +85,7 @@ TrackListView::TrackListView(
|
||||
this->lastQueryHash = 0;
|
||||
this->lastChanged = now();
|
||||
this->formatter = formatter;
|
||||
this->decorator = decorator;
|
||||
|
||||
if (!MISSING_ENTRY) {
|
||||
auto e = std::shared_ptr<SingleLineEntry>(new SingleLineEntry("track missing"));
|
||||
@ -251,25 +253,32 @@ static std::string formatWithoutAlbum(TrackPtr track, size_t width) {
|
||||
}
|
||||
|
||||
IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(cursespp::ScrollableWindow* window, size_t index) {
|
||||
bool selected = index == parent.GetSelectedIndex();
|
||||
int64 attrs = selected ? COLOR_PAIR(CURSESPP_HIGHLIGHTED_LIST_ITEM) : -1LL;
|
||||
|
||||
TrackPtr track = parent.metadata->Get(index);
|
||||
|
||||
if (!track) {
|
||||
return MISSING_ENTRY;
|
||||
}
|
||||
|
||||
TrackPtr playing = parent.playing;
|
||||
if (playing &&
|
||||
playing->Id() == track->Id() &&
|
||||
playing->LibraryId() == track->LibraryId())
|
||||
{
|
||||
if (selected) {
|
||||
attrs = COLOR_PAIR(CURSESPP_HIGHLIGHTED_SELECTED_LIST_ITEM);
|
||||
}
|
||||
else {
|
||||
attrs = COLOR_PAIR(CURSESPP_SELECTED_LIST_ITEM);
|
||||
int64 attrs = -1LL;
|
||||
|
||||
if (parent.decorator) {
|
||||
attrs = parent.decorator(track, index);
|
||||
}
|
||||
else {
|
||||
bool selected = index == parent.GetSelectedIndex();
|
||||
attrs = selected ? COLOR_PAIR(CURSESPP_HIGHLIGHTED_LIST_ITEM) : -1LL;
|
||||
|
||||
TrackPtr playing = parent.playing;
|
||||
if (playing &&
|
||||
playing->Id() == track->Id() &&
|
||||
playing->LibraryId() == track->LibraryId())
|
||||
{
|
||||
if (selected) {
|
||||
attrs = COLOR_PAIR(CURSESPP_HIGHLIGHTED_SELECTED_LIST_ITEM);
|
||||
}
|
||||
else {
|
||||
attrs = COLOR_PAIR(CURSESPP_SELECTED_LIST_ITEM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,14 +60,19 @@ namespace musik {
|
||||
typedef std::function<std::string(
|
||||
musik::core::TrackPtr, size_t)> RowFormatter;
|
||||
|
||||
typedef std::function<int64(
|
||||
musik::core::TrackPtr, size_t)> RowDecorator;
|
||||
|
||||
typedef std::shared_ptr<std::set<size_t> > Headers;
|
||||
|
||||
typedef musik::glue::TrackListQueryBase TrackListQueryBase;
|
||||
|
||||
|
||||
TrackListView(
|
||||
musik::core::audio::PlaybackService& playback,
|
||||
musik::core::LibraryPtr library,
|
||||
RowFormatter formatter = RowFormatter());
|
||||
RowFormatter formatter = RowFormatter(),
|
||||
RowDecorator decorator = RowDecorator());
|
||||
|
||||
virtual ~TrackListView();
|
||||
|
||||
@ -112,6 +117,7 @@ namespace musik {
|
||||
musik::core::LibraryPtr library;
|
||||
size_t lastQueryHash;
|
||||
RowFormatter formatter;
|
||||
RowDecorator decorator;
|
||||
std::chrono::milliseconds lastChanged;
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user