feat(color): Improve navigation with SYS and MDL keys (#4111)

This commit is contained in:
philmoz
2023-10-16 16:17:30 +10:00
committed by GitHub
parent c0a6503960
commit 7bf24f668a
10 changed files with 318 additions and 259 deletions
+29 -26
View File
@@ -21,8 +21,7 @@
#include "menu_model.h" #include "menu_model.h"
#include "translations.h" #include "menu_radio.h"
#include "view_channels.h"
#include "model_curves.h" #include "model_curves.h"
#include "model_flightmodes.h" #include "model_flightmodes.h"
#include "model_gvars.h" #include "model_gvars.h"
@@ -32,16 +31,15 @@
#include "model_mixer_scripts.h" #include "model_mixer_scripts.h"
#include "model_mixes.h" #include "model_mixes.h"
#include "model_outputs.h" #include "model_outputs.h"
#include "model_select.h"
#include "model_setup.h" #include "model_setup.h"
#include "model_telemetry.h" #include "model_telemetry.h"
#include "opentx.h" #include "opentx.h"
#include "special_functions.h" #include "special_functions.h"
#include "translations.h"
#include "view_channels.h"
ModelMenu::ModelMenu(): ModelMenu::ModelMenu() : TabsGroup(ICON_MODEL) { build(); }
TabsGroup(ICON_MODEL)
{
build();
}
void ModelMenu::build() void ModelMenu::build()
{ {
@@ -56,32 +54,24 @@ void ModelMenu::build()
addTab(new ModelSetupPage()); addTab(new ModelSetupPage());
#if defined(HELI) #if defined(HELI)
if (_modelHeliEnabled) if (_modelHeliEnabled) addTab(new ModelHeliPage());
addTab(new ModelHeliPage());
#endif #endif
#if defined(FLIGHT_MODES) #if defined(FLIGHT_MODES)
if (_modelFMEnabled) if (_modelFMEnabled) addTab(new ModelFlightModesPage());
addTab(new ModelFlightModesPage());
#endif #endif
addTab(new ModelInputsPage()); addTab(new ModelInputsPage());
addTab(new ModelMixesPage()); addTab(new ModelMixesPage());
addTab(new ModelOutputsPage()); addTab(new ModelOutputsPage());
if (_modelCurvesEnabled) if (_modelCurvesEnabled) addTab(new ModelCurvesPage());
addTab(new ModelCurvesPage());
#if defined(GVARS) #if defined(GVARS)
if (_modelGVEnabled) if (_modelGVEnabled) addTab(new ModelGVarsPage());
addTab(new ModelGVarsPage());
#endif #endif
if (_modelLSEnabled) if (_modelLSEnabled) addTab(new ModelLogicalSwitchesPage());
addTab(new ModelLogicalSwitchesPage()); if (_modelSFEnabled) addTab(new SpecialFunctionsPage(g_model.customFn));
if (_modelSFEnabled)
addTab(new SpecialFunctionsPage(g_model.customFn));
#if defined(LUA_MODEL_SCRIPTS) #if defined(LUA_MODEL_SCRIPTS)
if (_modelCustomScriptsEnabled) if (_modelCustomScriptsEnabled) addTab(new ModelMixerScriptsPage());
addTab(new ModelMixerScriptsPage());
#endif #endif
if (_modelTelemetryEnabled) if (_modelTelemetryEnabled) addTab(new ModelTelemetryPage());
addTab(new ModelTelemetryPage());
#if defined(PCBNV14) || defined(PCBPL18) #if defined(PCBNV14) || defined(PCBPL18)
addGoToMonitorsButton(); addGoToMonitorsButton();
@@ -109,9 +99,21 @@ void ModelMenu::checkEvents()
void ModelMenu::onEvent(event_t event) void ModelMenu::onEvent(event_t event)
{ {
#if defined(HARDWARE_KEYS) #if defined(HARDWARE_KEYS)
if (event == EVT_KEY_FIRST(KEY_MODEL)) { if (event == EVT_KEY_BREAK(KEY_MODEL)) {
killEvents(event); killEvents(event);
new ChannelsViewMenu(); new ChannelsViewMenu(this);
} else if (event == EVT_KEY_LONG(KEY_MODEL)) {
killEvents(KEY_MODEL);
onCancel();
new ModelLabelsWindow();
} else if (event == EVT_KEY_BREAK(KEY_SYS)) {
onCancel();
new RadioMenu();
} else if (event == EVT_KEY_LONG(KEY_SYS)) {
onCancel();
killEvents(KEY_SYS);
// Radio setup
(new RadioMenu())->setCurrentTab(2);
} else { } else {
TabsGroup::onEvent(event); TabsGroup::onEvent(event);
} }
@@ -122,7 +124,8 @@ void ModelMenu::onEvent(event_t event)
void ModelMenu::addGoToMonitorsButton() void ModelMenu::addGoToMonitorsButton()
{ {
new TextButton( new TextButton(
&header, {LCD_W / 2 + 6, MENU_TITLE_TOP + 1, LCD_W / 2 - 8, MENU_TITLE_HEIGHT - 2}, &header,
{LCD_W / 2 + 6, MENU_TITLE_TOP + 1, LCD_W / 2 - 8, MENU_TITLE_HEIGHT - 2},
STR_OPEN_CHANNEL_MONITORS, [=]() { STR_OPEN_CHANNEL_MONITORS, [=]() {
pushEvent(EVT_KEY_FIRST(KEY_MODEL)); pushEvent(EVT_KEY_FIRST(KEY_MODEL));
return 0; return 0;
+2 -6
View File
@@ -19,8 +19,7 @@
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#ifndef _MENU_MODEL_H_ #pragma once
#define _MENU_MODEL_H_
#include "tabsgroup.h" #include "tabsgroup.h"
@@ -29,8 +28,6 @@ class ModelMenu : public TabsGroup
public: public:
ModelMenu(); ModelMenu();
void onEvent(event_t event) override;
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override { return "ModelMenu"; } std::string getName() const override { return "ModelMenu"; }
#endif #endif
@@ -50,6 +47,5 @@ class ModelMenu : public TabsGroup
void build(); void build();
void checkEvents() override; void checkEvents() override;
void onEvent(event_t event) override;
}; };
#endif // _MENU_MODEL_H_
+32 -23
View File
@@ -19,29 +19,25 @@
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#include "opentx.h"
#include "menu_radio.h" #include "menu_radio.h"
#include "radio_setup.h"
#include "radio_sdmanager.h" #include "menu_model.h"
#include "radio_tools.h" #include "model_select.h"
#include "special_functions.h" #include "myeeprom.h"
#include "opentx.h"
#include "radio_calibration.h" #include "radio_calibration.h"
#include "radio_hardware.h"
#include "radio_sdmanager.h"
#include "radio_setup.h"
#include "radio_theme.h"
#include "radio_tools.h"
#include "radio_trainer.h" #include "radio_trainer.h"
#include "radio_version.h" #include "radio_version.h"
#include "radio_hardware.h" #include "special_functions.h"
#include "radio_theme.h"
#include "myeeprom.h"
RadioMenu::RadioMenu(): RadioMenu::RadioMenu() : TabsGroup(ICON_RADIO) { build(); }
TabsGroup(ICON_RADIO)
{
build();
}
RadioMenu::~RadioMenu() RadioMenu::~RadioMenu() { storageCheck(true); }
{
storageCheck(true);
}
void RadioMenu::build() void RadioMenu::build()
{ {
@@ -52,12 +48,9 @@ void RadioMenu::build()
addTab(new RadioToolsPage()); addTab(new RadioToolsPage());
addTab(new RadioSdManagerPage()); addTab(new RadioSdManagerPage());
addTab(new RadioSetupPage()); addTab(new RadioSetupPage());
if (_radioThemesEnabled) if (_radioThemesEnabled) addTab(new ThemeSetupPage());
addTab(new ThemeSetupPage()); if (_radioGFEnabled) addTab(new SpecialFunctionsPage(g_eeGeneral.customFn));
if (_radioGFEnabled) if (_radioTrainerEnabled) addTab(new RadioTrainerPage());
addTab(new SpecialFunctionsPage(g_eeGeneral.customFn));
if (_radioTrainerEnabled)
addTab(new RadioTrainerPage());
addTab(new RadioHardwarePage()); addTab(new RadioHardwarePage());
addTab(new RadioVersionPage()); addTab(new RadioVersionPage());
} }
@@ -76,3 +69,19 @@ void RadioMenu::checkEvents()
setCurrentTab(2); setCurrentTab(2);
} }
} }
void RadioMenu::onEvent(event_t event)
{
#if defined(HARDWARE_KEYS)
if (event == EVT_KEY_BREAK(KEY_MODEL)) {
onCancel();
new ModelMenu();
} else if (event == EVT_KEY_LONG(KEY_MODEL)) {
onCancel();
killEvents(KEY_MODEL);
new ModelLabelsWindow();
} else {
TabsGroup::onEvent(event);
}
#endif
}
+4 -5
View File
@@ -19,12 +19,12 @@
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#ifndef _MENU_RADIO_H_ #pragma once
#define _MENU_RADIO_H_
#include "tabsgroup.h" #include "tabsgroup.h"
class RadioMenu: public TabsGroup { class RadioMenu : public TabsGroup
{
public: public:
RadioMenu(); RadioMenu();
~RadioMenu(); ~RadioMenu();
@@ -36,6 +36,5 @@ class RadioMenu: public TabsGroup {
void build(); void build();
void checkEvents() override; void checkEvents() override;
void onEvent(event_t event) override;
}; };
#endif // _MENU_RADIO_H_
+67 -53
View File
@@ -27,6 +27,8 @@
#include "libopenui.h" #include "libopenui.h"
#include "listbox.h" #include "listbox.h"
#include "menu_model.h"
#include "menu_radio.h"
#include "model_templates.h" #include "model_templates.h"
#include "opentx.h" #include "opentx.h"
#include "standalone_lua.h" #include "standalone_lua.h"
@@ -64,8 +66,7 @@ constexpr int MODEL_CELLS_PER_LINE = 2;
constexpr int LABELS_WIDTH = 132; constexpr int LABELS_WIDTH = 132;
constexpr int LAY_MARGIN = 5; constexpr int LAY_MARGIN = 5;
constexpr coord_t MODEL_SELECT_CELL_WIDTH = constexpr coord_t MODEL_SELECT_CELL_WIDTH =
(LCD_W - LABELS_WIDTH - (LCD_W - LABELS_WIDTH - (MODEL_CELLS_PER_LINE + 1) * MODEL_CELL_PADDING) /
(MODEL_CELLS_PER_LINE + 1) * MODEL_CELL_PADDING) /
MODEL_CELLS_PER_LINE; MODEL_CELLS_PER_LINE;
#else // Portrait #else // Portrait
constexpr int LAY_MARGIN = 8; constexpr int LAY_MARGIN = 8;
@@ -85,7 +86,8 @@ class ToolbarButton : public Button
lv_obj_set_style_border_width(lvobj, lv_dpx(2), 0); lv_obj_set_style_border_width(lvobj, lv_dpx(2), 0);
lv_obj_set_style_border_opa(lvobj, LV_OPA_TRANSP, 0); lv_obj_set_style_border_opa(lvobj, LV_OPA_TRANSP, 0);
lv_obj_set_style_border_color(lvobj, makeLvColor(COLOR_THEME_FOCUS), LV_STATE_FOCUSED); lv_obj_set_style_border_color(lvobj, makeLvColor(COLOR_THEME_FOCUS),
LV_STATE_FOCUSED);
lv_obj_set_style_border_opa(lvobj, LV_OPA_100, LV_STATE_FOCUSED); lv_obj_set_style_border_opa(lvobj, LV_OPA_100, LV_STATE_FOCUSED);
} }
@@ -187,8 +189,7 @@ class ButtonHolder : public FormWindow
_pressHandler = std::move(pressHandler); _pressHandler = std::move(pressHandler);
} }
inline void setNewLabelHandler( inline void setNewLabelHandler(std::function<void()> newLabelHandler)
std::function<void()> newLabelHandler)
{ {
_newLabelHandler = std::move(newLabelHandler); _newLabelHandler = std::move(newLabelHandler);
} }
@@ -240,7 +241,8 @@ class ButtonHolder : public FormWindow
class ModelButton : public Button class ModelButton : public Button
{ {
public: public:
ModelButton(FormWindow *parent, const rect_t &rect, ModelCell *modelCell, std::function<void()> setSelected) : ModelButton(FormWindow *parent, const rect_t &rect, ModelCell *modelCell,
std::function<void()> setSelected) :
Button(parent, rect), modelCell(modelCell) Button(parent, rect), modelCell(modelCell)
{ {
m_setSelected = std::move(setSelected); m_setSelected = std::move(setSelected);
@@ -319,7 +321,8 @@ class ModelButton : public Button
const char *modelFilename() { return modelCell->modelFilename; } const char *modelFilename() { return modelCell->modelFilename; }
ModelCell *getModelCell() const { return modelCell; } ModelCell *getModelCell() const { return modelCell; }
void setFocused() { void setFocused()
{
if (!lv_obj_has_state(lvobj, LV_STATE_FOCUSED)) { if (!lv_obj_has_state(lvobj, LV_STATE_FOCUSED)) {
lv_group_focus_obj(lvobj); lv_group_focus_obj(lvobj);
} }
@@ -331,7 +334,8 @@ class ModelButton : public Button
BitmapBuffer *buffer = nullptr; BitmapBuffer *buffer = nullptr;
std::function<void()> m_setSelected = nullptr; std::function<void()> m_setSelected = nullptr;
void onClicked() override { void onClicked() override
{
setFocused(); setFocused();
Button::onClicked(); Button::onClicked();
} }
@@ -382,7 +386,8 @@ void ModelsPageBody::selectModel(ModelCell *model)
while (!TELEMETRY_STREAMING()) { while (!TELEMETRY_STREAMING()) {
if (getTicks() - startTime > TELEMETRY_CHECK_DELAY10ms) break; if (getTicks() - startTime > TELEMETRY_CHECK_DELAY10ms) break;
} }
return !TELEMETRY_STREAMING() || g_eeGeneral.disableRssiPoweroffAlarm; return !TELEMETRY_STREAMING() ||
g_eeGeneral.disableRssiPoweroffAlarm;
})) { })) {
return; // stop if connected but not confirmed return; // stop if connected but not confirmed
} }
@@ -512,7 +517,8 @@ void ModelsPageBody::openMenu()
{ {
Menu *menu = new Menu(this); Menu *menu = new Menu(this);
menu->setTitle(focusedModel->modelName); menu->setTitle(focusedModel->modelName);
if (g_eeGeneral.modelQuickSelect || focusedModel != modelslist.getCurrentModel()) { if (g_eeGeneral.modelQuickSelect ||
focusedModel != modelslist.getCurrentModel()) {
menu->addLine(STR_SELECT_MODEL, [=]() { selectModel(focusedModel); }); menu->addLine(STR_SELECT_MODEL, [=]() { selectModel(focusedModel); });
} }
menu->addLine(STR_DUPLICATE_MODEL, [=]() { duplicateModel(focusedModel); }); menu->addLine(STR_DUPLICATE_MODEL, [=]() { duplicateModel(focusedModel); });
@@ -543,16 +549,12 @@ void ModelsPageBody::update()
ModelButton *focusedButton = nullptr; ModelButton *focusedButton = nullptr;
for (auto &model : models) { for (auto &model : models) {
auto button = new ModelButton(this, rect_t{}, model, [=]() { auto button =
focusedModel = model; new ModelButton(this, rect_t{}, model, [=]() { focusedModel = model; });
});
if (!firstButton) if (!firstButton) firstButton = button;
firstButton = button; if (model == modelslist.getCurrentModel()) focusedButton = button;
if (model == modelslist.getCurrentModel()) if (model == focusedModel && !focusedButton) focusedButton = button;
focusedButton = button;
if (model == focusedModel && !focusedButton)
focusedButton = button;
// Press Handler for Models // Press Handler for Models
button->setPressHandler([=]() -> uint8_t { button->setPressHandler([=]() -> uint8_t {
@@ -576,8 +578,7 @@ void ModelsPageBody::update()
}); });
} }
if (!focusedButton) if (!focusedButton) focusedButton = firstButton;
focusedButton = firstButton;
if (focusedButton) { if (focusedButton) {
focusedButton->setFocused(); focusedButton->setFocused();
@@ -612,18 +613,14 @@ class LabelDialog : public Dialog
auto box_obj = box->getLvObj(); auto box_obj = box->getLvObj();
lv_obj_set_style_flex_main_place(box_obj, LV_FLEX_ALIGN_SPACE_EVENLY, 0); lv_obj_set_style_flex_main_place(box_obj, LV_FLEX_ALIGN_SPACE_EVENLY, 0);
auto btn = new TextButton( auto btn = new TextButton(box, rect_t{}, STR_SAVE, [=]() {
box, rect_t{}, STR_SAVE,
[=]() {
if (saveHandler != nullptr) saveHandler(label); if (saveHandler != nullptr) saveHandler(label);
deleteLater(); deleteLater();
return 0; return 0;
}); });
btn->setWidth(LV_DPI_DEF); btn->setWidth(LV_DPI_DEF);
btn = new TextButton( btn = new TextButton(box, rect_t{}, STR_CANCEL, [=]() {
box, rect_t{}, STR_CANCEL,
[=]() {
deleteLater(); deleteLater();
return 0; return 0;
}); });
@@ -670,8 +667,7 @@ void ModelLabelsWindow::onEvent(event_t event)
if (event == EVT_KEY_BREAK(KEY_PAGEUP) || if (event == EVT_KEY_BREAK(KEY_PAGEUP) ||
event == EVT_KEY_BREAK(KEY_PAGEDN)) { event == EVT_KEY_BREAK(KEY_PAGEDN)) {
#else #else
if (event == EVT_KEY_LONG(KEY_PAGEDN) || if (event == EVT_KEY_LONG(KEY_PAGEDN) || event == EVT_KEY_BREAK(KEY_PAGEDN)) {
event == EVT_KEY_BREAK(KEY_PAGEDN)) {
#endif #endif
std::set<uint32_t> curSel = lblselector->getSelection(); std::set<uint32_t> curSel = lblselector->getSelection();
std::set<uint32_t> sellist; std::set<uint32_t> sellist;
@@ -679,14 +675,12 @@ void ModelLabelsWindow::onEvent(event_t event)
int rowcount = lblselector->getRowCount(); int rowcount = lblselector->getRowCount();
if (event == EVT_KEY_BREAK(KEY_PAGEDN)) { if (event == EVT_KEY_BREAK(KEY_PAGEDN)) {
if(curSel.size()) if (curSel.size()) select = (*curSel.rbegin() + 1) % rowcount;
select = (*curSel.rbegin() + 1) % rowcount;
} else { } else {
killEvents(event); killEvents(event);
if (curSel.size()) { if (curSel.size()) {
select = (int)*curSel.begin() - 1; select = (int)*curSel.begin() - 1;
if(select < 0) if (select < 0) select += rowcount;
select += rowcount;
} else { } else {
select = rowcount - 1; select = rowcount - 1;
} }
@@ -695,6 +689,17 @@ void ModelLabelsWindow::onEvent(event_t event)
lblselector->setSelected(sellist); // Check the items lblselector->setSelected(sellist); // Check the items
lblselector->setSelected(select); // Causes the list to scroll lblselector->setSelected(select); // Causes the list to scroll
updateFilteredLabels(sellist); // Update the models updateFilteredLabels(sellist); // Update the models
} else if (event == EVT_KEY_BREAK(KEY_MODEL)) {
onCancel();
new ModelMenu();
} else if (event == EVT_KEY_BREAK(KEY_SYS)) {
onCancel();
new RadioMenu();
} else if (event == EVT_KEY_LONG(KEY_SYS)) {
onCancel();
killEvents(KEY_SYS);
// Radio setup
(new RadioMenu())->setCurrentTab(2);
} else { } else {
Page::onEvent(event); Page::onEvent(event);
} }
@@ -708,8 +713,8 @@ void ModelLabelsWindow::newModel()
storageCheck(true); storageCheck(true);
new SelectTemplateFolder([=](std::string folder, std::string name) { new SelectTemplateFolder([=](std::string folder, std::string name) {
// Create a new blank ModelCell and activate it first, createmodel() will modify // Create a new blank ModelCell and activate it first, createmodel() will
// the model in memory. // modify the model in memory.
auto newCell = modelslist.addModel("", false); auto newCell = modelslist.addModel("", false);
modelslist.setCurrentModel(newCell); modelslist.setCurrentModel(newCell);
@@ -721,9 +726,9 @@ void ModelLabelsWindow::newModel()
if (w) w->onCancel(); if (w) w->onCancel();
// Check for not 'Blank Model' // Check for not 'Blank Model'
if (name.size() > 0) if (name.size() > 0) {
{ static constexpr size_t LEN_BUFFER =
static constexpr size_t LEN_BUFFER = sizeof(TEMPLATES_PATH) + 2 * TEXT_FILENAME_MAXLEN + 1; sizeof(TEMPLATES_PATH) + 2 * TEXT_FILENAME_MAXLEN + 1;
char path[LEN_BUFFER + 1]; char path[LEN_BUFFER + 1];
snprintf(path, LEN_BUFFER, "%s/%s", TEMPLATES_PATH, folder.c_str()); snprintf(path, LEN_BUFFER, "%s/%s", TEMPLATES_PATH, folder.c_str());
@@ -784,11 +789,14 @@ void ModelLabelsWindow::buildHead(PageHeader *hdr)
} }
#if LCD_W > LCD_H #if LCD_W > LCD_H
static const lv_coord_t col_dsc[] = {LABELS_WIDTH, LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; static const lv_coord_t col_dsc[] = {LABELS_WIDTH, LV_GRID_FR(1),
static const lv_coord_t row_dsc[] = {LV_GRID_FR(1), BUTTONS_HEIGHT, LV_GRID_TEMPLATE_LAST}; LV_GRID_TEMPLATE_LAST};
static const lv_coord_t row_dsc[] = {LV_GRID_FR(1), BUTTONS_HEIGHT,
LV_GRID_TEMPLATE_LAST};
#else #else
static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
static const lv_coord_t row_dsc[] = {LV_GRID_FR(1), LABELS_HEIGHT, BUTTONS_HEIGHT, LV_GRID_TEMPLATE_LAST}; static const lv_coord_t row_dsc[] = {LV_GRID_FR(1), LABELS_HEIGHT,
BUTTONS_HEIGHT, LV_GRID_TEMPLATE_LAST};
#endif #endif
void ModelLabelsWindow::buildBody(FormWindow *window) void ModelLabelsWindow::buildBody(FormWindow *window)
@@ -817,25 +825,31 @@ void ModelLabelsWindow::buildBody(FormWindow *window)
#if LCD_W > LCD_H #if LCD_W > LCD_H
// Labels top left // Labels top left
lv_obj_set_grid_cell(lbl_obj, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_STRETCH, 0, 1); lv_obj_set_grid_cell(lbl_obj, LV_GRID_ALIGN_STRETCH, 0, 1,
LV_GRID_ALIGN_STRETCH, 0, 1);
// Buttons bottom left // Buttons bottom left
lv_obj_set_grid_cell(mdl_obj, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_STRETCH, 0, 2); lv_obj_set_grid_cell(mdl_obj, LV_GRID_ALIGN_STRETCH, 1, 1,
LV_GRID_ALIGN_STRETCH, 0, 2);
lv_obj_set_width(mdl_obj, lv_pct(100)); lv_obj_set_width(mdl_obj, lv_pct(100));
window->padRight(0); window->padRight(0);
// Models right // Models right
lv_obj_set_grid_cell(buth_obj, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_STRETCH, 1, 1); lv_obj_set_grid_cell(buth_obj, LV_GRID_ALIGN_STRETCH, 0, 1,
LV_GRID_ALIGN_STRETCH, 1, 1);
#else #else
// Models top // Models top
lv_obj_set_grid_cell(mdl_obj, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_STRETCH, 0, 1); lv_obj_set_grid_cell(mdl_obj, LV_GRID_ALIGN_STRETCH, 0, 1,
LV_GRID_ALIGN_STRETCH, 0, 1);
lv_obj_set_width(mdl_obj, lv_pct(100)); lv_obj_set_width(mdl_obj, lv_pct(100));
// Labels middle // Labels middle
lv_obj_set_grid_cell(lbl_obj, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_STRETCH, 1, 1); lv_obj_set_grid_cell(lbl_obj, LV_GRID_ALIGN_STRETCH, 0, 1,
LV_GRID_ALIGN_STRETCH, 1, 1);
// Buttons bottom // Buttons bottom
lv_obj_set_grid_cell(buth_obj, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_STRETCH, 2, 1); lv_obj_set_grid_cell(buth_obj, LV_GRID_ALIGN_STRETCH, 0, 1,
LV_GRID_ALIGN_STRETCH, 2, 1);
#endif #endif
lv_obj_update_layout(mdl_obj); lv_obj_update_layout(mdl_obj);
@@ -899,10 +913,10 @@ void ModelLabelsWindow::buildBody(FormWindow *window)
new ProgressDialog(this, STR_RENAME_LABEL, [=]() {}); new ProgressDialog(this, STR_RENAME_LABEL, [=]() {});
modelslabels.renameLabel( modelslabels.renameLabel(
oldLabel, newLabel, [=](const char *name, int percentage) { oldLabel, newLabel, [=](const char *name, int percentage) {
rndialog->setTitle(std::string(STR_RENAME_LABEL) + " " + name); rndialog->setTitle(std::string(STR_RENAME_LABEL) + " " +
name);
rndialog->updateProgress(percentage); rndialog->updateProgress(percentage);
if (percentage >= 100) if (percentage >= 100) rndialog->closeDialog();
rndialog->closeDialog();
}); });
auto labels = getLabels(); auto labels = getLabels();
lblselector->setNames(labels); lblselector->setNames(labels);
@@ -919,10 +933,10 @@ void ModelLabelsWindow::buildBody(FormWindow *window)
new ProgressDialog(this, STR_DELETE_LABEL, [=]() {}); new ProgressDialog(this, STR_DELETE_LABEL, [=]() {});
modelslabels.removeLabel( modelslabels.removeLabel(
labelToDelete, [=](const char *name, int percentage) { labelToDelete, [=](const char *name, int percentage) {
deldialog->setTitle(std::string(STR_RENAME_LABEL) + " " + name); deldialog->setTitle(std::string(STR_RENAME_LABEL) + " " +
name);
deldialog->updateProgress(percentage); deldialog->updateProgress(percentage);
if (percentage >= 100) if (percentage >= 100) deldialog->closeDialog();
deldialog->closeDialog();
}); });
auto labels = getLabels(); auto labels = getLabels();
std::set<uint32_t> newset; std::set<uint32_t> newset;
+27 -37
View File
@@ -22,18 +22,18 @@
#include "tabsgroup.h" #include "tabsgroup.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "view_main.h"
#include "static.h" #include "static.h"
#include "theme.h" #include "theme.h"
#include "view_main.h"
#if defined(HARDWARE_TOUCH) #if defined(HARDWARE_TOUCH)
#include "keyboard_base.h" #include "keyboard_base.h"
#endif #endif
#include "opentx.h" // TODO for constants...
#include <algorithm> #include <algorithm>
#include "opentx.h" // TODO for constants...
TabCarouselButton::TabCarouselButton(Window* parent, const rect_t& rect, TabCarouselButton::TabCarouselButton(Window* parent, const rect_t& rect,
std::vector<PageTab*>& tabs, uint8_t index, std::vector<PageTab*>& tabs, uint8_t index,
std::function<uint8_t(void)> pressHandler, std::function<uint8_t(void)> pressHandler,
@@ -67,8 +67,7 @@ TabsGroupHeader::TabsGroupHeader(TabsGroup* parent, uint8_t icon) :
parent->deleteLater(); parent->deleteLater();
return 1; return 1;
}, },
NO_FOCUS, NO_FOCUS, 0, window_create),
0, window_create),
#endif #endif
icon(icon), icon(icon),
carousel(this, parent) carousel(this, parent)
@@ -83,7 +82,8 @@ void TabsGroupHeader::paint(BitmapBuffer* dc)
TabsCarousel::TabsCarousel(Window* parent, TabsGroup* menu) : TabsCarousel::TabsCarousel(Window* parent, TabsGroup* menu) :
Window(parent, Window(parent,
{MENU_HEADER_BUTTONS_LEFT, 0, DATETIME_SEPARATOR_X - MENU_HEADER_BUTTONS_LEFT, {MENU_HEADER_BUTTONS_LEFT, 0,
DATETIME_SEPARATOR_X - MENU_HEADER_BUTTONS_LEFT,
MENU_HEADER_HEIGHT + 10}, MENU_HEADER_HEIGHT + 10},
NO_FOCUS | TRANSPARENT), NO_FOCUS | TRANSPARENT),
menu(menu) menu(menu)
@@ -92,27 +92,26 @@ TabsCarousel::TabsCarousel(Window* parent, TabsGroup* menu) :
void TabsCarousel::update() void TabsCarousel::update()
{ {
while(buttons.size() < menu->tabs.size()) while (buttons.size() < menu->tabs.size()) {
{
int index = buttons.size(); int index = buttons.size();
rect_t btnCoords = {(int)(index * (MENU_HEADER_BUTTON_WIDTH + 1)), 0, (int)(MENU_HEADER_BUTTON_WIDTH + 3), int(MENU_TITLE_TOP + 5)}; rect_t btnCoords = {(int)(index * (MENU_HEADER_BUTTON_WIDTH + 1)), 0,
buttons.emplace_back(new TabCarouselButton(this, btnCoords, menu->tabs, index, (int)(MENU_HEADER_BUTTON_WIDTH + 3),
int(MENU_TITLE_TOP + 5)};
buttons.emplace_back(new TabCarouselButton(
this, btnCoords, menu->tabs, index,
[&, index]() { [&, index]() {
menu->setCurrentTab(index); menu->setCurrentTab(index);
setCurrentIndex(index); setCurrentIndex(index);
for(auto &b: buttons) for (auto& b : buttons) b->check(false);
b->check(false);
buttons[index]->check(true); buttons[index]->check(true);
return true; return true;
},
TRANSPARENT | NO_FOCUS));
if (index == 0) buttons[index]->check(true);
} }
, TRANSPARENT | NO_FOCUS)); while (buttons.size() > menu->tabs.size()) {
if(index == 0)
buttons[index]->check(true);
}
while(buttons.size() > menu->tabs.size())
{
buttons.back()->deleteLater(); buttons.back()->deleteLater();
buttons.pop_back(); buttons.pop_back();
} }
@@ -120,16 +119,13 @@ void TabsCarousel::update()
void TabsCarousel::setCurrentIndex(uint8_t index) void TabsCarousel::setCurrentIndex(uint8_t index)
{ {
if(buttons.size() <= index) if (buttons.size() <= index) return;
return;
buttons[currentIndex]->check(false); buttons[currentIndex]->check(false);
currentIndex = index; currentIndex = index;
buttons[currentIndex]->check(true); buttons[currentIndex]->check(true);
} }
void TabsCarousel::paint(BitmapBuffer * dc) void TabsCarousel::paint(BitmapBuffer* dc) {}
{
}
static constexpr rect_t _get_body_rect() static constexpr rect_t _get_body_rect()
{ {
@@ -153,8 +149,7 @@ TabsGroup::TabsGroup(uint8_t icon):
TabsGroup::~TabsGroup() TabsGroup::~TabsGroup()
{ {
if (activeTabsGroup == this) if (activeTabsGroup == this) activeTabsGroup = nullptr;
activeTabsGroup = nullptr;
for (auto tab : tabs) { for (auto tab : tabs) {
delete tab; delete tab;
@@ -164,13 +159,13 @@ TabsGroup::~TabsGroup()
void TabsGroup::refreshTheme() void TabsGroup::refreshTheme()
{ {
if (activeTabsGroup) if (activeTabsGroup)
lv_obj_set_style_bg_color(activeTabsGroup->getLvObj(), makeLvColor(COLOR_THEME_SECONDARY3), 0); lv_obj_set_style_bg_color(activeTabsGroup->getLvObj(),
makeLvColor(COLOR_THEME_SECONDARY3), 0);
} }
void TabsGroup::deleteLater(bool detach, bool trash) void TabsGroup::deleteLater(bool detach, bool trash)
{ {
if (_deleted) if (_deleted) return;
return;
Layer::pop(this); Layer::pop(this);
@@ -272,7 +267,8 @@ void TabsGroup::checkEvents()
void TabsGroup::onEvent(event_t event) void TabsGroup::onEvent(event_t event)
{ {
#if defined(HARDWARE_KEYS) #if defined(HARDWARE_KEYS)
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event); TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(),
event);
#if defined(KEYS_GPIO_REG_PAGEUP) || defined(USE_HATS_AS_KEYS) #if defined(KEYS_GPIO_REG_PAGEUP) || defined(USE_HATS_AS_KEYS)
if (event == EVT_KEY_FIRST(KEY_PAGEDN)) { if (event == EVT_KEY_FIRST(KEY_PAGEDN)) {
@@ -295,15 +291,9 @@ void TabsGroup::onEvent(event_t event)
#endif #endif
} }
void TabsGroup::onClicked() void TabsGroup::onClicked() { Keyboard::hide(); }
{
Keyboard::hide();
}
void TabsGroup::onCancel() void TabsGroup::onCancel() { deleteLater(); }
{
deleteLater();
}
#if defined(HARDWARE_TOUCH) #if defined(HARDWARE_TOUCH)
bool TabsGroup::onTouchEnd(coord_t x, coord_t y) bool TabsGroup::onTouchEnd(coord_t x, coord_t y)
+54 -11
View File
@@ -19,16 +19,20 @@
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#include "opentx.h"
#include "libopenui.h"
#include "view_channels.h" #include "view_channels.h"
#include "channel_bar.h" #include "channel_bar.h"
#include "libopenui.h"
#include "menu_model.h"
#include "menu_radio.h"
#include "model_select.h"
#include "opentx.h"
#include "view_logical_switches.h" #include "view_logical_switches.h"
constexpr coord_t CHANNEL_VIEW_FOOTER_HEIGHT = 16; constexpr coord_t CHANNEL_VIEW_FOOTER_HEIGHT = 16;
ChannelsViewMenu::ChannelsViewMenu(): ChannelsViewMenu::ChannelsViewMenu(ModelMenu* parent) :
TabsGroup(ICON_MONITOR) TabsGroup(ICON_MONITOR), parentMenu(parent)
{ {
addTab(new ChannelsViewPage(0)); addTab(new ChannelsViewPage(0));
addTab(new ChannelsViewPage(1)); addTab(new ChannelsViewPage(1));
@@ -37,17 +41,53 @@ ChannelsViewMenu::ChannelsViewMenu():
addTab(new LogicalSwitchesViewPage()); addTab(new LogicalSwitchesViewPage());
} }
class ChannelsViewFooter: public Window { void ChannelsViewMenu::onEvent(event_t event)
{
#if defined(HARDWARE_KEYS)
if (event == EVT_KEY_BREAK(KEY_MODEL)) {
killEvents(event);
onCancel();
if (!parentMenu) {
new ModelMenu();
}
} else if (event == EVT_KEY_LONG(KEY_MODEL)) {
killEvents(KEY_MODEL);
onCancel();
if (parentMenu) parentMenu->onCancel();
new ModelLabelsWindow();
} else if (event == EVT_KEY_BREAK(KEY_SYS)) {
onCancel();
if (parentMenu) parentMenu->onCancel();
new RadioMenu();
} else if (event == EVT_KEY_LONG(KEY_SYS)) {
killEvents(KEY_SYS);
onCancel();
if (parentMenu) parentMenu->onCancel();
// Radio setup
(new RadioMenu())->setCurrentTab(2);
} else {
TabsGroup::onEvent(event);
}
#endif
}
class ChannelsViewFooter : public Window
{
public: public:
explicit ChannelsViewFooter(Window* parent) : explicit ChannelsViewFooter(Window* parent) :
Window(parent, {0, parent->height() - MODEL_SELECT_FOOTER_HEIGHT, LCD_W, MODEL_SELECT_FOOTER_HEIGHT}, OPAQUE) Window(parent,
{0, parent->height() - MODEL_SELECT_FOOTER_HEIGHT, LCD_W,
MODEL_SELECT_FOOTER_HEIGHT},
OPAQUE)
{ {
} }
// Draw single legend // Draw single legend
coord_t drawChannelsMonitorLegend(BitmapBuffer * dc, coord_t x, const char * s, int color) coord_t drawChannelsMonitorLegend(BitmapBuffer* dc, coord_t x, const char* s,
int color)
{ {
dc->drawSolidFilledRect(x, 4, LEG_COLORBOX + 2, LEG_COLORBOX + 2, COLOR_THEME_SECONDARY3); dc->drawSolidFilledRect(x, 4, LEG_COLORBOX + 2, LEG_COLORBOX + 2,
COLOR_THEME_SECONDARY3);
dc->drawSolidFilledRect(x + 1, 5, LEG_COLORBOX, LEG_COLORBOX, color); dc->drawSolidFilledRect(x + 1, 5, LEG_COLORBOX, LEG_COLORBOX, color);
dc->drawText(x + 20, 4, s, COLOR_THEME_PRIMARY2); dc->drawText(x + 20, 4, s, COLOR_THEME_PRIMARY2);
return x + 25 + getTextWidth(s); return x + 25 + getTextWidth(s);
@@ -58,7 +98,8 @@ class ChannelsViewFooter: public Window {
// Draw legend bar // Draw legend bar
coord_t x = 10; coord_t x = 10;
dc->drawSolidFilledRect(0, 0, width(), height(), COLOR_THEME_SECONDARY1); dc->drawSolidFilledRect(0, 0, width(), height(), COLOR_THEME_SECONDARY1);
x = drawChannelsMonitorLegend(dc, MENUS_MARGIN_LEFT, STR_MONITOR_OUTPUT_DESC, COLOR_THEME_ACTIVE); x = drawChannelsMonitorLegend(dc, MENUS_MARGIN_LEFT,
STR_MONITOR_OUTPUT_DESC, COLOR_THEME_ACTIVE);
drawChannelsMonitorLegend(dc, x, STR_MONITOR_MIXER_DESC, COLOR_THEME_FOCUS); drawChannelsMonitorLegend(dc, x, STR_MONITOR_MIXER_DESC, COLOR_THEME_FOCUS);
} }
}; };
@@ -73,11 +114,13 @@ void ChannelsViewPage::build(FormWindow * window)
#if LCD_H > LCD_W #if LCD_H > LCD_W
coord_t width = window->width() - (hmargin * 2); coord_t width = window->width() - (hmargin * 2);
coord_t xPos = hmargin; coord_t xPos = hmargin;
coord_t yPos = (chan % 8) * ((window->height() - CHANNEL_VIEW_FOOTER_HEIGHT - 8) / 8); coord_t yPos =
(chan % 8) * ((window->height() - CHANNEL_VIEW_FOOTER_HEIGHT - 8) / 8);
#else #else
coord_t width = window->width() / 2 - (hmargin * 2); coord_t width = window->width() / 2 - (hmargin * 2);
coord_t xPos = (chan % 8) >= 4 ? width + (hmargin * 2) : hmargin; coord_t xPos = (chan % 8) >= 4 ? width + (hmargin * 2) : hmargin;
coord_t yPos = (chan % 4) * ((window->height() - CHANNEL_VIEW_FOOTER_HEIGHT - 4) / 4); coord_t yPos =
(chan % 4) * ((window->height() - CHANNEL_VIEW_FOOTER_HEIGHT - 4) / 4);
#endif #endif
new ComboChannelBar(window, {xPos, yPos, width, 3 * BAR_HEIGHT + 3}, chan); new ComboChannelBar(window, {xPos, yPos, width, 3 * BAR_HEIGHT + 3}, chan);
} }
+8 -1
View File
@@ -24,6 +24,8 @@
#include "opentx.h" #include "opentx.h"
#include "tabsgroup.h" #include "tabsgroup.h"
class ModelMenu;
class ChannelsViewPage: public PageTab class ChannelsViewPage: public PageTab
{ {
public: public:
@@ -40,5 +42,10 @@ class ChannelsViewPage: public PageTab
class ChannelsViewMenu: public TabsGroup { class ChannelsViewMenu: public TabsGroup {
public: public:
ChannelsViewMenu(); ChannelsViewMenu(ModelMenu* parent = nullptr);
protected:
ModelMenu* parentMenu = nullptr;
void onEvent(event_t event) override;
}; };
+2 -4
View File
@@ -267,12 +267,10 @@ void ViewMain::onEvent(event_t event)
break; break;
case EVT_KEY_LONG(KEY_SYS): case EVT_KEY_LONG(KEY_SYS):
{
killEvents(KEY_SYS); killEvents(KEY_SYS);
if (viewMainMenu) viewMainMenu->onCancel();
// Radio setup // Radio setup
auto m = new RadioMenu(); (new RadioMenu())->setCurrentTab(2);
m->setCurrentTab(2);
}
break; break;
case EVT_KEY_FIRST(KEY_TELE): case EVT_KEY_FIRST(KEY_TELE):