From a535bfea181075c0910b98658bed3422ba1ea020 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 14 Jun 2021 11:15:25 +0200 Subject: [PATCH] Fixed TOOLS according to style guidelines --- radio/src/gui/colorlcd/radio_tools.cpp | 190 ++++++++++++++++++++----- 1 file changed, 153 insertions(+), 37 deletions(-) diff --git a/radio/src/gui/colorlcd/radio_tools.cpp b/radio/src/gui/colorlcd/radio_tools.cpp index 7cfc8e619..3484f2495 100644 --- a/radio/src/gui/colorlcd/radio_tools.cpp +++ b/radio/src/gui/colorlcd/radio_tools.cpp @@ -112,7 +112,8 @@ void RadioToolsPage::rebuild(FormWindow * window) *ext = '\0'; label = getBasename(path); } - new StaticText(window, grid.getLabelSlot(), "lua", BUTTON_BACKGROUND, CENTERED); + auto txt = new StaticText(window, grid.getLabelSlot(), "lua", + BUTTON_BACKGROUND, CENTERED); std::string path_str(path); auto b = new TextButton( @@ -126,6 +127,16 @@ void RadioToolsPage::rebuild(FormWindow * window) }, OPAQUE); b->setBgColorHandler([=]() -> LcdFlags { return FIELD_BGCOLOR; }); + b->setFocusHandler([=](bool focus) { + if (focus) { + txt->setBackgroundColor(FOCUS_BGCOLOR); + txt->setTextFlags(FOCUS_COLOR | CENTERED); + } else { + txt->setBackgroundColor(FIELD_FRAME_COLOR); + txt->setTextFlags(CENTERED); + } + txt->invalidate(); + }); grid.nextLine(); } } @@ -134,61 +145,166 @@ void RadioToolsPage::rebuild(FormWindow * window) #if defined(INTERNAL_MODULE_PXX2) // PXX2 modules tools - if (isPXX2ModuleOptionAvailable(reusableBuffer.hardwareAndSettings.modules[INTERNAL_MODULE].information.modelID, MODULE_OPTION_SPECTRUM_ANALYSER)) { - new StaticText(window, grid.getLabelSlot(), "access", BUTTON_BACKGROUND, CENTERED); - new TextButton(window, grid.getFieldSlot(1), STR_SPECTRUM_ANALYSER_INT, [=]() -> uint8_t { - new RadioSpectrumAnalyser(INTERNAL_MODULE); - return 0; - }, 0); + if (isPXX2ModuleOptionAvailable( + reusableBuffer.hardwareAndSettings.modules[INTERNAL_MODULE] + .information.modelID, + MODULE_OPTION_SPECTRUM_ANALYSER)) { + auto txt = new StaticText(window, grid.getLabelSlot(), "access", BUTTON_BACKGROUND, + CENTERED); + auto b = new TextButton( + window, grid.getFieldSlot(1), STR_SPECTRUM_ANALYSER_INT, + [=]() -> uint8_t { + new RadioSpectrumAnalyser(INTERNAL_MODULE); + return 0; + }, + OPAQUE); + b->setBgColorHandler([=]() -> LcdFlags { return FIELD_BGCOLOR; }); + b->setFocusHandler([=](bool focus) { + if (focus) { + txt->setBackgroundColor(FOCUS_BGCOLOR); + txt->setTextFlags(FOCUS_COLOR | CENTERED); + } else { + txt->setBackgroundColor(FIELD_FRAME_COLOR); + txt->setTextFlags(CENTERED); + } + txt->invalidate(); + }); grid.nextLine(); } - if (isPXX2ModuleOptionAvailable(reusableBuffer.hardwareAndSettings.modules[INTERNAL_MODULE].information.modelID, MODULE_OPTION_POWER_METER)) { - new StaticText(window, grid.getLabelSlot(), "access", BUTTON_BACKGROUND, CENTERED); - new TextButton(window, grid.getFieldSlot(1), STR_POWER_METER_INT, [=]() -> uint8_t { -// new RadioPowerMeter(INTERNAL_MODULE); - return 0; - }, 0); + if (isPXX2ModuleOptionAvailable( + reusableBuffer.hardwareAndSettings.modules[INTERNAL_MODULE] + .information.modelID, + MODULE_OPTION_POWER_METER)) { + auto txt = new StaticText(window, grid.getLabelSlot(), "access", + BUTTON_BACKGROUND, CENTERED); + auto b = new TextButton( + window, grid.getFieldSlot(1), STR_POWER_METER_INT, + [=]() -> uint8_t { + // new RadioPowerMeter(INTERNAL_MODULE); + return 0; + }, + OPAQUE); + b->setBgColorHandler([=]() -> LcdFlags { return FIELD_BGCOLOR; }); + b->setFocusHandler([=](bool focus) { + if (focus) { + txt->setBackgroundColor(FOCUS_BGCOLOR); + txt->setTextFlags(FOCUS_COLOR | CENTERED); + } else { + txt->setBackgroundColor(FIELD_FRAME_COLOR); + txt->setTextFlags(CENTERED); + } + txt->invalidate(); + }); grid.nextLine(); } #endif #if defined(INTERNAL_MODULE_MULTI) - new StaticText(window, grid.getLabelSlot(), "multi", BUTTON_BACKGROUND, CENTERED); - new TextButton(window, grid.getFieldSlot(1), STR_SPECTRUM_ANALYSER_INT, [=]() -> uint8_t { - new RadioSpectrumAnalyser(INTERNAL_MODULE); - return 0; - }, 0); - grid.nextLine(); + { + auto txt = new StaticText(window, grid.getLabelSlot(), "multi", + BUTTON_BACKGROUND, CENTERED); + auto b = new TextButton( + window, grid.getFieldSlot(1), STR_SPECTRUM_ANALYSER_INT, + [=]() -> uint8_t { + new RadioSpectrumAnalyser(INTERNAL_MODULE); + return 0; + }, + OPAQUE); + b->setBgColorHandler([=]() -> LcdFlags { return FIELD_BGCOLOR; }); + b->setFocusHandler([=](bool focus) { + if (focus) { + txt->setBackgroundColor(FOCUS_BGCOLOR); + txt->setTextFlags(FOCUS_COLOR | CENTERED); + } else { + txt->setBackgroundColor(FIELD_FRAME_COLOR); + txt->setTextFlags(CENTERED); + } + txt->invalidate(); + }); + grid.nextLine(); + } #endif #if defined(PXX2)|| defined(MULTIMODULE) - if (isPXX2ModuleOptionAvailable(reusableBuffer.hardwareAndSettings.modules[EXTERNAL_MODULE].information.modelID, MODULE_OPTION_SPECTRUM_ANALYSER) || isModuleMultimodule(EXTERNAL_MODULE)) { - new StaticText(window, grid.getLabelSlot(), isModuleMultimodule(EXTERNAL_MODULE) ? "multi" : "access", BUTTON_BACKGROUND, CENTERED); - new TextButton(window, grid.getFieldSlot(1), STR_SPECTRUM_ANALYSER_EXT, [=]() -> uint8_t { - new RadioSpectrumAnalyser(EXTERNAL_MODULE); - return 0; - }, 0); + if (isPXX2ModuleOptionAvailable( + reusableBuffer.hardwareAndSettings.modules[EXTERNAL_MODULE] + .information.modelID, + MODULE_OPTION_SPECTRUM_ANALYSER) || + isModuleMultimodule(EXTERNAL_MODULE)) { + auto txt = new StaticText(window, grid.getLabelSlot(), + isModuleMultimodule(EXTERNAL_MODULE) ? "multi" : "access", + BUTTON_BACKGROUND, CENTERED); + auto b = new TextButton( + window, grid.getFieldSlot(1), STR_SPECTRUM_ANALYSER_EXT, + [=]() -> uint8_t { + new RadioSpectrumAnalyser(EXTERNAL_MODULE); + return 0; + }, + OPAQUE); + b->setBgColorHandler([=]() -> LcdFlags { return FIELD_BGCOLOR; }); + b->setFocusHandler([=](bool focus) { + if (focus) { + txt->setBackgroundColor(FOCUS_BGCOLOR); + txt->setTextFlags(FOCUS_COLOR | CENTERED); + } else { + txt->setBackgroundColor(FIELD_FRAME_COLOR); + txt->setTextFlags(CENTERED); + } + txt->invalidate(); + }); grid.nextLine(); } #endif #if defined(PXX2) - if (isPXX2ModuleOptionAvailable(reusableBuffer.hardwareAndSettings.modules[EXTERNAL_MODULE].information.modelID, MODULE_OPTION_POWER_METER)) { - new StaticText(window, grid.getLabelSlot(), "access", BUTTON_BACKGROUND, CENTERED); - new TextButton(window, grid.getFieldSlot(1), STR_POWER_METER_EXT, [=]() -> uint8_t { -// new RadioPowerMeter(EXTERNAL_MODULE); - return 0; - }, 0); - + if (isPXX2ModuleOptionAvailable( + reusableBuffer.hardwareAndSettings.modules[EXTERNAL_MODULE] + .information.modelID, + MODULE_OPTION_POWER_METER)) { + auto txt = new StaticText(window, grid.getLabelSlot(), "access", + BUTTON_BACKGROUND, CENTERED); + auto b = new TextButton( + window, grid.getFieldSlot(1), STR_POWER_METER_EXT, + [=]() -> uint8_t { + // new RadioPowerMeter(EXTERNAL_MODULE); + return 0; + }, + OPAQUE); + b->setBgColorHandler([=]() -> LcdFlags { return FIELD_BGCOLOR; }); + b->setFocusHandler([=](bool focus) { + if (focus) { + txt->setBackgroundColor(FOCUS_BGCOLOR); + txt->setTextFlags(FOCUS_COLOR | CENTERED); + } else { + txt->setBackgroundColor(FIELD_FRAME_COLOR); + txt->setTextFlags(CENTERED); + } + txt->invalidate(); + }); grid.nextLine(); } #endif #if defined(GHOST) if (isModuleGhost(EXTERNAL_MODULE)) { - new StaticText(window, grid.getLabelSlot(), "ghost", BUTTON_BACKGROUND, CENTERED); - new TextButton(window, grid.getFieldSlot(1), "Ghost module config", [=]() -> uint8_t { - new RadioGhostModuleConfig(EXTERNAL_MODULE); - return 0; - }, 0); + auto txt = new StaticText(window, grid.getLabelSlot(), "ghost", + BUTTON_BACKGROUND, CENTERED); + auto b = new TextButton( + window, grid.getFieldSlot(1), "Ghost module config", + [=]() -> uint8_t { + new RadioGhostModuleConfig(EXTERNAL_MODULE); + return 0; + }, + OPAQUE); + b->setBgColorHandler([=]() -> LcdFlags { return FIELD_BGCOLOR; }); + b->setFocusHandler([=](bool focus) { + if (focus) { + txt->setBackgroundColor(FOCUS_BGCOLOR); + txt->setTextFlags(FOCUS_COLOR | CENTERED); + } else { + txt->setBackgroundColor(FIELD_FRAME_COLOR); + txt->setTextFlags(CENTERED); + } + txt->invalidate(); + }); grid.nextLine(); } #endif