mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-20 13:21:01 +00:00
Fixed weird auto scroll behavior in NowPlayingLayout when manually
selecting a new play index. Also, added ListWindow::IsEntryVisible().
This commit is contained in:
parent
82485ba6f3
commit
23b8b3cc9e
@ -68,7 +68,8 @@ NowPlayingLayout::NowPlayingLayout(
|
||||
: LayoutBase()
|
||||
, playback(playback)
|
||||
, library(library)
|
||||
, lastPlaylistQueryId(-1) {
|
||||
, lastPlaylistQueryId(-1)
|
||||
, reselectIndex(-1) {
|
||||
this->InitializeWindows();
|
||||
|
||||
this->playback.QueueEdited.connect(this, &NowPlayingLayout::RequeryTrackList);
|
||||
@ -164,7 +165,11 @@ void NowPlayingLayout::OnTrackListRequeried(musik::core::db::local::TrackListQue
|
||||
this->trackListView->SetSelectedIndex(0);
|
||||
}
|
||||
else { /* playing... */
|
||||
this->trackListView->ScrollTo(index == 0 ? index : index - 1);
|
||||
size_t scrollToIndex = index == 0 ? index : index - 1;
|
||||
if (!this->trackListView->IsEntryVisible(scrollToIndex)) {
|
||||
this->trackListView->ScrollTo(scrollToIndex);
|
||||
}
|
||||
|
||||
this->trackListView->SetSelectedIndex(index);
|
||||
}
|
||||
}
|
||||
@ -176,13 +181,11 @@ void NowPlayingLayout::OnTrackListRequeried(musik::core::db::local::TrackListQue
|
||||
scrolled into view */
|
||||
this->reselectIndex = std::min((int) this->trackListView->Count() - 1, this->reselectIndex);
|
||||
this->trackListView->SetSelectedIndex((size_t)this->reselectIndex);
|
||||
auto pos = this->trackListView->GetScrollPosition();
|
||||
int first = (int)pos.firstVisibleEntryIndex;
|
||||
int last = (int)first + pos.visibleEntryCount;
|
||||
int index = (int)this->reselectIndex;
|
||||
if (index < first || index >= last) {
|
||||
|
||||
if (!this->trackListView->IsEntryVisible((size_t) this->reselectIndex)) {
|
||||
this->trackListView->ScrollTo((size_t)this->reselectIndex);
|
||||
}
|
||||
|
||||
this->reselectIndex = -1;
|
||||
}
|
||||
|
||||
|
@ -179,10 +179,7 @@ void TrackListView::ScrollToPlaying() {
|
||||
size_t rawIndex = headers.TrackListToAdapterIndex(i);
|
||||
this->SetSelectedIndex(rawIndex);
|
||||
|
||||
auto pos = this->GetScrollPosition();
|
||||
size_t first = pos.firstVisibleEntryIndex;
|
||||
size_t last = first + pos.visibleEntryCount;
|
||||
if (rawIndex < first || rawIndex >= last) {
|
||||
if (!this->IsEntryVisible(rawIndex)) {
|
||||
this->ScrollTo(rawIndex);
|
||||
}
|
||||
|
||||
|
@ -200,6 +200,13 @@ void ListWindow::OnSelectionChanged(size_t newIndex, size_t oldIndex) {
|
||||
/* for subclass use */
|
||||
}
|
||||
|
||||
bool ListWindow::IsEntryVisible(size_t index) {
|
||||
auto pos = this->GetScrollPosition();
|
||||
size_t first = pos.firstVisibleEntryIndex;
|
||||
size_t last = first + pos.visibleEntryCount;
|
||||
return (index >= first && index < last);
|
||||
}
|
||||
|
||||
void ListWindow::SetSelectedIndex(size_t index) {
|
||||
if (this->selectedIndex != index) {
|
||||
if (index > this->GetScrollAdapter().GetEntryCount() &&
|
||||
|
@ -67,6 +67,7 @@ namespace cursespp {
|
||||
|
||||
virtual size_t GetSelectedIndex();
|
||||
virtual void SetSelectedIndex(size_t index);
|
||||
virtual bool IsEntryVisible(size_t index);
|
||||
|
||||
virtual void OnAdapterChanged();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user