mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-23 13:20:46 +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()
|
: LayoutBase()
|
||||||
, playback(playback)
|
, playback(playback)
|
||||||
, library(library)
|
, library(library)
|
||||||
, lastPlaylistQueryId(-1) {
|
, lastPlaylistQueryId(-1)
|
||||||
|
, reselectIndex(-1) {
|
||||||
this->InitializeWindows();
|
this->InitializeWindows();
|
||||||
|
|
||||||
this->playback.QueueEdited.connect(this, &NowPlayingLayout::RequeryTrackList);
|
this->playback.QueueEdited.connect(this, &NowPlayingLayout::RequeryTrackList);
|
||||||
@ -164,7 +165,11 @@ void NowPlayingLayout::OnTrackListRequeried(musik::core::db::local::TrackListQue
|
|||||||
this->trackListView->SetSelectedIndex(0);
|
this->trackListView->SetSelectedIndex(0);
|
||||||
}
|
}
|
||||||
else { /* playing... */
|
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);
|
this->trackListView->SetSelectedIndex(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,13 +181,11 @@ void NowPlayingLayout::OnTrackListRequeried(musik::core::db::local::TrackListQue
|
|||||||
scrolled into view */
|
scrolled into view */
|
||||||
this->reselectIndex = std::min((int) this->trackListView->Count() - 1, this->reselectIndex);
|
this->reselectIndex = std::min((int) this->trackListView->Count() - 1, this->reselectIndex);
|
||||||
this->trackListView->SetSelectedIndex((size_t)this->reselectIndex);
|
this->trackListView->SetSelectedIndex((size_t)this->reselectIndex);
|
||||||
auto pos = this->trackListView->GetScrollPosition();
|
|
||||||
int first = (int)pos.firstVisibleEntryIndex;
|
if (!this->trackListView->IsEntryVisible((size_t) this->reselectIndex)) {
|
||||||
int last = (int)first + pos.visibleEntryCount;
|
|
||||||
int index = (int)this->reselectIndex;
|
|
||||||
if (index < first || index >= last) {
|
|
||||||
this->trackListView->ScrollTo((size_t)this->reselectIndex);
|
this->trackListView->ScrollTo((size_t)this->reselectIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->reselectIndex = -1;
|
this->reselectIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,10 +179,7 @@ void TrackListView::ScrollToPlaying() {
|
|||||||
size_t rawIndex = headers.TrackListToAdapterIndex(i);
|
size_t rawIndex = headers.TrackListToAdapterIndex(i);
|
||||||
this->SetSelectedIndex(rawIndex);
|
this->SetSelectedIndex(rawIndex);
|
||||||
|
|
||||||
auto pos = this->GetScrollPosition();
|
if (!this->IsEntryVisible(rawIndex)) {
|
||||||
size_t first = pos.firstVisibleEntryIndex;
|
|
||||||
size_t last = first + pos.visibleEntryCount;
|
|
||||||
if (rawIndex < first || rawIndex >= last) {
|
|
||||||
this->ScrollTo(rawIndex);
|
this->ScrollTo(rawIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,6 +200,13 @@ void ListWindow::OnSelectionChanged(size_t newIndex, size_t oldIndex) {
|
|||||||
/* for subclass use */
|
/* 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) {
|
void ListWindow::SetSelectedIndex(size_t index) {
|
||||||
if (this->selectedIndex != index) {
|
if (this->selectedIndex != index) {
|
||||||
if (index > this->GetScrollAdapter().GetEntryCount() &&
|
if (index > this->GetScrollAdapter().GetEntryCount() &&
|
||||||
|
@ -67,6 +67,7 @@ namespace cursespp {
|
|||||||
|
|
||||||
virtual size_t GetSelectedIndex();
|
virtual size_t GetSelectedIndex();
|
||||||
virtual void SetSelectedIndex(size_t index);
|
virtual void SetSelectedIndex(size_t index);
|
||||||
|
virtual bool IsEntryVisible(size_t index);
|
||||||
|
|
||||||
virtual void OnAdapterChanged();
|
virtual void OnAdapterChanged();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user