mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-14 13:21:13 +00:00
Fixed list selection bug in ListOverlay -- should work properly now.
This commit is contained in:
parent
f79daccb1e
commit
26c0950d56
@ -77,6 +77,8 @@ void VisualizerOverlay::Show() {
|
||||
|
||||
for (size_t i = 0; i < vis::VisualizerCount(); i++) {
|
||||
adapter->AddEntry(vis::GetVisualizer(i)->Name());
|
||||
adapter->AddEntry(vis::GetVisualizer(i)->Name());
|
||||
adapter->AddEntry(vis::GetVisualizer(i)->Name());
|
||||
}
|
||||
|
||||
adapter->SetSelectable(true);
|
||||
@ -86,7 +88,7 @@ void VisualizerOverlay::Show() {
|
||||
dialog->SetAdapter(adapter)
|
||||
.SetTitle("visualizers")
|
||||
.SetItemSelectedCallback(
|
||||
[&](cursespp::IScrollAdapterPtr adapter, size_t index) {
|
||||
[](cursespp::IScrollAdapterPtr adapter, size_t index) {
|
||||
vis::SetSelectedVisualizer(vis::GetVisualizer(index));
|
||||
vis::SelectedVisualizer()->Show();
|
||||
});
|
||||
|
@ -170,7 +170,7 @@ void ListWindow::PageDown() {
|
||||
|
||||
void ListWindow::ScrollTo(size_t index) {
|
||||
this->GetScrollAdapter().DrawPage(
|
||||
this, index, &this->GetScrollPosition());
|
||||
this, index, &this->GetMutableScrollPosition());
|
||||
|
||||
this->Repaint();
|
||||
}
|
||||
@ -187,7 +187,7 @@ void ListWindow::SetSelectedIndex(size_t index) {
|
||||
this->GetScrollAdapter().DrawPage(
|
||||
this,
|
||||
this->scrollPosition.firstVisibleEntryIndex,
|
||||
&this->GetScrollPosition());
|
||||
&this->GetMutableScrollPosition());
|
||||
|
||||
this->Repaint();
|
||||
|
||||
@ -223,7 +223,11 @@ void ListWindow::OnDimensionsChanged() {
|
||||
this->ScrollTo(this->selectedIndex);
|
||||
}
|
||||
|
||||
IScrollAdapter::ScrollPosition& ListWindow::GetScrollPosition() {
|
||||
IScrollAdapter::ScrollPosition& ListWindow::GetMutableScrollPosition() {
|
||||
this->scrollPosition.logicalIndex = this->GetSelectedIndex(); /* hack */
|
||||
return this->scrollPosition;
|
||||
}
|
||||
|
||||
const IScrollAdapter::ScrollPosition& ListWindow::GetScrollPosition() {
|
||||
return this->GetMutableScrollPosition();
|
||||
}
|
||||
|
@ -70,13 +70,15 @@ namespace cursespp {
|
||||
|
||||
virtual void OnAdapterChanged();
|
||||
|
||||
virtual const IScrollAdapter::ScrollPosition& GetScrollPosition();
|
||||
|
||||
protected:
|
||||
virtual void OnSelectionChanged(size_t newIndex, size_t oldIndex);
|
||||
virtual void OnInvalidated();
|
||||
virtual void OnDimensionsChanged();
|
||||
|
||||
virtual IScrollAdapter& GetScrollAdapter();
|
||||
virtual IScrollAdapter::ScrollPosition& GetScrollPosition();
|
||||
virtual IScrollAdapter::ScrollPosition& GetMutableScrollPosition();
|
||||
|
||||
private:
|
||||
IScrollAdapter* adapter;
|
||||
|
@ -67,7 +67,10 @@ size_t ScrollAdapterBase::GetLineCount() {
|
||||
}
|
||||
|
||||
void ScrollAdapterBase::GetVisibleItems(
|
||||
size_t desired, std::deque<EntryPtr>& target, size_t& start)
|
||||
cursespp::ScrollableWindow* window,
|
||||
size_t desired,
|
||||
std::deque<EntryPtr>&
|
||||
target, size_t& start)
|
||||
{
|
||||
size_t actual = desired;
|
||||
|
||||
@ -79,7 +82,7 @@ void ScrollAdapterBase::GetVisibleItems(
|
||||
/* forward search first... */
|
||||
int end = (int) GetEntryCount();
|
||||
for (int i = (int) desired; i < end && totalHeight > 0; i++) {
|
||||
EntryPtr entry = this->GetEntry(DUMMY_SCROLLABLE_WINDOW, i);
|
||||
EntryPtr entry = this->GetEntry(window, i);
|
||||
entry->SetWidth(this->width);
|
||||
totalHeight -= entry->GetLineCount();
|
||||
target.push_back(entry);
|
||||
@ -92,7 +95,7 @@ void ScrollAdapterBase::GetVisibleItems(
|
||||
totalHeight = this->height;
|
||||
int i = GetEntryCount() - 1;
|
||||
while (i >= 0 && totalHeight >= 0) {
|
||||
EntryPtr entry = this->GetEntry(DUMMY_SCROLLABLE_WINDOW, i);
|
||||
EntryPtr entry = this->GetEntry(window, i);
|
||||
entry->SetWidth(this->width);
|
||||
|
||||
int lines = entry->GetLineCount();
|
||||
@ -138,7 +141,7 @@ void ScrollAdapterBase::DrawPage(ScrollableWindow* scrollable, size_t index, Scr
|
||||
|
||||
std::deque<EntryPtr> visible;
|
||||
size_t topIndex; /* calculated by GetVisibleItems */
|
||||
GetVisibleItems(index, visible, topIndex);
|
||||
GetVisibleItems(scrollable, index, visible, topIndex);
|
||||
|
||||
size_t drawnLines = 0;
|
||||
|
||||
|
@ -64,7 +64,12 @@ namespace cursespp {
|
||||
virtual void SetItemDecorator(ItemDecorator decorator) { this->decorator = decorator; }
|
||||
|
||||
protected:
|
||||
void GetVisibleItems(size_t desired, std::deque<EntryPtr>& target, size_t& start);
|
||||
void GetVisibleItems(
|
||||
cursespp::ScrollableWindow* window,
|
||||
size_t desired,
|
||||
std::deque<EntryPtr>& target,
|
||||
size_t& start);
|
||||
|
||||
virtual ItemDecorator GetItemDecorator() { return this->decorator; }
|
||||
|
||||
size_t GetWidth() { return this->width; }
|
||||
|
@ -78,7 +78,7 @@ ScrollPos& ScrollableWindow::GetMutableScrollPosition() {
|
||||
return this->scrollPosition;
|
||||
}
|
||||
|
||||
const ScrollPos& ScrollableWindow::GetScrollPosition() const {
|
||||
const ScrollPos& ScrollableWindow::GetScrollPosition() {
|
||||
return this->scrollPosition;
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ namespace cursespp {
|
||||
|
||||
void SetAllowArrowKeyPropagation(bool allow = true);
|
||||
|
||||
const IScrollAdapter::ScrollPosition& GetScrollPosition() const;
|
||||
virtual const IScrollAdapter::ScrollPosition& GetScrollPosition();
|
||||
|
||||
protected:
|
||||
virtual IScrollAdapter& GetScrollAdapter() = 0;
|
||||
|
@ -77,7 +77,7 @@ EntryPtr SimpleScrollAdapter::GetEntry(cursespp::ScrollableWindow* window, size_
|
||||
auto entry = this->entries.at(index);
|
||||
|
||||
SingleLineEntry* styleable = static_cast<SingleLineEntry*>(entry.get());
|
||||
styleable->SetAttrs(COLOR_PAIR(CURSESPP_TEXT_DEFAULT));
|
||||
styleable->SetAttrs(-1LL);
|
||||
|
||||
if (window && this->selectable) {
|
||||
if (index == window->GetScrollPosition().logicalIndex) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user