unify common layout settings

This commit is contained in:
Raphael Coeffic
2021-04-05 19:48:20 +02:00
parent da83e6b210
commit 179b86635c
7 changed files with 84 additions and 125 deletions
+28 -33
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
uint8_t checkSettings =
(topbar ? 1 << 0 : 0) |
(sliders ? 1 << 1 : 0) |
(trims ? 1 << 2 : 0) |
(flightMode ? 1 << 3 : 0);
(hasTopbar() ? 1 << 0 : 0) |
(hasSliders() ? 1 << 1 : 0) |
(hasTrims() ? 1 << 2 : 0) |
(hasFlightMode() ? 1 << 3 : 0);
if (checkSettings == decorationSettings) {
// everything ok, exit!
@@ -123,16 +123,16 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode)
// save settings
decorationSettings = checkSettings;
if (topbar) {
if (hasTopbar()) {
topBar = new TopBar(this);
topBar->load();
decorations.push_back(topBar);
}
if (sliders) {
if (hasSliders()) {
#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
decorations.push_back(
@@ -163,17 +163,17 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode)
#if defined(HARDWARE_EXT1)
if (IS_POT_SLIDER_AVAILABLE(EXT1)) {
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]; })
);
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]; })
);
}
else {
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]; })
);
}
@@ -182,33 +182,33 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode)
#if defined(HARDWARE_EXT2)
if (IS_POT_SLIDER_AVAILABLE(EXT2)) {
decorations.push_back(
new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE,
VERTICAL_SLIDERS_HEIGHT(topbar) / 2},
new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset, TRIM_SQUARE_SIZE,
VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2},
[=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_RIGHT]; })
);
decorations.push_back(
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]; })
);
}
else {
decorations.push_back(
new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE,
VERTICAL_SLIDERS_HEIGHT(topbar)},
new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset, TRIM_SQUARE_SIZE,
VERTICAL_SLIDERS_HEIGHT(hasTopbar())},
[=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_RIGHT]; })
);
}
#endif
}
if (trims) {
if (hasTrims()) {
#if defined(HARDWARE_POT3) || defined(HARDWARE_EXT1)
coord_t xOffset = sliders? TRIM_SQUARE_SIZE : 0;
coord_t xOffset = hasSliders() ? TRIM_SQUARE_SIZE : 0;
#else
coord_t xOffset = 0;
#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
@@ -226,20 +226,20 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode)
// Left
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); })
);
// Right
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); })
);
}
if (flightMode) {
if (hasFlightMode()) {
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;
}, CENTERED)
);
@@ -248,21 +248,16 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode)
rect_t Layout::getMainZone(rect_t zone) const
{
bool hasTopbar = getOptionValue(OPTION_TOPBAR)->boolValue;
bool hasFM = getOptionValue(OPTION_FM)->boolValue;
bool hasSliders = getOptionValue(OPTION_SLIDERS)->boolValue;
bool hasTrims = getOptionValue(OPTION_TRIMS)->boolValue;
if (hasTopbar) {
if (hasTopbar()) {
zone.y += MENU_HEADER_HEIGHT;
zone.h -= MENU_HEADER_HEIGHT;
}
if (hasFM || hasTrims) {
if (hasFlightMode() || hasTrims()) {
zone.h -= TRIM_SQUARE_SIZE;
}
if (hasSliders) {
if (hasSliders()) {
#if NUM_SLIDERS + NUM_POTS > 2
zone.h -= TRIM_SQUARE_SIZE;
#endif
@@ -270,7 +265,7 @@ rect_t Layout::getMainZone(rect_t zone) const
zone.x += TRIM_SQUARE_SIZE;
}
if (hasTrims) {
if (hasTrims()) {
zone.w -= 2 * TRIM_SQUARE_SIZE;
zone.x += TRIM_SQUARE_SIZE;
}
+43 -3
View File
@@ -32,7 +32,19 @@ constexpr coord_t TRIM_SQUARE_SIZE = 17;
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;
@@ -48,9 +60,10 @@ class Layout: public WidgetsContainer<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>
};
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)
{
decorate();
}
inline const LayoutFactory * getFactory() const
@@ -58,7 +71,31 @@ class Layout: public WidgetsContainer<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>
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:
const LayoutFactory * factory;
@@ -66,6 +103,9 @@ class Layout: public WidgetsContainer<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>
uint8_t decorationSettings = 0;
std::list<Window*> decorations;
// adds trims, sliders, pots, etc...
void decorate();
// get the Zone rect without decoration
rect_t getMainZone(rect_t zone) const;
};
+5 -21
View File
@@ -34,12 +34,8 @@ const uint8_t LBM_LAYOUT_1x1[] = {
};
const ZoneOption OPTIONS_LAYOUT_1x1[] = {
{ STR_TOP_BAR, ZoneOption::Bool },
{ STR_FLIGHT_MODE, ZoneOption::Bool },
{ STR_SLIDERS, ZoneOption::Bool },
{ STR_TRIMS, ZoneOption::Bool },
{ STR_MIRROR, ZoneOption::Bool },
{ nullptr, ZoneOption::Bool }
LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END
};
class Layout1x1: public Layout
@@ -48,27 +44,23 @@ class Layout1x1: public Layout
Layout1x1(const LayoutFactory * factory, Layout::PersistentData * persistentData):
Layout(factory, persistentData)
{
decorate();
}
void create() override
{
Layout::create();
// TODO: make this common to all layouts as well
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;
// TODO: really needed?
decorate();
}
void decorate()
{
Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM());
}
unsigned int getZonesCount() const override
{
return 1;
@@ -80,14 +72,6 @@ class Layout1x1: public Layout
return zone;
}
void checkEvents() override
{
Layout::checkEvents();
decorate();
}
protected:
uint8_t value = 0;
};
BaseLayoutFactory<Layout1x1> layout1x1("Layout1x1", "Fullscreen", LBM_LAYOUT_1x1, OPTIONS_LAYOUT_1x1);
+2 -21
View File
@@ -33,12 +33,8 @@ const uint8_t LBM_LAYOUT_2P1[] = {
};
const ZoneOption OPTIONS_LAYOUT_2P1[] = {
{ STR_TOP_BAR, ZoneOption::Bool },
{ STR_FLIGHT_MODE, ZoneOption::Bool },
{ STR_SLIDERS, ZoneOption::Bool },
{ STR_TRIMS, ZoneOption::Bool },
{ STR_MIRROR, ZoneOption::Bool },
{ nullptr, ZoneOption::Bool }
LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END
};
const rect_t ZONES_LAYOUT_2P1[3] = {
@@ -53,7 +49,6 @@ class Layout2P1: public Layout
Layout2P1(const LayoutFactory * factory, Layout::PersistentData * persistentData):
Layout(factory, persistentData)
{
decorate();
}
void create() override
@@ -68,11 +63,6 @@ class Layout2P1: public Layout
decorate();
}
void decorate()
{
Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM());
}
unsigned int getZonesCount() const override
{
return DIM(ZONES_LAYOUT_2P1);
@@ -82,15 +72,6 @@ class Layout2P1: public Layout
{
return ZONES_LAYOUT_2P1[index];
}
void checkEvents() override
{
Layout::checkEvents();
// TODO call this from the Layout config window
decorate();
}
protected:
uint8_t value = 0;
};
BaseLayoutFactory<Layout2P1> layout2P1("Layout2P1", "2 + 1", LBM_LAYOUT_2P1, OPTIONS_LAYOUT_2P1);
+2 -21
View File
@@ -33,12 +33,8 @@ const uint8_t LBM_LAYOUT_2x1[] = {
};
const ZoneOption OPTIONS_LAYOUT_2x1[] = {
{ STR_TOP_BAR, ZoneOption::Bool },
{ STR_FLIGHT_MODE, ZoneOption::Bool },
{ STR_SLIDERS, ZoneOption::Bool },
{ STR_TRIMS, ZoneOption::Bool },
{ STR_MIRROR, ZoneOption::Bool },
{ nullptr, ZoneOption::Bool }
LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END
};
class Layout2x1: public Layout
@@ -47,7 +43,6 @@ class Layout2x1: public Layout
Layout2x1(const LayoutFactory * factory, Layout::PersistentData * persistentData):
Layout(factory, persistentData)
{
decorate();
}
void create() override
@@ -62,12 +57,6 @@ class Layout2x1: public Layout
decorate();
}
void decorate()
{
Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM());
}
unsigned int getZonesCount() const override
{
return 2;
@@ -88,14 +77,6 @@ class Layout2x1: public Layout
}
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);
+2 -21
View File
@@ -33,12 +33,8 @@ const uint8_t LBM_LAYOUT_2x2[] = {
};
const ZoneOption OPTIONS_LAYOUT_2x2[] = {
{ STR_TOP_BAR, ZoneOption::Bool },
{ STR_FLIGHT_MODE, ZoneOption::Bool },
{ STR_SLIDERS, ZoneOption::Bool },
{ STR_TRIMS, ZoneOption::Bool },
{ STR_MIRROR, ZoneOption::Bool },
{ nullptr, ZoneOption::Bool }
LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END
};
class Layout2x2: public Layout
@@ -47,7 +43,6 @@ class Layout2x2: public Layout
Layout2x2(const LayoutFactory * factory, Layout::PersistentData * persistentData):
Layout(factory, persistentData)
{
decorate();
}
void create() override
@@ -62,11 +57,6 @@ class Layout2x2: public Layout
decorate();
}
void decorate()
{
Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM());
}
unsigned int getZonesCount() const override
{
return 4;
@@ -90,15 +80,6 @@ class Layout2x2: public Layout
}
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);
+2 -5
View File
@@ -25,15 +25,12 @@ const uint8_t LBM_LAYOUT_2x4[] = {
};
const ZoneOption OPTIONS_LAYOUT_2x4[] = {
{ "Top bar", ZoneOption::Bool },
{ "Flight mode", ZoneOption::Bool },
{ "Sliders", ZoneOption::Bool },
{ "Trims", ZoneOption::Bool },
LAYOUT_COMMON_OPTIONS,
{ "Panel1 background", ZoneOption::Bool },
{ " Color", ZoneOption::Color },
{ "Panel2 background", ZoneOption::Bool },
{ " Color", ZoneOption::Color },
{ nullptr, ZoneOption::Bool }
LAYOUT_OPTIONS_END
};
class Layout2x4: public Layout