mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-29 19:20:28 +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() {
|
||||
this->selectedIndex = 0;
|
||||
this->SetSelectedIndex(0);
|
||||
this->GetScrollAdapter().DrawPage(this->GetContent(), 0, &scrollPosition);
|
||||
this->Repaint();
|
||||
}
|
||||
|
||||
void ListWindow::ScrollToBottom() {
|
||||
IScrollAdapter& adapter = this->GetScrollAdapter();
|
||||
this->selectedIndex = adapter.GetEntryCount() - 1;
|
||||
this->SetSelectedIndex(max(0, adapter.GetEntryCount() - 1));
|
||||
adapter.DrawPage(this->GetContent(), selectedIndex, &scrollPosition);
|
||||
this->Repaint();
|
||||
}
|
||||
@ -48,9 +48,10 @@ void ListWindow::ScrollUp(int delta) {
|
||||
drawIndex = newIndex - 1;
|
||||
}
|
||||
|
||||
selectedIndex = newIndex;
|
||||
|
||||
drawIndex = max(0, drawIndex);
|
||||
|
||||
this->SetSelectedIndex(newIndex);
|
||||
|
||||
adapter.DrawPage(this->GetContent(), drawIndex, &this->scrollPosition);
|
||||
|
||||
this->Repaint();
|
||||
@ -72,7 +73,7 @@ void ListWindow::ScrollDown(int delta) {
|
||||
drawIndex = drawIndex + delta;
|
||||
}
|
||||
|
||||
selectedIndex = newIndex;
|
||||
this->SetSelectedIndex(newIndex);
|
||||
|
||||
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
|
||||
there is more to see. */
|
||||
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);
|
||||
this->Repaint();
|
||||
@ -102,12 +104,20 @@ void ListWindow::PageDown() {
|
||||
ScrollPos spos = this->GetScrollPosition();
|
||||
|
||||
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);
|
||||
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() {
|
||||
return this->selectedIndex;
|
||||
}
|
||||
|
@ -3,9 +3,12 @@
|
||||
#include "IScrollable.h"
|
||||
#include "IScrollAdapter.h"
|
||||
#include "ScrollableWindow.h"
|
||||
#include <sigslot/sigslot.h>
|
||||
|
||||
class ListWindow : public ScrollableWindow {
|
||||
public:
|
||||
sigslot::signal3<ListWindow*, size_t, size_t> SelectionChanged;
|
||||
|
||||
ListWindow(IWindow *parent = NULL);
|
||||
virtual ~ListWindow();
|
||||
|
||||
@ -20,6 +23,7 @@ class ListWindow : public ScrollableWindow {
|
||||
virtual size_t GetSelectedIndex();
|
||||
|
||||
protected:
|
||||
virtual void SetSelectedIndex(size_t index);
|
||||
virtual void OnAdapterChanged();
|
||||
virtual IScrollAdapter::ScrollPosition& GetScrollPosition();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user