Merge pull request #8432 from opentx/raphaelcoeffic/getmainzone

2.4: some layout improvements
This commit is contained in:
Bertrand Songis
2021-04-07 08:52:37 +02:00
committed by GitHub
12 changed files with 255 additions and 312 deletions
+57 -24
View File
@@ -97,14 +97,14 @@ void loadCustomScreens()
} }
} }
void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) void Layout::decorate()
{ {
// check if deco setting are still up-to-date // check if deco setting are still up-to-date
uint8_t checkSettings = uint8_t checkSettings =
(topbar ? 1 << 0 : 0) | (hasTopbar() ? 1 << 0 : 0) |
(sliders ? 1 << 1 : 0) | (hasSliders() ? 1 << 1 : 0) |
(trims ? 1 << 2 : 0) | (hasTrims() ? 1 << 2 : 0) |
(flightMode ? 1 << 3 : 0); (hasFlightMode() ? 1 << 3 : 0);
if (checkSettings == decorationSettings) { if (checkSettings == decorationSettings) {
// everything ok, exit! // everything ok, exit!
@@ -123,16 +123,16 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode)
// save settings // save settings
decorationSettings = checkSettings; decorationSettings = checkSettings;
if (topbar) { if (hasTopbar()) {
topBar = new TopBar(this); topBar = new TopBar(this);
topBar->load(); topBar->load();
decorations.push_back(topBar); decorations.push_back(topBar);
} }
if (sliders) { if (hasSliders()) {
#if defined(HARDWARE_EXT1) || defined(HARDWARE_EXT2) #if defined(HARDWARE_EXT1) || defined(HARDWARE_EXT2)
coord_t yOffset = (trims ? - TRIM_SQUARE_SIZE : 0) + (topbar ? TOPBAR_HEIGHT / 2 : 0); coord_t yOffset = (hasTrims() ? - TRIM_SQUARE_SIZE : 0) + (hasTopbar() ? TOPBAR_HEIGHT / 2 : 0);
#endif #endif
decorations.push_back( decorations.push_back(
@@ -163,17 +163,17 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode)
#if defined(HARDWARE_EXT1) #if defined(HARDWARE_EXT1)
if (IS_POT_SLIDER_AVAILABLE(EXT1)) { if (IS_POT_SLIDER_AVAILABLE(EXT1)) {
decorations.push_back( decorations.push_back(
new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2},
[=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_LEFT]; }) [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_LEFT]; })
); );
decorations.push_back( decorations.push_back(
new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2},
[=] { return calibratedAnalogs[CALIBRATED_POT_EXT1]; }) [=] { return calibratedAnalogs[CALIBRATED_POT_EXT1]; })
); );
} }
else { else {
decorations.push_back( decorations.push_back(
new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(hasTopbar())},
[=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_LEFT]; }) [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_LEFT]; })
); );
} }
@@ -182,33 +182,33 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode)
#if defined(HARDWARE_EXT2) #if defined(HARDWARE_EXT2)
if (IS_POT_SLIDER_AVAILABLE(EXT2)) { if (IS_POT_SLIDER_AVAILABLE(EXT2)) {
decorations.push_back( decorations.push_back(
new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset, TRIM_SQUARE_SIZE,
VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2},
[=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_RIGHT]; }) [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_RIGHT]; })
); );
decorations.push_back( decorations.push_back(
new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE, new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE,
VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2},
[=] { return calibratedAnalogs[CALIBRATED_POT_EXT2]; }) [=] { return calibratedAnalogs[CALIBRATED_POT_EXT2]; })
); );
} }
else { else {
decorations.push_back( decorations.push_back(
new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset, TRIM_SQUARE_SIZE,
VERTICAL_SLIDERS_HEIGHT(topbar)}, VERTICAL_SLIDERS_HEIGHT(hasTopbar())},
[=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_RIGHT]; }) [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_RIGHT]; })
); );
} }
#endif #endif
} }
if (trims) { if (hasTrims()) {
#if defined(HARDWARE_POT3) || defined(HARDWARE_EXT1) #if defined(HARDWARE_POT3) || defined(HARDWARE_EXT1)
coord_t xOffset = sliders? TRIM_SQUARE_SIZE : 0; coord_t xOffset = hasSliders() ? TRIM_SQUARE_SIZE : 0;
#else #else
coord_t xOffset = 0; coord_t xOffset = 0;
#endif #endif
coord_t yOffset = (trims ? - TRIM_SQUARE_SIZE : 0); coord_t yOffset = (hasTrims() ? - TRIM_SQUARE_SIZE : 0);
// Trim order TRIM_LH, TRIM_LV, TRIM_RV, TRIM_RH // Trim order TRIM_LH, TRIM_LV, TRIM_RV, TRIM_RH
@@ -226,22 +226,55 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode)
// Left // Left
decorations.push_back( decorations.push_back(
new MainViewVerticalTrim(this, {HMARGIN + xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset + (topbar ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, new MainViewVerticalTrim(this, {HMARGIN + xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset + (hasTopbar() ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(hasTopbar())},
[=] { return getTrimValue(mixerCurrentFlightMode, 1); }) [=] { return getTrimValue(mixerCurrentFlightMode, 1); })
); );
// Right // Right
decorations.push_back( decorations.push_back(
new MainViewVerticalTrim(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE - xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset + (topbar ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, new MainViewVerticalTrim(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE - xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset + (hasTopbar() ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(hasTopbar())},
[=] { return getTrimValue(mixerCurrentFlightMode, 2); }) [=] { return getTrimValue(mixerCurrentFlightMode, 2); })
); );
} }
if (flightMode) { if (hasFlightMode()) {
decorations.push_back( decorations.push_back(
new DynamicText(this, {50, LCD_H - 4 - (sliders? 2 * TRIM_SQUARE_SIZE: TRIM_SQUARE_SIZE), LCD_W - 100, 20}, [=] { new DynamicText(this, {50, LCD_H - 4 - (hasSliders() ? 2 * TRIM_SQUARE_SIZE: TRIM_SQUARE_SIZE), LCD_W - 100, 20}, [=] {
return g_model.flightModeData[mixerCurrentFlightMode].name; return g_model.flightModeData[mixerCurrentFlightMode].name;
}, CENTERED) }, CENTERED)
); );
} }
} }
rect_t Layout::getMainZone(rect_t zone) const
{
if (hasTopbar()) {
zone.y += MENU_HEADER_HEIGHT;
zone.h -= MENU_HEADER_HEIGHT;
}
if (hasFlightMode() || hasTrims()) {
zone.h -= TRIM_SQUARE_SIZE;
}
if (hasSliders()) {
#if NUM_SLIDERS + NUM_POTS > 2
zone.h -= TRIM_SQUARE_SIZE;
#endif
zone.w -= 2 * TRIM_SQUARE_SIZE;
zone.x += TRIM_SQUARE_SIZE;
}
if (hasTrims()) {
zone.w -= 2 * TRIM_SQUARE_SIZE;
zone.x += TRIM_SQUARE_SIZE;
}
if (zone.w % 2 != 0)
zone.w -= 1;
if (zone.h % 2 != 0)
zone.h -= 1;
return zone;
}
+68 -3
View File
@@ -32,29 +32,94 @@ constexpr coord_t TRIM_SQUARE_SIZE = 17;
class LayoutFactory; class LayoutFactory;
class Layout: public WidgetsContainer<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS> #define LAYOUT_COMMON_OPTIONS \
{ STR_TOP_BAR, ZoneOption::Bool }, \
{ STR_FLIGHT_MODE, ZoneOption::Bool }, \
{ STR_SLIDERS, ZoneOption::Bool }, \
{ STR_TRIMS, ZoneOption::Bool }, \
{ STR_MIRROR, ZoneOption::Bool }
#define LAYOUT_OPTIONS_END \
{ nullptr, ZoneOption::Bool }
typedef WidgetsContainer<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS> LayoutBase;
class Layout: public LayoutBase
{ {
friend class LayoutFactory; friend class LayoutFactory;
public: public:
// Common 'ZoneOptionValue's among all layouts
enum {
OPTION_TOPBAR = 0,
OPTION_FM,
OPTION_SLIDERS,
OPTION_TRIMS,
OPTION_MIRRORED,
OPTION_LAST_DEFAULT=OPTION_MIRRORED
};
Layout(const LayoutFactory * factory, PersistentData * persistentData): Layout(const LayoutFactory * factory, PersistentData * persistentData):
WidgetsContainer<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>({0, 0, LCD_W, LCD_H}, persistentData), LayoutBase({0, 0, LCD_W, LCD_H}, persistentData),
factory(factory) factory(factory)
{ {
decorate();
} }
void create() override
{
setOptionValue(OPTION_TOPBAR, OPTION_VALUE_BOOL(true));
setOptionValue(OPTION_FM, OPTION_VALUE_BOOL(true));
setOptionValue(OPTION_SLIDERS, OPTION_VALUE_BOOL(true));
setOptionValue(OPTION_TRIMS, OPTION_VALUE_BOOL(true));
setOptionValue(OPTION_MIRRORED, OPTION_VALUE_BOOL(false));
decorate();
}
inline const LayoutFactory * getFactory() const inline const LayoutFactory * getFactory() const
{ {
return factory; return factory;
} }
void decorate(bool topbar, bool sliders, bool trims, bool flightMode); void checkEvents() override
{
LayoutBase::checkEvents();
decorate();
}
bool hasTopbar() const {
return getOptionValue(OPTION_TOPBAR)->boolValue;
}
bool hasFlightMode() const {
return getOptionValue(OPTION_FM)->boolValue;
}
bool hasSliders() const {
return getOptionValue(OPTION_SLIDERS)->boolValue;
}
bool hasTrims() const {
return getOptionValue(OPTION_TRIMS)->boolValue;
}
bool isMirrored() const {
return getOptionValue(OPTION_MIRRORED)->boolValue;
}
protected: protected:
const LayoutFactory * factory; const LayoutFactory * factory;
TopBar * topBar = nullptr; TopBar * topBar = nullptr;
uint8_t decorationSettings = 0; uint8_t decorationSettings = 0;
std::list<Window*> decorations; std::list<Window*> decorations;
// adds trims, sliders, pots, etc...
void decorate();
// get the Zone rect without decoration
rect_t getMainZone(rect_t zone) const;
}; };
void registerLayout(const LayoutFactory * factory); void registerLayout(const LayoutFactory * factory);
+2 -66
View File
@@ -21,12 +21,6 @@
#include "opentx.h" #include "opentx.h"
#include "trims.h" #include "trims.h"
#define HAS_TOPBAR() (persistentData->options[0].value.boolValue == true)
#define HAS_FM() (persistentData->options[1].value.boolValue == true)
#define HAS_SLIDERS() (persistentData->options[2].value.boolValue == true)
#define HAS_TRIMS() (persistentData->options[3].value.boolValue == true)
#define IS_MIRRORED() (persistentData->options[4].value.boolValue == true)
constexpr coord_t border = 10; constexpr coord_t border = 10;
const uint8_t LBM_LAYOUT_1x1[] = { const uint8_t LBM_LAYOUT_1x1[] = {
@@ -34,12 +28,8 @@ const uint8_t LBM_LAYOUT_1x1[] = {
}; };
const ZoneOption OPTIONS_LAYOUT_1x1[] = { const ZoneOption OPTIONS_LAYOUT_1x1[] = {
{ STR_TOP_BAR, ZoneOption::Bool }, LAYOUT_COMMON_OPTIONS,
{ STR_FLIGHT_MODE, ZoneOption::Bool }, LAYOUT_OPTIONS_END
{ STR_SLIDERS, ZoneOption::Bool },
{ STR_TRIMS, ZoneOption::Bool },
{ STR_MIRROR, ZoneOption::Bool },
{ nullptr, ZoneOption::Bool }
}; };
class Layout1x1: public Layout class Layout1x1: public Layout
@@ -48,73 +38,19 @@ class Layout1x1: public Layout
Layout1x1(const LayoutFactory * factory, Layout::PersistentData * persistentData): Layout1x1(const LayoutFactory * factory, Layout::PersistentData * persistentData):
Layout(factory, persistentData) Layout(factory, persistentData)
{ {
decorate();
} }
void create() override
{
Layout::create();
persistentData->options[0].value.boolValue = true;
persistentData->options[1].value.boolValue = true;
persistentData->options[2].value.boolValue = true;
persistentData->options[3].value.boolValue = true;
persistentData->options[4].value.boolValue = false;
persistentData->options[5].value.boolValue = false;
decorate();
}
void decorate()
{
Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM());
}
unsigned int getZonesCount() const override unsigned int getZonesCount() const override
{ {
return 1; return 1;
} }
rect_t getMainZone(rect_t zone) const
{
if (HAS_TOPBAR()) {
zone.y += MENU_HEADER_HEIGHT;
zone.h -= MENU_HEADER_HEIGHT;
}
if (HAS_FM() || HAS_TRIMS()) {
zone.h -= TRIM_SQUARE_SIZE;
}
if (HAS_SLIDERS()) {
#if NUM_SLIDERS + NUM_POTS > 2
zone.h -= TRIM_SQUARE_SIZE;
#endif
zone.w -= 2 * TRIM_SQUARE_SIZE;
zone.x += TRIM_SQUARE_SIZE;
}
if (HAS_TRIMS()) {
zone.w -= 2 * TRIM_SQUARE_SIZE;
zone.x += TRIM_SQUARE_SIZE;
}
return zone;
}
rect_t getZone(unsigned int index) const override rect_t getZone(unsigned int index) const override
{ {
rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border}); rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border});
return zone; return zone;
} }
void checkEvents() override
{
Layout::checkEvents();
decorate();
}
protected:
uint8_t value = 0;
}; };
BaseLayoutFactory<Layout1x1> layout1x1("Layout1x1", "Fullscreen", LBM_LAYOUT_1x1, OPTIONS_LAYOUT_1x1); BaseLayoutFactory<Layout1x1> layout1x1("Layout1x1", "Fullscreen", LBM_LAYOUT_1x1, OPTIONS_LAYOUT_1x1);
+16 -45
View File
@@ -22,29 +22,15 @@
#include "sliders.h" #include "sliders.h"
#include "trims.h" #include "trims.h"
#define HAS_TOPBAR() (persistentData->options[0].value.boolValue == true) constexpr coord_t border = 10;
#define HAS_FM() (persistentData->options[1].value.boolValue == true)
#define HAS_SLIDERS() (persistentData->options[2].value.boolValue == true)
#define HAS_TRIMS() (persistentData->options[3].value.boolValue == true)
#define IS_MIRRORED() (persistentData->options[4].value.boolValue == true)
const uint8_t LBM_LAYOUT_2P1[] = { const uint8_t LBM_LAYOUT_2P1[] = {
#include "mask_layout2+1.lbm" #include "mask_layout2+1.lbm"
}; };
const ZoneOption OPTIONS_LAYOUT_2P1[] = { const ZoneOption OPTIONS_LAYOUT_2P1[] = {
{ STR_TOP_BAR, ZoneOption::Bool }, LAYOUT_COMMON_OPTIONS,
{ STR_FLIGHT_MODE, ZoneOption::Bool }, LAYOUT_OPTIONS_END
{ STR_SLIDERS, ZoneOption::Bool },
{ STR_TRIMS, ZoneOption::Bool },
{ STR_MIRROR, ZoneOption::Bool },
{ nullptr, ZoneOption::Bool }
};
const rect_t ZONES_LAYOUT_2P1[3] = {
{ 240, 60, 192, 152 },
{ 48, 60, 180, 70 },
{ 48, 142, 180, 70 }
}; };
class Layout2P1: public Layout class Layout2P1: public Layout
@@ -53,44 +39,29 @@ class Layout2P1: public Layout
Layout2P1(const LayoutFactory * factory, Layout::PersistentData * persistentData): Layout2P1(const LayoutFactory * factory, Layout::PersistentData * persistentData):
Layout(factory, persistentData) Layout(factory, persistentData)
{ {
decorate();
}
void create() override
{
Layout::create();
persistentData->options[0].value.boolValue = true;
persistentData->options[1].value.boolValue = true;
persistentData->options[2].value.boolValue = true;
persistentData->options[3].value.boolValue = true;
persistentData->options[4].value.boolValue = false;
persistentData->options[5].value.boolValue = false;
decorate();
}
void decorate()
{
Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM());
} }
unsigned int getZonesCount() const override unsigned int getZonesCount() const override
{ {
return DIM(ZONES_LAYOUT_2P1); return 3;
} }
rect_t getZone(unsigned int index) const override rect_t getZone(unsigned int index) const override
{ {
return ZONES_LAYOUT_2P1[index]; rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border});
}
void checkEvents() override if (index == 0) {
{ return {isMirrored() ? zone.x : zone.x + zone.w / 2, zone.y,zone.w / 2, zone.h};
Layout::checkEvents(); }
// TODO call this from the Layout config window else if (index == 1) {
decorate(); return {isMirrored() ? zone.x + zone.w / 2 : zone.x, zone.y,zone.w / 2, zone.h / 2};
}
else {
return {isMirrored() ? zone.x + zone.w / 2 : zone.x, zone.y + zone.h / 2,zone.w / 2, zone.h / 2};
}
return zone;
} }
protected:
uint8_t value = 0;
}; };
BaseLayoutFactory<Layout2P1> layout2P1("Layout2P1", "2 + 1", LBM_LAYOUT_2P1, OPTIONS_LAYOUT_2P1); BaseLayoutFactory<Layout2P1> layout2P1("Layout2P1", "2 + 1", LBM_LAYOUT_2P1, OPTIONS_LAYOUT_2P1);
+9 -46
View File
@@ -22,23 +22,15 @@
#include "sliders.h" #include "sliders.h"
#include "trims.h" #include "trims.h"
#define HAS_TOPBAR() (persistentData->options[0].value.boolValue == true) constexpr coord_t border = 10;
#define HAS_FM() (persistentData->options[1].value.boolValue == true)
#define HAS_SLIDERS() (persistentData->options[2].value.boolValue == true)
#define HAS_TRIMS() (persistentData->options[3].value.boolValue == true)
#define IS_MIRRORED() (persistentData->options[4].value.boolValue == true)
const uint8_t LBM_LAYOUT_2x1[] = { const uint8_t LBM_LAYOUT_2x1[] = {
#include "mask_layout2x1.lbm" #include "mask_layout2x1.lbm"
}; };
const ZoneOption OPTIONS_LAYOUT_2x1[] = { const ZoneOption OPTIONS_LAYOUT_2x1[] = {
{ STR_TOP_BAR, ZoneOption::Bool }, LAYOUT_COMMON_OPTIONS,
{ STR_FLIGHT_MODE, ZoneOption::Bool }, LAYOUT_OPTIONS_END
{ STR_SLIDERS, ZoneOption::Bool },
{ STR_TRIMS, ZoneOption::Bool },
{ STR_MIRROR, ZoneOption::Bool },
{ nullptr, ZoneOption::Bool }
}; };
class Layout2x1: public Layout class Layout2x1: public Layout
@@ -47,27 +39,8 @@ class Layout2x1: public Layout
Layout2x1(const LayoutFactory * factory, Layout::PersistentData * persistentData): Layout2x1(const LayoutFactory * factory, Layout::PersistentData * persistentData):
Layout(factory, persistentData) Layout(factory, persistentData)
{ {
decorate();
} }
void create() override
{
Layout::create();
persistentData->options[0].value.boolValue = true;
persistentData->options[1].value.boolValue = true;
persistentData->options[2].value.boolValue = true;
persistentData->options[3].value.boolValue = true;
persistentData->options[4].value.boolValue = false;
persistentData->options[5].value.boolValue = false;
decorate();
}
void decorate()
{
Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM());
}
unsigned int getZonesCount() const override unsigned int getZonesCount() const override
{ {
return 2; return 2;
@@ -75,27 +48,17 @@ class Layout2x1: public Layout
rect_t getZone(unsigned int index) const override rect_t getZone(unsigned int index) const override
{ {
rect_t zone; rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border});
zone.w = (LCD_W-3*10) / 2;
zone.x = (index & 1) ? 20 + zone.w : 10; if (index == 0) {
if (persistentData->options[0].value.boolValue) { return {isMirrored() ? zone.x + zone.w / 2 : zone.x, zone.y, zone.w / 2, zone.h};
zone.h = (LCD_H-MENU_HEADER_HEIGHT-2*10);
zone.y = MENU_HEADER_HEIGHT + 10;
} }
else { else {
zone.h = (LCD_H-2*10); return {isMirrored() ? zone.x : zone.x + zone.w / 2, zone.y, zone.w / 2, zone.h};
zone.y = 10;
} }
return zone; return zone;
} }
void checkEvents() override
{
Layout::checkEvents();
decorate();
}
protected:
uint8_t value = 0;
}; };
BaseLayoutFactory<Layout2x1> Layout2x1("Layout2x1", "2 x 1", LBM_LAYOUT_2x1, OPTIONS_LAYOUT_2x1); BaseLayoutFactory<Layout2x1> Layout2x1("Layout2x1", "2 x 1", LBM_LAYOUT_2x1, OPTIONS_LAYOUT_2x1);
+14 -52
View File
@@ -22,23 +22,15 @@
#include "sliders.h" #include "sliders.h"
#include "trims.h" #include "trims.h"
#define HAS_TOPBAR() (persistentData->options[0].value.boolValue == true) constexpr coord_t border = 10;
#define HAS_FM() (persistentData->options[1].value.boolValue == true)
#define HAS_SLIDERS() (persistentData->options[2].value.boolValue == true)
#define HAS_TRIMS() (persistentData->options[3].value.boolValue == true)
#define IS_MIRRORED() (persistentData->options[4].value.boolValue == true)
const uint8_t LBM_LAYOUT_2x2[] = { const uint8_t LBM_LAYOUT_2x2[] = {
#include "mask_layout2x2.lbm" #include "mask_layout2x2.lbm"
}; };
const ZoneOption OPTIONS_LAYOUT_2x2[] = { const ZoneOption OPTIONS_LAYOUT_2x2[] = {
{ STR_TOP_BAR, ZoneOption::Bool }, LAYOUT_COMMON_OPTIONS,
{ STR_FLIGHT_MODE, ZoneOption::Bool }, LAYOUT_OPTIONS_END
{ STR_SLIDERS, ZoneOption::Bool },
{ STR_TRIMS, ZoneOption::Bool },
{ STR_MIRROR, ZoneOption::Bool },
{ nullptr, ZoneOption::Bool }
}; };
class Layout2x2: public Layout class Layout2x2: public Layout
@@ -47,24 +39,6 @@ class Layout2x2: public Layout
Layout2x2(const LayoutFactory * factory, Layout::PersistentData * persistentData): Layout2x2(const LayoutFactory * factory, Layout::PersistentData * persistentData):
Layout(factory, persistentData) Layout(factory, persistentData)
{ {
decorate();
}
void create() override
{
Layout::create();
persistentData->options[0].value.boolValue = true;
persistentData->options[1].value.boolValue = true;
persistentData->options[2].value.boolValue = true;
persistentData->options[3].value.boolValue = true;
persistentData->options[4].value.boolValue = false;
persistentData->options[5].value.boolValue = false;
decorate();
}
void decorate()
{
Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM());
} }
unsigned int getZonesCount() const override unsigned int getZonesCount() const override
@@ -74,31 +48,19 @@ class Layout2x2: public Layout
rect_t getZone(unsigned int index) const override rect_t getZone(unsigned int index) const override
{ {
rect_t zone; rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border});
zone.w = (LCD_W-3*10) / 2;
zone.x = (index & 1) ? 20 + zone.w : 10; zone.w /= 2;
if (persistentData->options[0].value.boolValue) { zone.h /= 2;
zone.h = (LCD_H-MENU_HEADER_HEIGHT-3*10) / 2;
zone.y = MENU_HEADER_HEIGHT + 10; if (index == 1 || index == 3)
} zone.y += zone.h;
else {
zone.h = (LCD_H-3*10) / 2; if ((!isMirrored() && index > 1) || (isMirrored() && index < 2))
zone.y = 10; zone.x += zone.w;
}
if (index >= 2) {
zone.y += 10 + zone.h;
}
return zone; return zone;
} }
void checkEvents() override
{
Layout::checkEvents();
decorate();
}
protected:
uint8_t value = 0;
}; };
BaseLayoutFactory<Layout2x2> layout2x2("Layout2x2", "2 x 2", LBM_LAYOUT_2x2, OPTIONS_LAYOUT_2x2); BaseLayoutFactory<Layout2x2> layout2x2("Layout2x2", "2 x 2", LBM_LAYOUT_2x2, OPTIONS_LAYOUT_2x2);
+27 -61
View File
@@ -20,25 +20,32 @@
#include "opentx.h" #include "opentx.h"
constexpr coord_t border = 10;
const uint8_t LBM_LAYOUT_2x4[] = { const uint8_t LBM_LAYOUT_2x4[] = {
#include "mask_layout2x4.lbm" #include "mask_layout2x4.lbm"
}; };
const ZoneOption OPTIONS_LAYOUT_2x4[] = { const ZoneOption OPTIONS_LAYOUT_2x4[] = {
{ "Top bar", ZoneOption::Bool }, LAYOUT_COMMON_OPTIONS,
{ "Flight mode", ZoneOption::Bool },
{ "Sliders", ZoneOption::Bool },
{ "Trims", ZoneOption::Bool },
{ "Panel1 background", ZoneOption::Bool }, { "Panel1 background", ZoneOption::Bool },
{ " Color", ZoneOption::Color }, { " Color", ZoneOption::Color },
{ "Panel2 background", ZoneOption::Bool }, { "Panel2 background", ZoneOption::Bool },
{ " Color", ZoneOption::Color }, { " Color", ZoneOption::Color },
{ nullptr, ZoneOption::Bool } LAYOUT_OPTIONS_END
}; };
class Layout2x4: public Layout class Layout2x4: public Layout
{ {
public: public:
enum {
OPTION_PANEL1_BACKGROUND = OPTION_LAST_DEFAULT + 1,
OPTION_PANEL1_COLOR,
OPTION_PANEL2_BACKGROUND,
OPTION_PANEL2_COLOR
};
Layout2x4(const LayoutFactory * factory, Layout::PersistentData * persistentData): Layout2x4(const LayoutFactory * factory, Layout::PersistentData * persistentData):
Layout(factory, persistentData) Layout(factory, persistentData)
{ {
@@ -47,14 +54,10 @@ class Layout2x4: public Layout
void create() override void create() override
{ {
Layout::create(); Layout::create();
persistentData->options[0] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) }; setOptionValue(OPTION_PANEL1_BACKGROUND, OPTION_VALUE_BOOL(true));
persistentData->options[1] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) }; setOptionValue(OPTION_PANEL1_COLOR, OPTION_VALUE_UNSIGNED( RGB(77,112,203)));
persistentData->options[2] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) }; setOptionValue(OPTION_PANEL2_BACKGROUND, OPTION_VALUE_BOOL(true));
persistentData->options[3] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) }; setOptionValue(OPTION_PANEL2_COLOR, OPTION_VALUE_UNSIGNED( RGB(77,112,203)));
persistentData->options[4] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
persistentData->options[5] = ZoneOptionValueTyped { ZOV_Unsigned, OPTION_VALUE_UNSIGNED( RGB(77,112,203)) };
persistentData->options[6] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
persistentData->options[7] = ZoneOptionValueTyped { ZOV_Unsigned, OPTION_VALUE_UNSIGNED( RGB(77,112,203)) };
} }
unsigned int getZonesCount() const override unsigned int getZonesCount() const override
@@ -64,56 +67,19 @@ class Layout2x4: public Layout
rect_t getZone(unsigned int index) const override rect_t getZone(unsigned int index) const override
{ {
rect_t zone; rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border});
zone.x = (index >= 4) ? 260 : 60;
zone.y = 56 + (index % 4) * 42; zone.w /= 2;
zone.w = 160; zone.h /= 4;
zone.h = 32;
if ((!isMirrored() && index > 3) || (isMirrored() && index < 4)) {
zone.x += zone.w;
}
zone.y += (index % 4) * zone.h;
return zone; return zone;
} }
// virtual void refresh();
}; };
//void Layout2x4::refresh()
//{
// theme->drawBackground();
//
// if (persistentData->options[0].value.boolValue) {
// drawTopBar();
// }
//
// if (persistentData->options[1].value.boolValue) {
// // Flight mode
// lcdDrawSizedText(LCD_W / 2 - getTextWidth(g_model.flightModeData[mixerCurrentFlightMode].name,
// sizeof(g_model.flightModeData[mixerCurrentFlightMode].name),
// ZCHAR | FONT(XS)) / 2,
// 232,
// g_model.flightModeData[mixerCurrentFlightMode].name,
// sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | FONT(XS));
// }
//
// if (persistentData->options[2].value.boolValue) {
// // Pots and rear sliders positions
// drawMainPots();
// }
//
// if (persistentData->options[3].value.boolValue) {
// // Trims
// drawTrims(mixerCurrentFlightMode);
// }
//
// if (persistentData->options[4].value.boolValue) {
// lcdSetColor(persistentData->options[5].value.unsignedValue);
// lcdDrawSolidFilledRect(50, 50, 180, 170, CUSTOM_COLOR);
// }
//
// if (persistentData->options[6].value.boolValue) {
// lcdSetColor(persistentData->options[7].value.unsignedValue);
// lcdDrawSolidFilledRect(250, 50, 180, 170, CUSTOM_COLOR);
// }
//
// Layout::refresh();
//}
BaseLayoutFactory<Layout2x4> layout2x4("Layout2x4", "2 x 4", LBM_LAYOUT_2x4, OPTIONS_LAYOUT_2x4); BaseLayoutFactory<Layout2x4> layout2x4("Layout2x4", "2 x 4", LBM_LAYOUT_2x4, OPTIONS_LAYOUT_2x4);
+2 -1
View File
@@ -32,9 +32,10 @@ void ScreenMenu::updateTabs()
{ {
removeAllTabs(); removeAllTabs();
addTab(new ScreenUserInterfacePage());
for (int index = 0; index < MAX_CUSTOM_SCREENS; index++) { for (int index = 0; index < MAX_CUSTOM_SCREENS; index++) {
if (customScreens[index]) { if (customScreens[index]) {
auto tab = new ScreenSetupPage(this, customScreens[index], g_model.screenData[index]); auto tab = new ScreenSetupPage(this, customScreens[index], g_model.screenData[index]);
std::string title(STR_MAIN_VIEW_X); std::string title(STR_MAIN_VIEW_X);
title.back() = index + '1'; title.back() = index + '1';
+44 -12
View File
@@ -26,6 +26,28 @@
#define SET_DIRTY() storageDirty(EE_MODEL) #define SET_DIRTY() storageDirty(EE_MODEL)
ScreenUserInterfacePage::ScreenUserInterfacePage():
PageTab(STR_USER_INTERFACE, ICON_THEME_SETUP)
{
}
void ScreenUserInterfacePage::build(FormWindow * window)
{
FormGridLayout grid;
// Theme choice
new StaticText(window, grid.getLabelSlot(), STR_THEME, 0, 0);
// TODO: Theme picklist
grid.nextLine();
// Theme options ?
// Top Bar
new StaticText(window, grid.getLabelSlot(), STR_TOP_BAR, 0, 0);
// TODO: enable settings topbar widgets
grid.nextLine();
}
ScreenAddPage::ScreenAddPage(ScreenMenu * menu, uint8_t pageIndex): ScreenAddPage::ScreenAddPage(ScreenMenu * menu, uint8_t pageIndex):
PageTab(), PageTab(),
menu(menu), menu(menu),
@@ -158,25 +180,35 @@ class SetupWidgetsPageSlot: public Button
{ {
widget = screen->getWidget(slotIndex); widget = screen->getWidget(slotIndex);
setPressHandler([=]() -> uint8_t { setPressHandler([=]() -> uint8_t {
Menu * menu = new Menu(this);
menu->addLine(TR_SELECT_WIDGET, [=]() {
Menu * menu = new Menu(this);
for (auto factory: getRegisteredWidgets()) {
menu->addLine(factory->getName(), [=]() {
if (widget) widget->deleteLater();
widget = screen->createWidget(slotIndex, factory);
});
}
});
if (widget) { if (widget) {
Menu * menu = new Menu(this);
menu->addLine(TR_SELECT_WIDGET, [=]() {
Menu * menu = new Menu(this);
for (auto factory: getRegisteredWidgets()) {
menu->addLine(factory->getName(), [=]() {
if (widget) widget->deleteLater();
widget = screen->createWidget(slotIndex, factory);
});
}
});
menu->addLine(TR_WIDGET_SETTINGS, [=]() { menu->addLine(TR_WIDGET_SETTINGS, [=]() {
new WidgetSettings(this, widget); new WidgetSettings(this, widget);
}); });
menu->addLine(STR_REMOVE_WIDGET, [=]() { menu->addLine(STR_REMOVE_WIDGET, [=]() {
widget->deleteLater(); widget->deleteLater();
widget = nullptr; widget = nullptr;
}); });
return 0;
}
else {
Menu * menu = new Menu(this);
for (auto factory: getRegisteredWidgets()) {
menu->addLine(factory->getName(), [=]() {
if (widget) widget->deleteLater();
widget = screen->createWidget(slotIndex, factory);
});
}
} }
return 0; return 0;
}); });
+9
View File
@@ -22,6 +22,15 @@
#include "layout.h" #include "layout.h"
#include "datastructs.h" #include "datastructs.h"
class ScreenUserInterfacePage: public PageTab {
public:
ScreenUserInterfacePage();
void build(FormWindow * window) override;
protected:
};
class ScreenAddPage: public PageTab { class ScreenAddPage: public PageTab {
public: public:
ScreenAddPage(ScreenMenu * menu, uint8_t pageIndex); ScreenAddPage(ScreenMenu * menu, uint8_t pageIndex);
+2 -2
View File
@@ -79,12 +79,12 @@ class OutputsWidget: public Widget
void twoColumns(BitmapBuffer * dc) void twoColumns(BitmapBuffer * dc)
{ {
uint8_t endColumn = drawChannels(dc, 0, 0, width() / 2, height(), uint8_t endColumn = drawChannels(dc, 0, 0, (width() / 2) - 1, height(),
persistentData->options[0].value.unsignedValue, persistentData->options[0].value.unsignedValue,
persistentData->options[1].value.boolValue, persistentData->options[1].value.boolValue,
persistentData->options[2].value.unsignedValue); persistentData->options[2].value.unsignedValue);
drawChannels(dc, width() / 2 + 2, 0, width() / 2, height(), endColumn + 1, drawChannels(dc, width() / 2, 0, (width() / 2) - 1, height(), endColumn + 1,
persistentData->options[1].value.boolValue, persistentData->options[1].value.boolValue,
persistentData->options[2].value.unsignedValue); persistentData->options[2].value.unsignedValue);
} }
@@ -104,6 +104,11 @@ class WidgetsContainer: public FormGroup, public WidgetsContainerInterface
return &persistentData->options[index].value; return &persistentData->options[index].value;
} }
inline void setOptionValue(unsigned int index, const ZoneOptionValue& value)
{
persistentData->options[index].value = value;
}
unsigned int getZonesCount() const override = 0; unsigned int getZonesCount() const override = 0;
rect_t getZone(unsigned int index) const override = 0; rect_t getZone(unsigned int index) const override = 0;