mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-30 06:32:36 +00:00
Fixed auto-scroll behavior in TrackListView -- had some backwards logic
last night.
This commit is contained in:
parent
6dbde108f7
commit
dd0e413e38
@ -49,6 +49,7 @@
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#define WINDOW_MESSAGE_QUERY_COMPLETED 1002
|
||||
#define WINDOW_MESSAGE_SCROLL_TO_PLAYING 1003
|
||||
|
||||
using namespace musik::core;
|
||||
using namespace musik::core::audio;
|
||||
@ -61,7 +62,7 @@ using namespace boost::chrono;
|
||||
/* if the user hasn't changed the selected index in 30 seconds
|
||||
we assume he's not paying attention, and will automatically scroll
|
||||
the view to the next track if it's invisible. */
|
||||
static const milliseconds AUTO_SCROLL_COOLDOWN = milliseconds(30000LL);
|
||||
static const milliseconds AUTO_SCROLL_COOLDOWN = milliseconds(60000LL);
|
||||
|
||||
static inline milliseconds now() {
|
||||
return duration_cast<milliseconds>(system_clock::now().time_since_epoch());
|
||||
@ -106,11 +107,6 @@ void TrackListView::OnQueryCompleted(IQueryPtr query) {
|
||||
}
|
||||
}
|
||||
|
||||
void TrackListView::OnSelectionChanged(size_t newIndex, size_t oldIndex) {
|
||||
ListWindow::OnSelectionChanged(newIndex, oldIndex);
|
||||
this->lastChanged = now();
|
||||
}
|
||||
|
||||
std::shared_ptr<TrackList> TrackListView::GetTrackList() {
|
||||
return this->metadata;
|
||||
}
|
||||
@ -132,8 +128,7 @@ void TrackListView::ScrollToPlaying() {
|
||||
auto pos = this->GetScrollPosition();
|
||||
size_t first = pos.firstVisibleEntryIndex;
|
||||
size_t last = first + pos.visibleEntryCount;
|
||||
if (i < first || i > last) {
|
||||
/* only scroll if the playing track is not visible. */
|
||||
if (i < first || i >= last) {
|
||||
this->ScrollTo(i);
|
||||
}
|
||||
break;
|
||||
@ -162,22 +157,38 @@ void TrackListView::ProcessMessage(IMessage &message) {
|
||||
this->Requeried(); /* for external handlers */
|
||||
}
|
||||
}
|
||||
else if (message.Type() == WINDOW_MESSAGE_SCROLL_TO_PLAYING) {
|
||||
this->ScrollToPlaying();
|
||||
}
|
||||
}
|
||||
|
||||
bool TrackListView::KeyPress(const std::string& key) {
|
||||
bool handled = false;
|
||||
|
||||
if (Hotkeys::Is(Hotkeys::NavigateJumpToPlaying, key)) {
|
||||
this->ScrollToPlaying();
|
||||
return true;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
return ListWindow::KeyPress(key);
|
||||
handled = ListWindow::KeyPress(key);
|
||||
|
||||
if (handled) {
|
||||
this->lastChanged = now();
|
||||
|
||||
this->DebounceMessage(
|
||||
WINDOW_MESSAGE_SCROLL_TO_PLAYING,
|
||||
0, 0, AUTO_SCROLL_COOLDOWN.count());
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
void TrackListView::OnTrackChanged(size_t index, musik::core::TrackPtr track) {
|
||||
this->playing = track;
|
||||
this->OnAdapterChanged();
|
||||
|
||||
if (now() - lastChanged >= AUTO_SCROLL_COOLDOWN) {
|
||||
if (now() - lastChanged >= AUTO_SCROLL_COOLDOWN)
|
||||
{
|
||||
this->ScrollToPlaying();
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,6 @@ namespace musik {
|
||||
protected:
|
||||
virtual cursespp::IScrollAdapter& GetScrollAdapter();
|
||||
void OnQueryCompleted(musik::core::IQueryPtr query);
|
||||
void OnSelectionChanged(size_t newIndex, size_t oldIndex);
|
||||
|
||||
class Adapter : public cursespp::ScrollAdapterBase {
|
||||
public:
|
||||
|
@ -178,7 +178,9 @@ void ListWindow::SetSelectedIndex(size_t index) {
|
||||
this->selectedIndex = index;
|
||||
|
||||
this->GetScrollAdapter().DrawPage(
|
||||
this, index, &this->GetScrollPosition());
|
||||
this,
|
||||
this->scrollPosition.firstVisibleEntryIndex,
|
||||
&this->GetScrollPosition());
|
||||
|
||||
this->Repaint();
|
||||
|
||||
|
@ -138,6 +138,11 @@ void MessageQueue::Post(IMessagePtr message, int64 delayMs) {
|
||||
this->queue.insert(curr, m);
|
||||
}
|
||||
|
||||
void MessageQueue::Debounce(IMessagePtr message, int delayMs) {
|
||||
Remove(message->Target(), message->Type());
|
||||
Post(message, delayMs);
|
||||
}
|
||||
|
||||
void MessageQueue::Dispatch(IMessagePtr message) {
|
||||
message->Target()->ProcessMessage(*message);
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ namespace cursespp {
|
||||
|
||||
void Post(IMessagePtr message, int64 delayMs = 0);
|
||||
void Remove(IMessageTarget *target, int type = -1);
|
||||
void Debounce(IMessagePtr message, int delayMs = 0);
|
||||
|
||||
void Dispatch();
|
||||
|
||||
private:
|
||||
|
@ -160,6 +160,16 @@ void Window::PostMessage(int messageType, int64 user1, int64 user2, int64 delay)
|
||||
delay);
|
||||
}
|
||||
|
||||
void Window::DebounceMessage(int messageType, int64 user1, int64 user2, int64 delay) {
|
||||
MessageQueue::Instance().Debounce(
|
||||
Message::Create(
|
||||
this,
|
||||
messageType,
|
||||
user1,
|
||||
user2),
|
||||
delay);
|
||||
}
|
||||
|
||||
void Window::RemoveMessage(int messageType) {
|
||||
MessageQueue::Instance().Remove(this, messageType);
|
||||
}
|
||||
|
@ -103,8 +103,11 @@ namespace cursespp {
|
||||
|
||||
protected:
|
||||
IWindow* GetParent() const;
|
||||
|
||||
void PostMessage(int messageType, int64 user1 = 0, int64 user2 = 0, int64 delay = 0);
|
||||
void DebounceMessage(int messageType, int64 user1 = 0, int64 user2 = 0, int64 delay = 0);
|
||||
void RemoveMessage(int messageType);
|
||||
|
||||
void Create();
|
||||
void Destroy();
|
||||
void Recreate();
|
||||
|
Loading…
x
Reference in New Issue
Block a user