Added "SELECT ALL" and "SELECT NONE" buttons to OptionListComponent.

This commit is contained in:
Aloshi 2014-05-28 20:59:11 -05:00
parent 6d7cb52fd8
commit 09312a5b2d

View file

@ -43,6 +43,12 @@ private:
auto font = Font::get(FONT_SIZE_MEDIUM); auto font = Font::get(FONT_SIZE_MEDIUM);
ComponentListRow row; ComponentListRow row;
static const char* CHECKED_PATH = ":/checkbox_checked.svg";
static const char* UNCHECKED_PATH = ":/checkbox_unchecked.svg";
// for select all/none
std::vector<ImageComponent*> checkboxes;
for(auto it = mParent->mEntries.begin(); it != mParent->mEntries.end(); it++) for(auto it = mParent->mEntries.begin(); it != mParent->mEntries.end(); it++)
{ {
row.elements.clear(); row.elements.clear();
@ -54,7 +60,7 @@ private:
{ {
// add checkbox // add checkbox
auto checkbox = std::make_shared<ImageComponent>(mWindow); auto checkbox = std::make_shared<ImageComponent>(mWindow);
checkbox->setImage(it->selected ? ":/checkbox_checked.svg" : ":/checkbox_unchecked.svg"); checkbox->setImage(it->selected ? CHECKED_PATH : UNCHECKED_PATH);
checkbox->setResize(0, font->getLetterHeight()); checkbox->setResize(0, font->getLetterHeight());
row.addElement(checkbox, false); row.addElement(checkbox, false);
@ -63,9 +69,12 @@ private:
row.makeAcceptInputHandler([this, &e, checkbox] row.makeAcceptInputHandler([this, &e, checkbox]
{ {
e.selected = !e.selected; e.selected = !e.selected;
checkbox->setImage(e.selected ? ":/checkbox_checked.svg" : ":/checkbox_unchecked.svg"); checkbox->setImage(e.selected ? CHECKED_PATH : UNCHECKED_PATH);
mParent->onSelectedChanged(); mParent->onSelectedChanged();
}); });
// for select all/none
checkboxes.push_back(checkbox.get());
}else{ }else{
// input handler for non-multiselect // input handler for non-multiselect
// update selected value and close // update selected value and close
@ -84,6 +93,27 @@ private:
mMenu.addButton("BACK", "accept", [this] { delete this; }); mMenu.addButton("BACK", "accept", [this] { delete this; });
if(mParent->mMultiSelect)
{
mMenu.addButton("SELECT ALL", "select all", [this, checkboxes] {
for(unsigned int i = 0; i < mParent->mEntries.size(); i++)
{
mParent->mEntries.at(i).selected = true;
checkboxes.at(i)->setImage(CHECKED_PATH);
}
mParent->onSelectedChanged();
});
mMenu.addButton("SELECT NONE", "select none", [this, checkboxes] {
for(unsigned int i = 0; i < mParent->mEntries.size(); i++)
{
mParent->mEntries.at(i).selected = false;
checkboxes.at(i)->setImage(UNCHECKED_PATH);
}
mParent->onSelectedChanged();
});
}
mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f); mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f);
addChild(&mMenu); addChild(&mMenu);
} }