feat(color): single press to trigger model select menu (#2533)

In a similar way as the file preview, using the ENTER key will trigger the menu, while touching a preview unselected model will just select it in the list. A second tap will then trigger the menu.
This commit is contained in:
Raphael Coeffic
2022-10-13 13:08:21 +10:00
committed by GitHub
parent eb2e693eae
commit 9bfb36a587
+10 -2
View File
@@ -241,6 +241,7 @@ class ModelButton : public Button
ModelButton(FormGroup *parent, const rect_t &rect, ModelCell *modelCell) : ModelButton(FormGroup *parent, const rect_t &rect, ModelCell *modelCell) :
Button(parent, rect), modelCell(modelCell) Button(parent, rect), modelCell(modelCell)
{ {
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE);
setWidth(MODEL_SELECT_CELL_WIDTH); setWidth(MODEL_SELECT_CELL_WIDTH);
setHeight(MODEL_SELECT_CELL_HEIGHT); setHeight(MODEL_SELECT_CELL_HEIGHT);
} }
@@ -323,6 +324,14 @@ class ModelButton : public Button
bool loaded = false; bool loaded = false;
ModelCell *modelCell; ModelCell *modelCell;
BitmapBuffer *buffer = nullptr; BitmapBuffer *buffer = nullptr;
void onClicked() override {
if (!lv_obj_has_state(lvobj, LV_STATE_FOCUSED)) {
lv_group_focus_obj(lvobj);
} else {
Button::onClicked();
}
}
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -470,10 +479,9 @@ void ModelsPageBody::update(int selected)
for (auto &model : models) { for (auto &model : models) {
auto button = new ModelButton(this, rect_t{}, model); auto button = new ModelButton(this, rect_t{}, model);
button->setPressHandler([=]() -> uint8_t { return 1; });
// Long Press Handler for Models // Long Press Handler for Models
button->setLongPressHandler([=]() -> uint8_t { button->setPressHandler([=]() -> uint8_t {
Menu *menu = new Menu(this); Menu *menu = new Menu(this);
menu->setTitle(model->modelName); menu->setTitle(model->modelName);
if (model != modelslist.getCurrentModel()) { if (model != modelslist.getCurrentModel()) {