Skip to content

Commit

Permalink
feat(color): Improvements to switch and source select menu (#4104)
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz committed Oct 13, 2023
1 parent 614ff28 commit ede1d00
Show file tree
Hide file tree
Showing 33 changed files with 695 additions and 488 deletions.
110 changes: 70 additions & 40 deletions radio/src/gui/colorlcd/sourcechoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,74 +20,104 @@
*/

#include "sourcechoice.h"
#include "menutoolbar.h"
#include "menu.h"

#include "dataconstants.h"
#include "lcd.h"
#include "strhelpers.h"
#include "draw_functions.h"
#include "lcd.h"
#include "menu.h"
#include "menutoolbar.h"
#include "opentx.h"
#include "strhelpers.h"
#include "switches.h"

#if LCD_W > LCD_H
#define FILTER_COLUMNS 3
#else
#define FILTER_COLUMNS 2
#endif

class SourceChoiceMenuToolbar : public MenuToolbar
{
public:
SourceChoiceMenuToolbar(SourceChoice * choice, Menu * menu):
MenuToolbar(choice, menu)
{
addButton(STR_CHAR_INPUT, MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT);
public:
SourceChoiceMenuToolbar(SourceChoice *choice, Menu *menu) :
MenuToolbar(choice, menu, FILTER_COLUMNS)
{
addButton(STR_CHAR_INPUT, MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT, nullptr,
STR_MENU_INPUTS);
#if defined(LUA_MODEL_SCRIPTS)
if (modelCustomScriptsEnabled())
addButton(STR_CHAR_LUA, MIXSRC_FIRST_LUA, MIXSRC_LAST_LUA);
if (modelCustomScriptsEnabled())
addButton(STR_CHAR_LUA, MIXSRC_FIRST_LUA, MIXSRC_LAST_LUA, nullptr,
STR_MENU_LUA);
#endif
#if defined(PCBHORUS)
auto lastSource = MIXSRC_LAST_SPACEMOUSE;
auto lastSource = MIXSRC_LAST_SPACEMOUSE;
#elif defined(IMU)
auto lastSource = MIXSRC_TILT_Y;
auto lastSource = MIXSRC_TILT_Y;
#else
auto lastSource = MIXSRC_LAST_STICK;
auto lastSource = MIXSRC_LAST_STICK;
#endif
addButton(STR_CHAR_STICK, MIXSRC_FIRST_STICK, lastSource, [=](int16_t index) {
if (index >= MIXSRC_FIRST_POT && index <= MIXSRC_LAST_POT)
return false;
addButton(
STR_CHAR_STICK, MIXSRC_FIRST_STICK, lastSource,
[=](int16_t index) {
if (index >= MIXSRC_FIRST_POT && index <= MIXSRC_LAST_POT)
return false;
#if MAX_AXIS > 0
if (index >= MIXSRC_FIRST_AXIS && index <= MIXSRC_LAST_AXIS)
return false;
if (index >= MIXSRC_FIRST_AXIS && index <= MIXSRC_LAST_AXIS)
return false;
#endif
return index >= MIXSRC_FIRST_STICK && index <= lastSource;
});
addButton(STR_CHAR_POT, MIXSRC_FIRST_POT, MIXSRC_LAST_POT);
addButton(STR_CHAR_FUNCTION, MIXSRC_MIN, MIXSRC_LAST_TIMER, [=](int16_t index) {
return (index >= MIXSRC_MIN && index <= MIXSRC_MAX) || (index >= MIXSRC_TX_VOLTAGE && index <= MIXSRC_LAST_TIMER);
});
return index >= MIXSRC_FIRST_STICK && index <= lastSource;
},
STR_MENU_STICKS);
addButton(STR_CHAR_POT, MIXSRC_FIRST_POT, MIXSRC_LAST_POT, nullptr,
STR_MENU_POTS);
addButton(
STR_CHAR_FUNCTION, MIXSRC_MIN, MIXSRC_LAST_TIMER,
[=](int16_t index) {
return (index >= MIXSRC_MIN && index <= MIXSRC_MAX) ||
(index >= MIXSRC_TX_VOLTAGE && index <= MIXSRC_LAST_TIMER);
},
STR_MENU_OTHER);
#if defined(HELI)
if (modelHeliEnabled())
addButton(STR_CHAR_CYC, MIXSRC_FIRST_HELI, MIXSRC_LAST_HELI);
if (modelHeliEnabled())
addButton(STR_CHAR_CYC, MIXSRC_FIRST_HELI, MIXSRC_LAST_HELI, nullptr,
STR_MENU_HELI);
#endif
addButton(STR_CHAR_TRIM, MIXSRC_FIRST_TRIM, MIXSRC_LAST_TRIM);
addButton(STR_CHAR_SWITCH, MIXSRC_FIRST_SWITCH, MIXSRC_LAST_SWITCH);
if (modelLSEnabled())
addButton(STR_CHAR_SWITCH, MIXSRC_FIRST_LOGICAL_SWITCH, MIXSRC_LAST_LOGICAL_SWITCH);
addButton(STR_CHAR_TRAINER, MIXSRC_FIRST_TRAINER, MIXSRC_LAST_TRAINER);
addButton(STR_CHAR_CHANNEL, MIXSRC_FIRST_CH, MIXSRC_LAST_CH);
addButton(STR_CHAR_TRIM, MIXSRC_FIRST_TRIM, MIXSRC_LAST_TRIM, nullptr,
STR_MENU_TRIMS);
addButton(STR_CHAR_SWITCH, MIXSRC_FIRST_SWITCH, MIXSRC_LAST_SWITCH, nullptr,
STR_MENU_SWITCHES);
if (modelLSEnabled())
addButton("LS", MIXSRC_FIRST_LOGICAL_SWITCH, MIXSRC_LAST_LOGICAL_SWITCH,
nullptr, STR_MENU_LOGICAL_SWITCHES);
addButton(STR_CHAR_TRAINER, MIXSRC_FIRST_TRAINER, MIXSRC_LAST_TRAINER,
nullptr, STR_MENU_TRAINER);
addButton(STR_CHAR_CHANNEL, MIXSRC_FIRST_CH, MIXSRC_LAST_CH, nullptr,
STR_MENU_CHANNELS);
#if defined(GVARS)
if (modelGVEnabled())
addButton(STR_CHAR_SLIDER, MIXSRC_FIRST_GVAR, MIXSRC_LAST_GVAR);
if (modelGVEnabled())
addButton(STR_CHAR_SLIDER, MIXSRC_FIRST_GVAR, MIXSRC_LAST_GVAR, nullptr,
STR_MENU_GVARS);
#endif
if (modelTelemetryEnabled())
addButton(STR_CHAR_TELEMETRY, MIXSRC_FIRST_TELEM, MIXSRC_LAST_TELEM);
}
if (modelTelemetryEnabled())
addButton(STR_CHAR_TELEMETRY, MIXSRC_FIRST_TELEM, MIXSRC_LAST_TELEM,
nullptr, STR_MENU_TELEMETRY);

if ((nxtBtnPos > filterColumns) && choice->isValueAvailable &&
choice->isValueAvailable(0))
addButton(STR_SELECT_MENU_CLR, 0, 0, nullptr, nullptr, true);
}
};

// defined in gui/gui_common.cpp
uint8_t switchToMix(uint8_t source);

SourceChoice::SourceChoice(Window* parent, const rect_t &rect, int16_t vmin,
SourceChoice::SourceChoice(Window *parent, const rect_t &rect, int16_t vmin,
int16_t vmax, std::function<int16_t()> getValue,
std::function<void(int16_t)> setValue,
WindowFlags windowFlags, LcdFlags textFlags) :
Choice(parent, rect, vmin, vmax, getValue, setValue)
{
setMenuTitle(STR_SOURCE);
setBeforeDisplayMenuHandler([=](Menu *menu) {
auto tb = new SourceChoiceMenuToolbar(this, menu);
menu->setToolbar(tb);
Expand Down Expand Up @@ -122,5 +152,5 @@ SourceChoice::SourceChoice(Window* parent, const rect_t &rect, int16_t vmin,
return std::string(getSourceString(value));
});

setAvailableHandler([](int v){ return isSourceAvailable(v); });
setAvailableHandler([](int v) { return isSourceAvailable(v); });
}
5 changes: 5 additions & 0 deletions radio/src/gui/colorlcd/sourcechoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "choice.h"
#include "form.h"

class SourceChoiceMenuToolbar;

bool isSourceAvailable(int source);

class SourceChoice : public Choice
Expand All @@ -35,6 +37,9 @@ class SourceChoice : public Choice
std::function<void(int16_t)> setValue,
WindowFlags windowFlags = 0, LcdFlags textFlags = 0);

protected:
friend SourceChoiceMenuToolbar;

#if defined(DEBUG_WINDOWS)
std::string getName() const override { return "SourceChoice"; }
#endif
Expand Down
88 changes: 79 additions & 9 deletions radio/src/gui/colorlcd/switchchoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,69 @@ class SwitchChoiceMenuToolbar : public MenuToolbar
{
public:
SwitchChoiceMenuToolbar(SwitchChoice* choice, Menu* menu) :
MenuToolbar(choice, menu)
MenuToolbar(choice, menu, 2)
{
addButton(STR_CHAR_SWITCH, SWSRC_FIRST_SWITCH, SWSRC_LAST_MULTIPOS_SWITCH);
addButton(STR_CHAR_TRIM, SWSRC_FIRST_TRIM, SWSRC_LAST_TRIM);
addButton(STR_CHAR_SWITCH, SWSRC_FIRST_LOGICAL_SWITCH, SWSRC_LAST_LOGICAL_SWITCH);
addButton(STR_CHAR_TELEMETRY, SWSRC_FIRST_SENSOR, SWSRC_LAST_SENSOR);
addButton(STR_CHAR_SWITCH, SWSRC_FIRST_SWITCH, SWSRC_LAST_MULTIPOS_SWITCH,
nullptr, STR_MENU_SWITCHES);
addButton(STR_CHAR_TRIM, SWSRC_FIRST_TRIM, SWSRC_LAST_TRIM, nullptr,
STR_MENU_TRIMS);
addButton("LS", SWSRC_FIRST_LOGICAL_SWITCH, SWSRC_LAST_LOGICAL_SWITCH,
nullptr, STR_MENU_LOGICAL_SWITCHES);
addButton("FM", SWSRC_FIRST_FLIGHT_MODE, SWSRC_LAST_FLIGHT_MODE, nullptr,
STR_FLIGHT_MODE);
addButton(STR_CHAR_TELEMETRY, SWSRC_FIRST_SENSOR, SWSRC_LAST_SENSOR,
nullptr, STR_MENU_TELEMETRY);
#if defined(DEBUG_LATENCY)
auto lastSource = SWSRC_LATENCY_TOGGLE;
#else
auto lastSource = SWSRC_RADIO_ACTIVITY;
#endif
addButton(STR_CHAR_FUNCTION, SWSRC_TELEMETRY_STREAMING, lastSource, [=](int16_t index) {
index = abs(index);
return index == 0 || (index >= SWSRC_TELEMETRY_STREAMING && index <= lastSource && !(index >= SWSRC_FIRST_SENSOR && index <= SWSRC_LAST_SENSOR));
addButton(
STR_CHAR_FUNCTION, SWSRC_ON, lastSource,
[=](int16_t index) {
index = abs(index);
return index == 0 || index == SWSRC_ON || index == SWSRC_ONE ||
(index >= SWSRC_TELEMETRY_STREAMING && index <= lastSource &&
!(index >= SWSRC_FIRST_SENSOR && index <= SWSRC_LAST_SENSOR));
},
STR_MENU_OTHER);

if ((nxtBtnPos > filterColumns) && choice->isValueAvailable &&
choice->isValueAvailable(0))
addButton(STR_SELECT_MENU_CLR, 0, 0, nullptr, nullptr, true);

#if defined(HARDWARE_TOUCH)
coord_t y =
height() - MENUS_TOOLBAR_BUTTON_WIDTH - MENUS_TOOLBAR_BUTTON_PADDING;
coord_t w = width() - MENUS_TOOLBAR_BUTTON_PADDING * 2;

invertBtn = new MenuToolbarButton(
this, {MENUS_TOOLBAR_BUTTON_PADDING, y, w, MENUS_TOOLBAR_BUTTON_WIDTH},
STR_SELECT_MENU_INV);
invertBtn->check(choice->inverted);

invertBtn->setPressHandler([=]() {
lv_obj_clear_state(invertBtn->getLvObj(), LV_STATE_FOCUSED);
longPress();
return choice->inverted;
});
#endif
}

void longPress()
{
SwitchChoice* switchChoice = (SwitchChoice*)choice;
switchChoice->inverted = !switchChoice->inverted;
auto idx = menu->selection();
switchChoice->fillMenu(menu, filter);
menu->select(idx);
#if defined(HARDWARE_TOUCH)
invertBtn->check(switchChoice->inverted);
#endif
}

protected:
MenuToolbarButton* invertBtn = nullptr;
};

void SwitchChoice::LongPressHandler(void* data)
Expand All @@ -61,12 +108,33 @@ void SwitchChoice::LongPressHandler(void* data)
}
}

void SwitchChoice::setValue(int value)
{
if (inMenu) {
if (inverted) value = -value;
inMenu = false;
}
Choice::setValue(value);
}

int SwitchChoice::getIntValue() const
{
int value = Choice::getIntValue();
if (inMenu) value = abs(value);
return value;
}

SwitchChoice::SwitchChoice(Window* parent, const rect_t& rect, int vmin,
int vmax, std::function<int16_t()> getValue,
std::function<void(int16_t)> setValue) :
Choice(parent, rect, vmin, vmax, getValue, setValue)
Choice(parent, rect, 0, vmax, getValue, setValue)
{
setMenuTitle(STR_SWITCH);

setBeforeDisplayMenuHandler([=](Menu* menu) {
inverted = getValue() < 0;
inMenu = true;

auto tb = new SwitchChoiceMenuToolbar(this, menu);
menu->setToolbar(tb);

Expand Down Expand Up @@ -94,6 +162,8 @@ SwitchChoice::SwitchChoice(Window* parent, const rect_t& rect, int vmin,
});

setTextHandler([=](int value) {
if (inMenu && inverted) value = -value;

if (isValueAvailable && !isValueAvailable(value))
return std::to_string(0); // we will fix this later

Expand Down
10 changes: 10 additions & 0 deletions radio/src/gui/colorlcd/switchchoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "choice.h"
#include "form.h"

class SwitchChoiceMenuToolbar;

class SwitchChoice : public Choice
{
public:
Expand All @@ -35,6 +37,14 @@ class SwitchChoice : public Choice
static void LongPressHandler(void* data);

protected:
friend SwitchChoiceMenuToolbar;

bool inverted = false;
bool inMenu = false;

void setValue(int value) override;
int getIntValue() const override;

#if defined(DEBUG_WINDOWS)
std::string getName() const override { return "SwitchChoice"; }
#endif
Expand Down
18 changes: 18 additions & 0 deletions radio/src/gui/colorlcd/themes/etx_lv_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,19 @@ const lv_obj_class_t etx_button_class = {
.instance_size = sizeof(lv_btn_t),
};

const lv_obj_class_t etx_menu_button_class = {
.base_class = &lv_btn_class,
.constructor_cb = etx_button_constructor,
.destructor_cb = nullptr,
.user_data = nullptr,
.event_cb = nullptr,
.width_def = LV_SIZE_CONTENT,
.height_def = 32,
.editable = LV_OBJ_CLASS_EDITABLE_INHERIT,
.group_def = LV_OBJ_CLASS_GROUP_DEF_FALSE,
.instance_size = sizeof(lv_btn_t),
};

const lv_obj_class_t etx_choice_class = {
.base_class = &lv_obj_class,
.constructor_cb = etx_choice_constructor,
Expand Down Expand Up @@ -983,6 +996,11 @@ lv_obj_t* etx_button_create(lv_obj_t* parent)
return etx_create(&etx_button_class, parent);
}

lv_obj_t* etx_menu_button_create(lv_obj_t* parent)
{
return etx_create(&etx_menu_button_class, parent);
}

lv_obj_t* etx_choice_create(lv_obj_t* parent)
{
return etx_create(&etx_choice_class, parent);
Expand Down
6 changes: 1 addition & 5 deletions radio/src/targets/horus/libopenui_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ constexpr uint32_t ALERT_MESSAGE_LEFT = ALERT_TITLE_LEFT;

constexpr coord_t INPUT_EDIT_CURVE_WIDTH = 132;
constexpr coord_t INPUT_EDIT_CURVE_HEIGHT = INPUT_EDIT_CURVE_WIDTH;
constexpr coord_t MENUS_LINE_HEIGHT = 35;
constexpr coord_t MENUS_WIDTH = 200;
constexpr coord_t MENUS_MAX_HEIGHT = (MENUS_LINE_HEIGHT * 7);

constexpr rect_t MENUS_TOOLBAR_RECT = { 100, 51, 30, 209 };
constexpr coord_t MENUS_MAX_HEIGHT = (MENUS_LINE_HEIGHT * 7) + 8;

#define ROTARY_ENCODER_SPEED() rotencSpeed
4 changes: 0 additions & 4 deletions radio/src/targets/nv14/libopenui_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ constexpr uint32_t ALERT_MESSAGE_LEFT = 15;

constexpr coord_t INPUT_EDIT_CURVE_WIDTH = 176;
constexpr coord_t INPUT_EDIT_CURVE_HEIGHT = 132;
constexpr coord_t MENUS_LINE_HEIGHT = 35;
constexpr coord_t MENUS_WIDTH = 200;
constexpr coord_t MENUS_MAX_HEIGHT = (MENUS_LINE_HEIGHT * 10);

constexpr rect_t MENUS_TOOLBAR_RECT = { 35, (LCD_H - MENUS_MAX_HEIGHT) / 2, 50, MENUS_MAX_HEIGHT };

// Disable rotary encoder, as the NV14 does not have one
#define ROTARY_ENCODER_SPEED() 0
Loading

0 comments on commit ede1d00

Please sign in to comment.