[color] set focus on current model or close to the current operation
Resolves #345
This commit is contained in:
committed by
Raphael Coeffic
parent
32aad89cf3
commit
79eee634fd
@@ -210,14 +210,21 @@ class ModelCategoryPageBody : public FormWindow
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(int selected = 0)
|
void update(int selected = -1)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
|
if (selected < 0) {
|
||||||
|
auto model = modelslist.getCurrentModel();
|
||||||
|
selected = category->getModelIndex(model);
|
||||||
|
if (selected < 0) selected = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
coord_t y = MODEL_CELL_PADDING;
|
coord_t y = MODEL_CELL_PADDING;
|
||||||
coord_t x = MODEL_CELL_PADDING;
|
coord_t x = MODEL_CELL_PADDING;
|
||||||
|
|
||||||
|
ModelButton* selectButton = nullptr;
|
||||||
for (auto &model : *category) {
|
for (auto &model : *category) {
|
||||||
auto button = new ModelButton(
|
auto button = new ModelButton(
|
||||||
this, {x, y, MODEL_SELECT_CELL_WIDTH, MODEL_SELECT_CELL_HEIGHT},
|
this, {x, y, MODEL_SELECT_CELL_WIDTH, MODEL_SELECT_CELL_HEIGHT},
|
||||||
@@ -237,7 +244,7 @@ class ModelCategoryPageBody : public FormWindow
|
|||||||
storageCheck(true);
|
storageCheck(true);
|
||||||
|
|
||||||
modelslist.setCurrentModel(model);
|
modelslist.setCurrentModel(model);
|
||||||
update(); // modelslist.getModelIndex(modelCell));
|
update();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
menu->addLine(STR_CREATE_MODEL, getCreateModelAction());
|
menu->addLine(STR_CREATE_MODEL, getCreateModelAction());
|
||||||
@@ -264,7 +271,7 @@ class ModelCategoryPageBody : public FormWindow
|
|||||||
.c_str(),
|
.c_str(),
|
||||||
[=] {
|
[=] {
|
||||||
modelslist.removeModel(category, model);
|
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) {
|
if (selected == index) {
|
||||||
button->setFocus(SET_FOCUS_DEFAULT);
|
selectButton = button;
|
||||||
}
|
}
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
@@ -299,6 +306,8 @@ class ModelCategoryPageBody : public FormWindow
|
|||||||
|
|
||||||
if (category->empty()) {
|
if (category->empty()) {
|
||||||
setFocus();
|
setFocus();
|
||||||
|
} else if (selectButton) {
|
||||||
|
selectButton->setFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,4 +377,9 @@ ModelSelectMenu::ModelSelectMenu():
|
|||||||
for (auto category: modelslist.getCategories()) {
|
for (auto category: modelslist.getCategories()) {
|
||||||
addTab(new ModelCategoryPage(category));
|
addTab(new ModelCategoryPage(category));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int idx = modelslist.getCurrentCategoryIdx();
|
||||||
|
if (idx >= 0) {
|
||||||
|
setCurrentTab(idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,6 +240,19 @@ void ModelsCategory::moveModel(ModelCell * model, int8_t step)
|
|||||||
erase(current);
|
erase(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ModelsCategory::getModelIndex(const ModelCell* model)
|
||||||
|
{
|
||||||
|
int idx = 0;
|
||||||
|
for (auto m : *this) {
|
||||||
|
if (model == m)
|
||||||
|
return idx;
|
||||||
|
|
||||||
|
++idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void ModelsCategory::save(FIL * file)
|
void ModelsCategory::save(FIL * file)
|
||||||
{
|
{
|
||||||
#if !defined(SDCARD_YAML)
|
#if !defined(SDCARD_YAML)
|
||||||
@@ -389,6 +402,22 @@ void ModelsList::setCurrentCategory(ModelsCategory * cat)
|
|||||||
currentCategory = cat;
|
currentCategory = cat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ModelsList::getCurrentCategoryIdx() const
|
||||||
|
{
|
||||||
|
if (!currentCategory)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int idx = 0;
|
||||||
|
for (auto cat : categories) {
|
||||||
|
if (currentCategory == cat)
|
||||||
|
return idx;
|
||||||
|
|
||||||
|
++idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void ModelsList::setCurrentModel(ModelCell * cell)
|
void ModelsList::setCurrentModel(ModelCell * cell)
|
||||||
{
|
{
|
||||||
currentModel = cell;
|
currentModel = cell;
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ public:
|
|||||||
void removeModel(ModelCell * model);
|
void removeModel(ModelCell * model);
|
||||||
void moveModel(ModelCell * model, int8_t step);
|
void moveModel(ModelCell * model, int8_t step);
|
||||||
|
|
||||||
|
int getModelIndex(const ModelCell* model);
|
||||||
|
|
||||||
void save(FIL * file);
|
void save(FIL * file);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -118,6 +120,7 @@ public:
|
|||||||
{
|
{
|
||||||
return currentCategory;
|
return currentCategory;
|
||||||
}
|
}
|
||||||
|
int getCurrentCategoryIdx() const;
|
||||||
|
|
||||||
void setCurrentModel(ModelCell * cell);
|
void setCurrentModel(ModelCell * cell);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user