mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 04:52:32 +00:00
Added new NO_SELECTION constant to ListWindow, and use it to help set and reset default state.
This commit is contained in:
parent
2d65ab480a
commit
e8b9c873db
@ -40,10 +40,9 @@
|
||||
using namespace musik::core;
|
||||
|
||||
MetadataValue::MetadataValue(const DBID newId, const char *value)
|
||||
: id(newId)
|
||||
{
|
||||
if(value) {
|
||||
this->value = value;
|
||||
: id(newId) {
|
||||
if (value) {
|
||||
this->value = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ void CategoryListView::Requery() {
|
||||
|
||||
DBID CategoryListView::GetSelectedId() {
|
||||
size_t index = this->GetSelectedIndex();
|
||||
if (this->metadata && index < this->metadata->size()) {
|
||||
if (index != NO_SELECTION && this->metadata && index < this->metadata->size()) {
|
||||
return this->metadata->at(index)->id;
|
||||
}
|
||||
return -1;
|
||||
|
@ -3,9 +3,11 @@
|
||||
|
||||
typedef IScrollAdapter::ScrollPosition ScrollPos;
|
||||
|
||||
size_t ListWindow::NO_SELECTION = (size_t) -1;
|
||||
|
||||
ListWindow::ListWindow(IWindow *parent)
|
||||
: ScrollableWindow(parent) {
|
||||
this->selectedIndex = 0;
|
||||
this->selectedIndex = (size_t) -1;
|
||||
}
|
||||
|
||||
ListWindow::~ListWindow() {
|
||||
@ -130,6 +132,18 @@ size_t ListWindow::GetSelectedIndex() {
|
||||
void ListWindow::OnAdapterChanged() {
|
||||
IScrollAdapter *adapter = &GetScrollAdapter();
|
||||
|
||||
size_t count = adapter->GetEntryCount();
|
||||
|
||||
/* update initial state... */
|
||||
if (selectedIndex == NO_SELECTION) {
|
||||
if (adapter->GetEntryCount()) {
|
||||
this->SetSelectedIndex(0);
|
||||
}
|
||||
}
|
||||
else if (count == 0) {
|
||||
this->SetSelectedIndex(NO_SELECTION);
|
||||
}
|
||||
|
||||
GetScrollAdapter().DrawPage(
|
||||
this->GetContent(),
|
||||
this->scrollPosition.firstVisibleEntryIndex,
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
class ListWindow : public ScrollableWindow {
|
||||
public:
|
||||
static size_t NO_SELECTION;
|
||||
|
||||
sigslot::signal3<ListWindow*, size_t, size_t> SelectionChanged;
|
||||
|
||||
ListWindow(IWindow *parent = NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user