[color] set focus on current model or close to the current operation

Resolves #345
This commit is contained in:
Raphael Coeffic
2021-06-28 09:00:12 +02:00
committed by Raphael Coeffic
parent 32aad89cf3
commit 79eee634fd
3 changed files with 50 additions and 4 deletions
+18 -4
View File
@@ -210,14 +210,21 @@ class ModelCategoryPageBody : public FormWindow
update();
}
void update(int selected = 0)
void update(int selected = -1)
{
clear();
if (selected < 0) {
auto model = modelslist.getCurrentModel();
selected = category->getModelIndex(model);
if (selected < 0) selected = 0;
}
int index = 0;
coord_t y = MODEL_CELL_PADDING;
coord_t x = MODEL_CELL_PADDING;
ModelButton* selectButton = nullptr;
for (auto &model : *category) {
auto button = new ModelButton(
this, {x, y, MODEL_SELECT_CELL_WIDTH, MODEL_SELECT_CELL_HEIGHT},
@@ -237,7 +244,7 @@ class ModelCategoryPageBody : public FormWindow
storageCheck(true);
modelslist.setCurrentModel(model);
update(); // modelslist.getModelIndex(modelCell));
update();
});
}
menu->addLine(STR_CREATE_MODEL, getCreateModelAction());
@@ -264,7 +271,7 @@ class ModelCategoryPageBody : public FormWindow
.c_str(),
[=] {
modelslist.removeModel(category, model);
update(index > 0 ? index - 1 : 0);
update(index < category->size() - 1 ? index : index - 1);
});
});
}
@@ -275,7 +282,7 @@ class ModelCategoryPageBody : public FormWindow
});
if (selected == index) {
button->setFocus(SET_FOCUS_DEFAULT);
selectButton = button;
}
index++;
@@ -299,6 +306,8 @@ class ModelCategoryPageBody : public FormWindow
if (category->empty()) {
setFocus();
} else if (selectButton) {
selectButton->setFocus();
}
}
@@ -368,4 +377,9 @@ ModelSelectMenu::ModelSelectMenu():
for (auto category: modelslist.getCategories()) {
addTab(new ModelCategoryPage(category));
}
int idx = modelslist.getCurrentCategoryIdx();
if (idx >= 0) {
setCurrentTab(idx);
}
}