mirror of
https://github.com/clangen/musikcube.git
synced 2025-04-10 12:44:32 +00:00
Added a "SelectionChanged" event to ListWindow
This commit is contained in:
parent
d1f2d867f5
commit
c259e911db
@ -13,14 +13,14 @@ ListWindow::~ListWindow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ListWindow::ScrollToTop() {
|
void ListWindow::ScrollToTop() {
|
||||||
this->selectedIndex = 0;
|
this->SetSelectedIndex(0);
|
||||||
this->GetScrollAdapter().DrawPage(this->GetContent(), 0, &scrollPosition);
|
this->GetScrollAdapter().DrawPage(this->GetContent(), 0, &scrollPosition);
|
||||||
this->Repaint();
|
this->Repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListWindow::ScrollToBottom() {
|
void ListWindow::ScrollToBottom() {
|
||||||
IScrollAdapter& adapter = this->GetScrollAdapter();
|
IScrollAdapter& adapter = this->GetScrollAdapter();
|
||||||
this->selectedIndex = adapter.GetEntryCount() - 1;
|
this->SetSelectedIndex(max(0, adapter.GetEntryCount() - 1));
|
||||||
adapter.DrawPage(this->GetContent(), selectedIndex, &scrollPosition);
|
adapter.DrawPage(this->GetContent(), selectedIndex, &scrollPosition);
|
||||||
this->Repaint();
|
this->Repaint();
|
||||||
}
|
}
|
||||||
@ -48,9 +48,10 @@ void ListWindow::ScrollUp(int delta) {
|
|||||||
drawIndex = newIndex - 1;
|
drawIndex = newIndex - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedIndex = newIndex;
|
|
||||||
|
|
||||||
drawIndex = max(0, drawIndex);
|
drawIndex = max(0, drawIndex);
|
||||||
|
|
||||||
|
this->SetSelectedIndex(newIndex);
|
||||||
|
|
||||||
adapter.DrawPage(this->GetContent(), drawIndex, &this->scrollPosition);
|
adapter.DrawPage(this->GetContent(), drawIndex, &this->scrollPosition);
|
||||||
|
|
||||||
this->Repaint();
|
this->Repaint();
|
||||||
@ -72,7 +73,7 @@ void ListWindow::ScrollDown(int delta) {
|
|||||||
drawIndex = drawIndex + delta;
|
drawIndex = drawIndex + delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedIndex = newIndex;
|
this->SetSelectedIndex(newIndex);
|
||||||
|
|
||||||
adapter.DrawPage(this->GetContent(), drawIndex, &this->scrollPosition);
|
adapter.DrawPage(this->GetContent(), drawIndex, &this->scrollPosition);
|
||||||
|
|
||||||
@ -88,7 +89,8 @@ void ListWindow::PageUp() {
|
|||||||
the top of the list. otherwise, scroll down by one to give indication
|
the top of the list. otherwise, scroll down by one to give indication
|
||||||
there is more to see. */
|
there is more to see. */
|
||||||
target = (target > 0) ? target + 1 : 0;
|
target = (target > 0) ? target + 1 : 0;
|
||||||
this->selectedIndex = (target == 0) ? 0 : target + 1;
|
|
||||||
|
this->SetSelectedIndex((target == 0) ? 0 : target + 1);
|
||||||
|
|
||||||
adapter.DrawPage(this->GetContent(), target, &this->scrollPosition);
|
adapter.DrawPage(this->GetContent(), target, &this->scrollPosition);
|
||||||
this->Repaint();
|
this->Repaint();
|
||||||
@ -102,12 +104,20 @@ void ListWindow::PageDown() {
|
|||||||
ScrollPos spos = this->GetScrollPosition();
|
ScrollPos spos = this->GetScrollPosition();
|
||||||
|
|
||||||
size_t lastVisible = spos.firstVisibleEntryIndex + spos.visibleEntryCount - 1;
|
size_t lastVisible = spos.firstVisibleEntryIndex + spos.visibleEntryCount - 1;
|
||||||
this->selectedIndex = min(adapter.GetEntryCount() - 1, lastVisible + 1);
|
this->SetSelectedIndex(min(adapter.GetEntryCount() - 1, lastVisible + 1));
|
||||||
|
|
||||||
adapter.DrawPage(this->GetContent(), lastVisible, &this->scrollPosition);
|
adapter.DrawPage(this->GetContent(), lastVisible, &this->scrollPosition);
|
||||||
this->Repaint();
|
this->Repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ListWindow::SetSelectedIndex(size_t index) {
|
||||||
|
if (this->selectedIndex != index) {
|
||||||
|
size_t prev = this->selectedIndex;
|
||||||
|
this->selectedIndex = index;
|
||||||
|
this->SelectionChanged(this, index, prev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t ListWindow::GetSelectedIndex() {
|
size_t ListWindow::GetSelectedIndex() {
|
||||||
return this->selectedIndex;
|
return this->selectedIndex;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,12 @@
|
|||||||
#include "IScrollable.h"
|
#include "IScrollable.h"
|
||||||
#include "IScrollAdapter.h"
|
#include "IScrollAdapter.h"
|
||||||
#include "ScrollableWindow.h"
|
#include "ScrollableWindow.h"
|
||||||
|
#include <sigslot/sigslot.h>
|
||||||
|
|
||||||
class ListWindow : public ScrollableWindow {
|
class ListWindow : public ScrollableWindow {
|
||||||
public:
|
public:
|
||||||
|
sigslot::signal3<ListWindow*, size_t, size_t> SelectionChanged;
|
||||||
|
|
||||||
ListWindow(IWindow *parent = NULL);
|
ListWindow(IWindow *parent = NULL);
|
||||||
virtual ~ListWindow();
|
virtual ~ListWindow();
|
||||||
|
|
||||||
@ -20,6 +23,7 @@ class ListWindow : public ScrollableWindow {
|
|||||||
virtual size_t GetSelectedIndex();
|
virtual size_t GetSelectedIndex();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void SetSelectedIndex(size_t index);
|
||||||
virtual void OnAdapterChanged();
|
virtual void OnAdapterChanged();
|
||||||
virtual IScrollAdapter::ScrollPosition& GetScrollPosition();
|
virtual IScrollAdapter::ScrollPosition& GetScrollPosition();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user