feat(color): use dynamic memory allocation for screen & widget data (#6782)

This commit is contained in:
philmoz
2025-11-19 13:35:42 +10:00
committed by GitHub
parent 003fcacad0
commit 5c96b1e15c
96 changed files with 2512 additions and 1895 deletions
@@ -88,11 +88,6 @@ void GVarNumberEdit::switchGVarMode()
#endif
}
void GVarNumberEdit::setSuffix(std::string value)
{
num_field->setSuffix(value);
}
void GVarNumberEdit::onEvent(event_t event)
{
if (event == EVT_KEY_LONG(KEY_ENTER)) {
@@ -37,7 +37,6 @@ class GVarNumberEdit : public Window
LcdFlags textFlags = 0, int32_t voffset = 0, int32_t vdefault = 0);
void switchGVarMode();
void setSuffix(std::string value);
void setFastStep(int value) { num_field->setFastStep(value); }
void setAccelFactor(int value) { num_field->setAccelFactor(value); }
@@ -103,7 +103,7 @@ void SourceNumberEdit::switchSourceMode()
update();
}
void SourceNumberEdit::setSuffix(std::string value)
void SourceNumberEdit::setSuffix(const std::string& value)
{
num_field->setSuffix(value);
}
@@ -38,7 +38,7 @@ class SourceNumberEdit : public Window
int32_t vdefault = 0);
void switchSourceMode();
void setSuffix(std::string value);
void setSuffix(const std::string& value);
void setFastStep(int value) { num_field->setFastStep(value); }
void setAccelFactor(int value) { num_field->setAccelFactor(value); }
+1 -2
View File
@@ -20,7 +20,6 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
static const uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_FULL, LAYOUT_MAP_HALF,
@@ -29,5 +28,5 @@ static const uint8_t zmap[] = {
};
BaseLayoutFactory<Layout> Layout1P2("Layout1P2", "1 + 2",
defaultZoneOptions,
defaultLayoutOptions,
3, (uint8_t*)zmap);
+1 -2
View File
@@ -20,7 +20,6 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
static const uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_FULL,
@@ -30,5 +29,5 @@ static const uint8_t zmap[] = {
};
BaseLayoutFactory<Layout> Layout1P3("Layout1P3", "1 + 3",
defaultZoneOptions,
defaultLayoutOptions,
4, (uint8_t*)zmap);
+1 -2
View File
@@ -20,7 +20,6 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
static const uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_FULL,
@@ -30,5 +29,5 @@ static const uint8_t zmap[] = {
LAYOUT_MAP_HALF, LAYOUT_MAP_3QTR, LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR,
};
BaseLayoutFactory<Layout> Layout1P4("Layout1P4", "1 + 4", defaultZoneOptions, 5,
BaseLayoutFactory<Layout> Layout1P4("Layout1P4", "1 + 4", defaultLayoutOptions, 5,
(uint8_t*)zmap);
+2 -2
View File
@@ -20,12 +20,12 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
#include "translations/translations.h"
static const uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_FULL, LAYOUT_MAP_FULL,
};
BaseLayoutFactory<Layout> layout1x1("Layout1x1", STR_WIDGET_FULLSCREEN,
defaultZoneOptions,
defaultLayoutOptions,
1, (uint8_t*)zmap);
@@ -20,7 +20,6 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
const LayoutOption OPTIONS_LAYOUT_APPMODE[] = {LAYOUT_OPTIONS_END};
@@ -28,9 +27,9 @@ class LayoutAppMode : public Layout
{
public:
LayoutAppMode(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData, uint8_t zoneCount,
int screenNum, uint8_t zoneCount,
uint8_t* zoneMap) :
Layout(parent, factory, persistentData, zoneCount, zoneMap)
Layout(parent, factory, screenNum, zoneCount, zoneMap)
{
}
+1 -2
View File
@@ -20,7 +20,6 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
static const uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_FULL, LAYOUT_MAP_HALF,
@@ -28,5 +27,5 @@ static const uint8_t zmap[] = {
};
BaseLayoutFactory<Layout> Layout1x2("Layout1x2", "1 x 2",
defaultZoneOptions,
defaultLayoutOptions,
2, (uint8_t*)zmap);
+1 -2
View File
@@ -20,7 +20,6 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
static const uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_FULL, LAYOUT_MAP_1THIRD,
@@ -29,5 +28,5 @@ static const uint8_t zmap[] = {
};
BaseLayoutFactory<Layout> Layout1x3("Layout1x3", "1 x 3",
defaultZoneOptions,
defaultLayoutOptions,
3, (uint8_t*)zmap);
+1 -2
View File
@@ -20,7 +20,6 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
static const uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_FULL, LAYOUT_MAP_1QTR,
@@ -30,5 +29,5 @@ static const uint8_t zmap[] = {
};
BaseLayoutFactory<Layout> Layout1x4("Layout1x4", "1 x 4",
defaultZoneOptions,
defaultLayoutOptions,
4, (uint8_t*)zmap);
+1 -2
View File
@@ -20,7 +20,6 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
static const uint8_t zmap[] = {
LAYOUT_MAP_HALF, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_FULL, // ordered to match previous implementation
@@ -29,7 +28,7 @@ static const uint8_t zmap[] = {
};
BaseLayoutFactory<Layout> layout2P1("Layout2P1", "2 + 1",
defaultZoneOptions,
defaultLayoutOptions,
3, (uint8_t*)zmap);
const LayoutFactory* defaultLayout = &layout2P1;
+1 -2
View File
@@ -20,7 +20,6 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
static const uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF,
@@ -31,5 +30,5 @@ static const uint8_t zmap[] = {
};
BaseLayoutFactory<Layout> Layout2P3("Layout2P3", "2 + 3",
defaultZoneOptions,
defaultLayoutOptions,
5, (uint8_t*)zmap);
+1 -2
View File
@@ -20,7 +20,6 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
static const uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_FULL,
@@ -28,5 +27,5 @@ static const uint8_t zmap[] = {
};
BaseLayoutFactory<Layout> Layout2x1("Layout2x1", "2 x 1",
defaultZoneOptions,
defaultLayoutOptions,
2, (uint8_t*)zmap);
+1 -2
View File
@@ -20,7 +20,6 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
static const uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF,
@@ -30,5 +29,5 @@ static const uint8_t zmap[] = {
};
BaseLayoutFactory<Layout> layout2x2("Layout2x2", "2 x 2",
defaultZoneOptions,
defaultLayoutOptions,
4, (uint8_t*)zmap);
+1 -2
View File
@@ -20,7 +20,6 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
static const uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD,
@@ -32,5 +31,5 @@ static const uint8_t zmap[] = {
};
BaseLayoutFactory<Layout> layout2x3("Layout2x3", "2 x 3",
defaultZoneOptions,
defaultLayoutOptions,
6, (uint8_t*)zmap);
+7 -7
View File
@@ -20,14 +20,14 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
#include "translations/translations.h"
const LayoutOption OPTIONS_LAYOUT_2x4[] = {
LAYOUT_COMMON_OPTIONS,
{STR_DEF(STR_PANEL1_BACKGROUND), ZoneOption::Bool, OPTION_VALUE_BOOL(true)},
{STR_DEF(STR_PANEL_COLOR), ZoneOption::Color, RGB2FLAGS(77, 112, 203)},
{STR_DEF(STR_PANEL2_BACKGROUND), ZoneOption::Bool, OPTION_VALUE_BOOL(true)},
{STR_DEF(STR_PANEL_COLOR), ZoneOption::Color, RGB2FLAGS(77, 112, 203)},
{STR_DEF(STR_PANEL1_BACKGROUND), LayoutOption::Bool, true},
{STR_DEF(STR_PANEL_COLOR), LayoutOption::Color, RGB2FLAGS(77, 112, 203)},
{STR_DEF(STR_PANEL2_BACKGROUND), LayoutOption::Bool, true},
{STR_DEF(STR_PANEL_COLOR), LayoutOption::Color, RGB2FLAGS(77, 112, 203)},
LAYOUT_OPTIONS_END};
class Layout2x4 : public Layout
@@ -41,9 +41,9 @@ class Layout2x4 : public Layout
};
Layout2x4(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData, uint8_t zoneCount,
int screenNum, uint8_t zoneCount,
uint8_t* zoneMap) :
Layout(parent, factory, persistentData, zoneCount, zoneMap)
Layout(parent, factory, screenNum, zoneCount, zoneMap)
{
panel1 = lv_obj_create(lvobj);
lv_obj_set_style_bg_opa(panel1, LV_OPA_COVER, LV_PART_MAIN);
+1 -2
View File
@@ -20,7 +20,6 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
static const uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR,
@@ -32,5 +31,5 @@ static const uint8_t zmap[] = {
};
BaseLayoutFactory<Layout> layout4P2("Layout4P2", "4 + 2",
defaultZoneOptions,
defaultLayoutOptions,
6, (uint8_t*)zmap);
@@ -20,7 +20,6 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
static const uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR,
@@ -32,5 +31,5 @@ static const uint8_t zmap[] = {
};
BaseLayoutFactory<Layout> layout4P2B("Layout4P2B", "4 + 2B",
defaultZoneOptions,
defaultLayoutOptions,
6, (uint8_t*)zmap);
+7 -7
View File
@@ -20,17 +20,17 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
#include "translations/translations.h"
// 4x2 layout: 4 rows, 2 columns
// Suitable for portrait screens and vertical screen usage
const LayoutOption OPTIONS_LAYOUT_4x2[] = {
LAYOUT_COMMON_OPTIONS,
{STR_DEF(STR_PANEL1_BACKGROUND), ZoneOption::Bool, OPTION_VALUE_BOOL(true)},
{STR_DEF(STR_PANEL_COLOR), ZoneOption::Color, RGB2FLAGS(77, 112, 203)},
{STR_DEF(STR_PANEL2_BACKGROUND), ZoneOption::Bool, OPTION_VALUE_BOOL(true)},
{STR_DEF(STR_PANEL_COLOR), ZoneOption::Color, RGB2FLAGS(77, 112, 203)},
{STR_DEF(STR_PANEL1_BACKGROUND), LayoutOption::Bool, true},
{STR_DEF(STR_PANEL_COLOR), LayoutOption::Color, RGB2FLAGS(77, 112, 203)},
{STR_DEF(STR_PANEL2_BACKGROUND), LayoutOption::Bool, true},
{STR_DEF(STR_PANEL_COLOR), LayoutOption::Color, RGB2FLAGS(77, 112, 203)},
LAYOUT_OPTIONS_END};
class Layout4x2 : public Layout
@@ -44,9 +44,9 @@ class Layout4x2 : public Layout
};
Layout4x2(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData, uint8_t zoneCount,
int screenNum, uint8_t zoneCount,
uint8_t* zoneMap) :
Layout(parent, factory, persistentData, zoneCount, zoneMap)
Layout(parent, factory, screenNum, zoneCount, zoneMap)
{
panel1 = lv_obj_create(lvobj);
lv_obj_set_style_bg_opa(panel1, LV_OPA_COVER, LV_PART_MAIN);
+5 -5
View File
@@ -20,15 +20,15 @@
*/
#include "layout.h"
#include "layout_factory_impl.h"
#include "translations/translations.h"
// 6x1 layout: 6 rows, 1 column
// Single column with 6 vertical zones
const LayoutOption OPTIONS_LAYOUT_6x1[] = {
LAYOUT_COMMON_OPTIONS,
{STR_DEF(STR_PANEL_BACKGROUND), ZoneOption::Bool, OPTION_VALUE_BOOL(true)},
{STR_DEF(STR_PANEL_COLOR), ZoneOption::Color, RGB2FLAGS(50, 50, 50)},
{STR_DEF(STR_PANEL_BACKGROUND), LayoutOption::Bool, true},
{STR_DEF(STR_PANEL_COLOR), LayoutOption::Color, RGB2FLAGS(50, 50, 50)},
LAYOUT_OPTIONS_END};
class Layout6x1 : public Layout
@@ -40,9 +40,9 @@ class Layout6x1 : public Layout
};
Layout6x1(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData, uint8_t zoneCount,
int screenNum, uint8_t zoneCount,
uint8_t* zoneMap) :
Layout(parent, factory, persistentData, zoneCount, zoneMap)
Layout(parent, factory, screenNum, zoneCount, zoneMap)
{
panel = lv_obj_create(lvobj);
lv_obj_set_style_bg_opa(panel, LV_OPA_COVER, LV_PART_MAIN);
+3 -3
View File
@@ -50,19 +50,19 @@ class NumberEdit : public TextButton
void setAccelFactor(int value) { accelFactor = value; }
void setValue(int value);
void setPrefix(std::string value)
void setPrefix(const std::string& value)
{
prefix = std::move(value);
update();
}
void setSuffix(std::string value)
void setSuffix(const std::string& value)
{
suffix = std::move(value);
update();
}
void setZeroText(std::string value)
void setZeroText(const std::string& value)
{
zeroText = std::move(value);
update();
+12
View File
@@ -195,6 +195,18 @@ ModelTextEdit::ModelTextEdit(Window* parent, const rect_t& rect, char* value,
{
}
ModelStringEdit::ModelStringEdit(Window* parent, const rect_t& rect, std::string value,
std::function<void(const char* s)> updateHandler) :
TextEdit(parent, rect, txt, MAX_STR_EDIT_LEN,
[=]() {
if (updateHandler) updateHandler(txt);
storageDirty(EE_MODEL);
})
{
strncpy(txt, value.c_str(), length);
update();
}
RadioTextEdit::RadioTextEdit(Window* parent, const rect_t& rect, char* value,
uint8_t length) :
TextEdit(parent, rect, value, length,
+12
View File
@@ -52,6 +52,18 @@ class ModelTextEdit : public TextEdit
uint8_t length, std::function<void(void)> updateHandler = nullptr);
};
class ModelStringEdit : public TextEdit
{
public:
ModelStringEdit(Window* parent, const rect_t& rect, std::string value,
std::function<void(const char* s)> updateHandler);
static constexpr int MAX_STR_EDIT_LEN = 255;
protected:
char txt[MAX_STR_EDIT_LEN+1];
};
class RadioTextEdit : public TextEdit
{
public:
@@ -0,0 +1,213 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#if !defined(BACKUP)
#include <vector>
#include <string>
#endif
#include "etx_lv_theme.h"
struct WidgetOption;
//-----------------------------------------------------------------------------
enum WidgetOptionAlign
{
ALIGN_LEFT,
ALIGN_CENTER,
ALIGN_RIGHT,
// this one MUST be last
ALIGN_COUNT
};
enum WidgetOptionValueEnum {
WOV_Unsigned=0,
WOV_Signed,
WOV_Bool,
WOV_String,
WOV_Source,
WOV_Color
};
#define WIDGET_OPTION_VALUE_SIGNED(x) WidgetOptionValue{ .signedValue = (x) }
#define WIDGET_OPTION_VALUE_STRING(...) WidgetOptionValue{ .stringValue = { __VA_ARGS__ } }
struct WidgetOptionValue
{
#if defined(YAML_GENERATOR)
CUST_ATTR(unsignedValue, r_wov_unsigned, w_wov_unsigned);
CUST_ATTR(signedValue, r_wov_signed, w_wov_signed);
CUST_ATTR(boolValue, r_wov_unsigned, w_wov_unsigned);
CUST_ATTR(stringValue, r_wov_string, w_wov_string);
CUST_ATTR(source, r_wov_source, w_wov_source);
CUST_ATTR(color, r_wov_color, w_wov_color);
#else
union {
uint32_t unsignedValue;
int32_t signedValue;
uint32_t boolValue;
};
#if !defined(BACKUP)
std::string stringValue;
#endif
#endif
};
struct WidgetOptionValueTyped
{
#if defined(YAML_GENERATOR)
CUST_ATTR(type, r_wov_type, w_wov_type);
#else
WidgetOptionValueEnum type;
#endif
WidgetOptionValue value FUNC(select_wov);
};
//-----------------------------------------------------------------------------
#define MAX_WIDGET_OPTIONS 50 // For YAML parser
struct WidgetPersistentData {
#if defined(YAML_GENERATOR)
WidgetOptionValueTyped options[MAX_WIDGET_OPTIONS] FUNC(widget_option_is_active);
#else
#if !defined(BACKUP)
std::vector<WidgetOptionValueTyped> options;
void addEntry(int idx);
bool hasOption(int idx);
void setDefault(int idx, const WidgetOption* opt, bool forced);
void clear();
WidgetOptionValueEnum getType(int idx);
void setType(int idx, WidgetOptionValueEnum typ);
int32_t getSignedValue(int idx);
void setSignedValue(int idx, int32_t newValue);
uint32_t getUnsignedValue(int idx);
void setUnsignedValue(int idx, uint32_t newValue);
bool getBoolValue(int idx);
void setBoolValue(int idx, bool newValue);
std::string getString(int idx);
void setString(int idx, const char* s);
#endif
#endif
};
//-----------------------------------------------------------------------------
enum LayoutOptionValueEnum {
LOV_None=0,
LOV_Bool,
LOV_Color
};
union LayoutOptionValue
{
#if defined(YAML_GENERATOR)
CUST_ATTR(unsignedValue, r_lov_unsigned, w_lov_unsigned);
CUST_ATTR(boolValue, r_lov_unsigned, w_lov_unsigned);
CUST_ATTR(color, r_lov_color, w_lov_color);
#else
uint32_t unsignedValue;
uint32_t boolValue;
#endif
};
struct LayoutOptionValueTyped
{
#if defined(YAML_GENERATOR)
CUST_ATTR(type, r_lov_type, w_lov_type);
#else
LayoutOptionValueEnum type;
#endif
LayoutOptionValue value FUNC(select_lov);
};
#define MAX_LAYOUT_ZONES 10
#define MAX_LAYOUT_OPTIONS 10
struct ZonePersistentData {
#if defined(YAML_GENERATOR)
CUST_ATTR(widgetName, r_widget_name, w_widget_name);
#else
#if !defined(BACKUP)
std::string widgetName;
#endif
#endif
WidgetPersistentData widgetData FUNC(isAlwaysActive);
#if !defined(YAML_GENERATOR)
void clear();
#endif
};
struct LayoutPersistentData {
ZonePersistentData zones[MAX_LAYOUT_ZONES] FUNC(widget_is_active);
LayoutOptionValueTyped options[MAX_LAYOUT_OPTIONS] FUNC(layout_option_is_active);
#if !defined(YAML_GENERATOR)
void clearZone(int idx);
void clear();
const char* getWidgetName(int idx);
void setWidgetName(int idx, const char* s);
WidgetPersistentData* getWidgetData(int idx);
bool hasWidget(int idx);
#endif
};
//-----------------------------------------------------------------------------
struct CustomScreenData {
#if defined(YAML_GENERATOR)
CUST_ATTR(LayoutId, r_screen_id, w_screen_id);
#else
#if !defined(BACKUP)
std::string LayoutId;
#endif
#endif
LayoutPersistentData layoutData FUNC(isAlwaysActive);
};
//-----------------------------------------------------------------------------
static LAYOUT_VAL_SCALED(MENU_HEADER_BUTTONS_LEFT, 47)
#if LCD_W == 800 // TODO: handle this better
static constexpr int TOPBAR_ZONE_WIDTH = 102;
#else
static LAYOUT_VAL_SCALED(TOPBAR_ZONE_WIDTH, 70)
#endif
static constexpr int MAX_TOPBAR_ZONES = (LCD_W - MENU_HEADER_BUTTONS_LEFT - 1 + TOPBAR_ZONE_WIDTH / 2) / TOPBAR_ZONE_WIDTH;
struct TopBarPersistentData {
ZonePersistentData zones[MAX_TOPBAR_ZONES] FUNC(widget_is_active);
#if !defined(YAML_GENERATOR)
void clearZone(int idx);
void clear();
const char* getWidgetName(int idx);
void setWidgetName(int idx, const char* s);
WidgetPersistentData* getWidgetData(int idx);
bool hasWidget(int idx);
bool isWidget(int idx, const char* s);
#endif
};
//-----------------------------------------------------------------------------
+307 -33
View File
@@ -20,11 +20,60 @@
*/
#include "edgetx.h"
#include "topbar_impl.h"
#include "topbar.h"
#include "view_main.h"
#include "widget.h"
WidgetsContainer* customScreens[MAX_CUSTOM_SCREENS] = {};
const LayoutOption defaultLayoutOptions[] = {LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END};
//-----------------------------------------------------------------------------
void ZonePersistentData::clear()
{
widgetName[0] = 0;
widgetData.clear();
}
void LayoutPersistentData::clearZone(int idx)
{
zones[idx].clear();
}
void LayoutPersistentData::clear()
{
for (int i = 0; i < MAX_LAYOUT_ZONES; i += 1)
clearZone(i);
for (int i = 0; i < MAX_LAYOUT_OPTIONS; i += 1) {
options[i].type = LOV_None;
options[i].value.unsignedValue = 0;
}
}
const char* LayoutPersistentData::getWidgetName(int idx)
{
return zones[idx].widgetName.c_str();
}
void LayoutPersistentData::setWidgetName(int idx, const char* s)
{
zones[idx].widgetName = s;
}
WidgetPersistentData* LayoutPersistentData::getWidgetData(int idx)
{
return &zones[idx].widgetData;
}
bool LayoutPersistentData::hasWidget(int idx)
{
return zones[idx].widgetName[0] != 0;
}
//-----------------------------------------------------------------------------
std::list<const LayoutFactory*>& LayoutFactory::getRegisteredLayouts()
{
static std::list<const LayoutFactory*> layouts;
@@ -46,11 +95,11 @@ const LayoutFactory* LayoutFactory::getLayoutFactory(const char* name)
// Loads a layout, but does not attach it to any window
//
WidgetsContainer* LayoutFactory::loadLayout(
Window* parent, const char* name, LayoutPersistentData* persistentData)
Window* parent, int screenNum)
{
const LayoutFactory* factory = getLayoutFactory(name);
const LayoutFactory* factory = getLayoutFactory(g_model.getScreenLayoutId(screenNum));
if (factory) {
return factory->load(parent, persistentData);
return factory->load(parent, screenNum);
}
return nullptr;
}
@@ -74,13 +123,12 @@ void LayoutFactory::deleteCustomScreens(bool clearTopBar)
void LayoutFactory::loadDefaultLayout()
{
auto& screen = customScreens[0];
auto& screenData = g_model.screenData[0];
if (screen == nullptr && defaultLayout != nullptr) {
strcpy(screenData.LayoutId, defaultLayout->getId());
g_model.setScreenLayoutId(0, defaultLayout->getId());
auto viewMain = ViewMain::instance();
screen = defaultLayout->create(viewMain, &screenData.layoutData);
screen = defaultLayout->create(viewMain, 0);
//
// TODO:
// -> attach a few default widgets
@@ -103,8 +151,7 @@ void LayoutFactory::loadCustomScreens()
while (i < MAX_CUSTOM_SCREENS) {
auto& screen = customScreens[i];
screen = loadLayout(viewMain, g_model.screenData[i].LayoutId,
&g_model.screenData[i].layoutData);
screen = loadLayout(viewMain, i);
if (!screen) {
// no more layouts
@@ -145,7 +192,6 @@ WidgetsContainer* LayoutFactory::createCustomScreen(
if (customScreenIndex >= MAX_CUSTOM_SCREENS) return nullptr;
auto& screen = customScreens[customScreenIndex];
auto& screenData = g_model.screenData[customScreenIndex];
if (screen != nullptr) {
screen->deleteLater(true, false);
@@ -153,37 +199,265 @@ WidgetsContainer* LayoutFactory::createCustomScreen(
}
auto viewMain = ViewMain::instance();
screen = create(viewMain, &screenData.layoutData);
screen = create(viewMain, customScreenIndex);
if (!screen) return nullptr;
viewMain->addMainView(screen, customScreenIndex);
auto dst = g_model.screenData[customScreenIndex].LayoutId;
auto src = getId();
strncpy(dst, src, sizeof(CustomScreenData::LayoutId));
g_model.setScreenLayoutId(customScreenIndex, getId());
return screen;
}
void LayoutFactory::disposeCustomScreen(unsigned idx)
{
// move custom screen data
if (idx >= MAX_CUSTOM_SCREENS) {
return;
}
auto dst = &g_model.screenData[idx];
auto src = dst + 1;
auto len = sizeof(CustomScreenData) * (MAX_CUSTOM_SCREENS - idx - 1);
memmove(dst, src, len);
dst = &g_model.screenData[MAX_CUSTOM_SCREENS - 1];
len = sizeof(CustomScreenData);
memset(dst, 0, len);
}
LayoutFactory::LayoutFactory(const char* id, const char* name) :
id(id), name(name)
LayoutFactory::LayoutFactory(const char* id, const char* name, const LayoutOption * options, uint8_t zoneCount, uint8_t* zoneMap) :
id(id), name(name), options(options), zoneCount(zoneCount), zoneMap(zoneMap)
{
getRegisteredLayouts().push_back(this);
bitmap = (MaskBitmap*)malloc(align32(BM_W * BM_H + sizeof(MaskBitmap)));
bitmap->width = BM_W;
bitmap->height = BM_H;
uint8_t* bm = (uint8_t*)bitmap->data;
memset(bm, 0, BM_W * BM_H);
memset(bm, 0xFF, BM_W);
memset(bm+((BM_H-1)*BM_W), 0xFF, BM_W);
for (int y = 1; y < BM_H - 1; y += 1) {
bm[y*BM_W] = 0xFF;
bm[y*BM_W+BM_W-1] = 0xFF;
}
for (int i = 0; i < zoneCount * 4; i += 4) {
uint8_t xo = BM_W * zoneMap[i] / LAYOUT_MAP_DIV;
uint8_t yo = BM_H * zoneMap[i+1] / LAYOUT_MAP_DIV;
uint8_t w = BM_W * zoneMap[i+2] / LAYOUT_MAP_DIV;
uint8_t h = (BM_H * zoneMap[i+3] + LAYOUT_MAP_DIV/2) / LAYOUT_MAP_DIV;
if (yo > 0)
memset(bm+(yo*BM_W+xo), 0xFF, w);
if (xo > 0) {
for (int y = 0; y < h; y += 1) {
bm[(yo+y)*BM_W+xo] = 0xFF;
}
}
}
}
LayoutFactory::~LayoutFactory()
{
if (bitmap) {
free((void*)bitmap);
bitmap = nullptr;
}
}
inline LayoutOptionValueEnum layoutValueEnumFromType(LayoutOption::Type type)
{
switch(type) {
case LayoutOption::Bool:
return LOV_Bool;
case LayoutOption::Color:
return LOV_Color;
default:
return LOV_None;
}
}
void LayoutFactory::initPersistentData(int screenNum, bool setDefault) const
{
auto layoutData = g_model.getScreenLayoutData(screenNum);
if (setDefault) {
layoutData->clear();
}
if (options) {
int i = 0;
for (const LayoutOption* option = options; option->name; option++, i++) {
// TODO compiler bug? The CPU freezes ... persistentData->options[i++]
// = option->deflt;
auto optVal = &layoutData->options[i];
if (setDefault) {
memcpy(&optVal->value, &option->deflt, sizeof(LayoutOptionValue));
}
optVal->type = layoutValueEnumFromType(option->type);
}
}
}
WidgetsContainer* LayoutFactory::create(Window* parent, int screenNum) const
{
initPersistentData(screenNum, true);
return createNew(parent, screenNum);
}
WidgetsContainer* LayoutFactory::load(Window* parent, int screenNum) const
{
initPersistentData(screenNum, false);
Layout* layout = createNew(parent, screenNum);
if (layout)
layout->load();
return layout;
}
//-----------------------------------------------------------------------------
Layout::Layout(Window* parent, const LayoutFactory* factory,
int screenNum, uint8_t zoneCount,
uint8_t* zoneMap) :
WidgetsContainer(parent, {0, 0, LCD_W, LCD_H}, zoneCount),
factory(factory),
decoration(new ViewMainDecoration(this)),
zoneMap(zoneMap), screenNum(screenNum)
{
setWindowFlag(NO_FOCUS);
show(true);
}
void Layout::setTrimsVisible(bool visible)
{
decoration->setTrimsVisible(visible);
}
void Layout::setSlidersVisible(bool visible)
{
decoration->setSlidersVisible(visible);
}
void Layout::setFlightModeVisible(bool visible)
{
decoration->setFlightModeVisible(visible);
}
void Layout::show(bool visible)
{
// Set visible decoration
setSlidersVisible(visible && hasSliders());
setTrimsVisible(visible && hasTrims());
setFlightModeVisible(visible && hasFlightMode());
if (visible) {
// and update relevant windows
updateZones();
}
}
rect_t Layout::getMainZone() const
{
rect_t zone = decoration->getMainZone();
if (hasSliders() || hasTrims() || hasFlightMode()) {
// some decoration activated
zone.x += PAD_LARGE;
zone.y += PAD_LARGE;
zone.w -= 2 * PAD_LARGE;
zone.h -= 2 * PAD_LARGE;
}
return ViewMain::instance()->getMainZone(zone, hasTopbar());
}
rect_t Layout::getZone(unsigned int index) const
{
rect_t z = getMainZone();
unsigned int i = index * 4;
coord_t xo = z.w * zoneMap[i] / LAYOUT_MAP_DIV;
coord_t yo = z.h * zoneMap[i + 1] / LAYOUT_MAP_DIV;
coord_t w = z.w * zoneMap[i + 2] / LAYOUT_MAP_DIV;
coord_t h = z.h * zoneMap[i + 3] / LAYOUT_MAP_DIV;
if (isMirrored()) xo = z.w - xo - w;
return {z.x + xo, z.y + yo, w, h};
}
void Layout::checkEvents()
{
Window::checkEvents();
rect_t z = getMainZone();
if (z.x != lastMainZone.x || z.y != lastMainZone.y || z.w != lastMainZone.w || z.h != lastMainZone.h) {
lastMainZone = z;
for (int i = 0; i < zoneCount; i++)
if (widgets[i] && widgets[i]->isFullscreen())
return;
updateZones();
}
}
void Layout::removeWidget(unsigned int index)
{
if (index >= zoneCount) return;
g_model.getScreenLayoutData(screenNum)->clearZone(index);
WidgetsContainer::removeWidget(index);
}
Widget* Layout::createWidget(unsigned int index,
const WidgetFactory* factory)
{
if (index >= zoneCount) return nullptr;
// remove old one if existing
removeWidget(index);
Widget* widget = nullptr;
if (factory) {
g_model.getScreenLayoutData(screenNum)->setWidgetName(index, factory->getName());
widget = factory->create(this, getZone(index), screenNum, index);
}
widgets[index] = widget;
if (widget) widget->attach(this);
return widget;
}
void Layout::load()
{
unsigned int count = getZonesCount();
for (unsigned int i = 0; i < count; i++) {
// remove old widget
if (widgets[i]) {
widgets[i]->deleteLater();
widgets[i] = nullptr;
}
}
for (unsigned int i = 0; i < count; i++) {
// and load new one if required
if (g_model.getScreenLayoutData(screenNum)->hasWidget(i)) {
widgets[i] = WidgetFactory::newWidget(g_model.getScreenLayoutData(screenNum)->getWidgetName(i), this, getZone(i), screenNum, i);
}
}
}
LayoutOptionValue* Layout::getOptionValue(unsigned int index) const
{
return &g_model.getScreenLayoutData(screenNum)->options[index].value;
}
bool Layout::hasTopbar() const {
return getOptionValue(LAYOUT_OPTION_TOPBAR)->boolValue;
}
bool Layout::hasFlightMode() const {
return getOptionValue(LAYOUT_OPTION_FM)->boolValue;
}
bool Layout::hasSliders() const {
return getOptionValue(LAYOUT_OPTION_SLIDERS)->boolValue;
}
bool Layout::hasTrims() const {
return getOptionValue(LAYOUT_OPTION_TRIMS)->boolValue;
}
bool Layout::isMirrored() const {
return getOptionValue(LAYOUT_OPTION_MIRRORED)->boolValue;
}
//-----------------------------------------------------------------------------
+150 -28
View File
@@ -21,55 +21,154 @@
#pragma once
#include <list>
#include "definitions.h"
#include "dataconstants.h"
#include "widgets_container.h"
#include "widget.h"
#include "view_main_decoration.h"
#include <memory>
class LayoutFactory;
//-----------------------------------------------------------------------------
struct LayoutOption
{
enum Type {
Integer,
Bool,
Color,
};
STR_TYP name;
ZoneOption::Type type;
ZoneOptionValue deflt;
LayoutOption::Type type;
LayoutOptionValue deflt;
};
#define MAX_LAYOUT_ZONES 10
#define MAX_LAYOUT_OPTIONS 10
// Common 'LayoutOptionValue's among all layouts
enum {
LAYOUT_OPTION_TOPBAR = 0,
LAYOUT_OPTION_FM,
LAYOUT_OPTION_SLIDERS,
LAYOUT_OPTION_TRIMS,
LAYOUT_OPTION_MIRRORED,
#if !defined(YAML_GENERATOR)
typedef WidgetsContainerPersistentData<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>
LayoutPersistentData;
#else
struct LayoutPersistentData {
ZonePersistentData zones[MAX_LAYOUT_ZONES];
ZoneOptionValueTyped options[MAX_LAYOUT_OPTIONS];
LAYOUT_OPTION_LAST_DEFAULT=LAYOUT_OPTION_MIRRORED
};
#define LAYOUT_COMMON_OPTIONS \
{STR_DEF(STR_TOP_BAR), LayoutOption::Bool, true}, \
{STR_DEF(STR_FLIGHT_MODE), LayoutOption::Bool, true}, \
{STR_DEF(STR_SLIDERS), LayoutOption::Bool, true}, \
{STR_DEF(STR_TRIMS), LayoutOption::Bool, true}, \
{STR_DEF(STR_MIRROR), LayoutOption::Bool, false}
#define LAYOUT_OPTIONS_END \
{ nullptr, LayoutOption::Bool }
extern const LayoutOption defaultLayoutOptions[];
//-----------------------------------------------------------------------------
#define LAYOUT_MAP_DIV 60
#define LAYOUT_MAP_0 0
#define LAYOUT_MAP_1QTR 15
#define LAYOUT_MAP_1THIRD 20
#define LAYOUT_MAP_HALF 30
#define LAYOUT_MAP_2THIRD 40
#define LAYOUT_MAP_3QTR 45
#define LAYOUT_MAP_FULL 60
//-----------------------------------------------------------------------------
class Layout: public WidgetsContainer
{
friend class LayoutFactory;
public:
Layout(Window* parent, const LayoutFactory * factory,
int screenNum, uint8_t zoneCount, uint8_t* zoneMap);
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "Layout";
}
#endif
Widget* createWidget(unsigned int index,
const WidgetFactory* factory) override;
void load();
LayoutOptionValue* getOptionValue(unsigned int index) const;
const LayoutFactory * getFactory() const
{
return factory;
}
virtual bool hasTopbar() const;
virtual bool hasFlightMode() const;
virtual bool hasSliders() const;
virtual bool hasTrims() const;
virtual bool isMirrored() const;
// Set decoration visibility
void setTrimsVisible(bool visible);
void setSlidersVisible(bool visible);
void setFlightModeVisible(bool visible);
// Updates settings for trims, sliders, pots, etc...
void show(bool visible = true) override;
bool isLayout() override { return true; }
void removeWidget(unsigned int index) override;
protected:
const LayoutFactory * factory = nullptr;
std::unique_ptr<ViewMainDecoration> decoration;
uint8_t* zoneMap = nullptr;
int screenNum;
rect_t lastMainZone = {0,0,0,0};
// Last time we refreshed the window
uint32_t lastRefresh = 0;
// Get the available space for widgets
rect_t getMainZone() const;
unsigned int getZonesCount() const override { return zoneCount; }
rect_t getZone(unsigned int index) const override;
void checkEvents() override;
};
//-----------------------------------------------------------------------------
class LayoutFactory
{
public:
LayoutFactory(const char* id, const char* name);
LayoutFactory(const char* id, const char* name, const LayoutOption * options, uint8_t zoneCount, uint8_t* zoneMap);
~LayoutFactory();
const char* getId() const { return id; }
const char* getName() const { return name; }
virtual const MaskBitmap* getBitmap() const = 0;
const MaskBitmap* getBitmap() const { return bitmap; }
virtual const LayoutOption* getLayoutOptions() const = 0;
const LayoutOption * getLayoutOptions() const
{
return options;
}
virtual WidgetsContainer* create(
Window* parent, LayoutPersistentData* persistentData) const = 0;
virtual Layout* createNew(Window* parent, int screenNum) const = 0;
virtual WidgetsContainer* load(
Window* parent, LayoutPersistentData* persistentData) const = 0;
WidgetsContainer* create(Window* parent, int screenNum) const;
WidgetsContainer* load(Window* parent, int screenNum) const;
virtual void initPersistentData(LayoutPersistentData* persistentData,
bool setDefault) const = 0;
// Remove custom screen from the model
static void disposeCustomScreen(unsigned idx);
void initPersistentData(int screenNum, bool setDefault) const;
// delete all custom screens from memory
static void deleteCustomScreens(bool clearTopBar = false);
@@ -91,12 +190,35 @@ class LayoutFactory
protected:
const char* id;
const char* name;
const LayoutOption * options;
uint8_t zoneCount;
uint8_t* zoneMap;
MaskBitmap * bitmap = nullptr;
static WidgetsContainer* loadLayout(Window* parent, const char* name,
LayoutPersistentData* persistentData);
static WidgetsContainer* loadLayout(Window* parent, int screenNum);
static const LayoutFactory* getLayoutFactory(const char* name);
};
//-----------------------------------------------------------------------------
template<class T>
class BaseLayoutFactory: public LayoutFactory
{
public:
BaseLayoutFactory(const char * id, const char * name,
const LayoutOption * options, uint8_t zoneCount, uint8_t* zoneMap) :
LayoutFactory(id, name, options, zoneCount, zoneMap)
{
}
Layout* createNew(Window* parent, int screenNum) const override
{
return new T(parent, this, screenNum, zoneCount, zoneMap);
}
};
extern const LayoutFactory* defaultLayout;
extern WidgetsContainer* customScreens[MAX_CUSTOM_SCREENS];
//-----------------------------------------------------------------------------
@@ -1,112 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "layout_factory_impl.h"
#include "edgetx.h"
#include "sliders.h"
#include "trims.h"
#include "view_main.h"
Layout::Layout(Window* parent, const LayoutFactory* factory,
PersistentData* persistentData, uint8_t zoneCount,
uint8_t* zoneMap) :
LayoutBase(parent, {0, 0, LCD_W, LCD_H}, persistentData),
factory(factory),
decoration(new ViewMainDecoration(this)),
zoneCount(zoneCount),
zoneMap(zoneMap)
{
show(true);
}
void Layout::setTrimsVisible(bool visible)
{
decoration->setTrimsVisible(visible);
}
void Layout::setSlidersVisible(bool visible)
{
decoration->setSlidersVisible(visible);
}
void Layout::setFlightModeVisible(bool visible)
{
decoration->setFlightModeVisible(visible);
}
void Layout::show(bool visible)
{
// Set visible decoration
setSlidersVisible(visible && hasSliders());
setTrimsVisible(visible && hasTrims());
setFlightModeVisible(visible && hasFlightMode());
if (visible) {
// and update relevant windows
updateZones();
}
}
rect_t Layout::getMainZone() const
{
rect_t zone = decoration->getMainZone();
if (hasSliders() || hasTrims() || hasFlightMode()) {
// some decoration activated
zone.x += PAD_LARGE;
zone.y += PAD_LARGE;
zone.w -= 2 * PAD_LARGE;
zone.h -= 2 * PAD_LARGE;
}
return ViewMain::instance()->getMainZone(zone, hasTopbar());
}
rect_t Layout::getZone(unsigned int index) const
{
rect_t z = getMainZone();
unsigned int i = index * 4;
coord_t xo = z.w * zoneMap[i] / LAYOUT_MAP_DIV;
coord_t yo = z.h * zoneMap[i + 1] / LAYOUT_MAP_DIV;
coord_t w = z.w * zoneMap[i + 2] / LAYOUT_MAP_DIV;
coord_t h = z.h * zoneMap[i + 3] / LAYOUT_MAP_DIV;
if (isMirrored()) xo = z.w - xo - w;
return {z.x + xo, z.y + yo, w, h};
}
void Layout::checkEvents()
{
Window::checkEvents();
rect_t z = getMainZone();
if (z.x != lastMainZone.x || z.y != lastMainZone.y || z.w != lastMainZone.w || z.h != lastMainZone.h) {
lastMainZone = z;
for (int i = 0; i < MAX_LAYOUT_ZONES; i++)
if (widgets[i] && widgets[i]->isFullscreen())
return;
updateZones();
}
}
const LayoutOption defaultZoneOptions[] = {LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END};
@@ -1,234 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include <list>
#include "audio.h"
#include "translations/translations.h"
#include "widgets_container_impl.h"
#include "view_main_decoration.h"
#include "layout.h"
#include <memory>
#define LAYOUT_COMMON_OPTIONS \
{STR_DEF(STR_TOP_BAR), ZoneOption::Bool, OPTION_VALUE_BOOL(true)}, \
{STR_DEF(STR_FLIGHT_MODE), ZoneOption::Bool, OPTION_VALUE_BOOL(true)}, \
{STR_DEF(STR_SLIDERS), ZoneOption::Bool, OPTION_VALUE_BOOL(true)}, \
{STR_DEF(STR_TRIMS), ZoneOption::Bool, OPTION_VALUE_BOOL(true)}, \
{STR_DEF(STR_MIRROR), ZoneOption::Bool, OPTION_VALUE_BOOL(false)}
#define LAYOUT_OPTIONS_END \
{ nullptr, ZoneOption::Bool }
typedef WidgetsContainerImpl<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS> LayoutBase;
extern const LayoutOption defaultZoneOptions[];
#define LAYOUT_MAP_DIV 60
#define LAYOUT_MAP_0 0
#define LAYOUT_MAP_1QTR 15
#define LAYOUT_MAP_1THIRD 20
#define LAYOUT_MAP_HALF 30
#define LAYOUT_MAP_2THIRD 40
#define LAYOUT_MAP_3QTR 45
#define LAYOUT_MAP_FULL 60
class Layout: public LayoutBase
{
friend class LayoutFactory;
public:
Layout(Window* parent, const LayoutFactory * factory, PersistentData * persistentData,
uint8_t zoneCount, uint8_t* zoneMap);
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "Layout";
}
#endif
void create() override {}
const LayoutFactory * getFactory() const
{
return factory;
}
virtual bool hasTopbar() const {
return getOptionValue(LAYOUT_OPTION_TOPBAR)->boolValue;
}
virtual bool hasFlightMode() const {
return getOptionValue(LAYOUT_OPTION_FM)->boolValue;
}
virtual bool hasSliders() const {
return getOptionValue(LAYOUT_OPTION_SLIDERS)->boolValue;
}
virtual bool hasTrims() const {
return getOptionValue(LAYOUT_OPTION_TRIMS)->boolValue;
}
virtual bool isMirrored() const {
return getOptionValue(LAYOUT_OPTION_MIRRORED)->boolValue;
}
// Set decoration visibility
void setTrimsVisible(bool visible);
void setSlidersVisible(bool visible);
void setFlightModeVisible(bool visible);
// Updates settings for trims, sliders, pots, etc...
void show(bool visible = true) override;
bool isLayout() override { return true; }
protected:
const LayoutFactory * factory = nullptr;
std::unique_ptr<ViewMainDecoration> decoration;
uint8_t zoneCount;
uint8_t* zoneMap = nullptr;
rect_t lastMainZone = {0,0,0,0};
// Last time we refreshed the window
uint32_t lastRefresh = 0;
// Get the available space for widgets
rect_t getMainZone() const;
unsigned int getZonesCount() const override { return zoneCount; }
rect_t getZone(unsigned int index) const override;
void checkEvents() override;
};
template<class T>
class BaseLayoutFactory: public LayoutFactory
{
public:
BaseLayoutFactory(const char * id, const char * name,
const LayoutOption * options, uint8_t zoneCount, uint8_t* zoneMap):
LayoutFactory(id, name),
options(options),
zoneCount(zoneCount),
zoneMap(zoneMap)
{
bitmap = (MaskBitmap*)malloc(align32(BM_W * BM_H + sizeof(MaskBitmap)));
bitmap->width = BM_W;
bitmap->height = BM_H;
uint8_t* bm = (uint8_t*)bitmap->data;
memset(bm, 0, BM_W * BM_H);
memset(bm, 0xFF, BM_W);
memset(bm+((BM_H-1)*BM_W), 0xFF, BM_W);
for (int y = 1; y < BM_H - 1; y += 1) {
bm[y*BM_W] = 0xFF;
bm[y*BM_W+BM_W-1] = 0xFF;
}
for (int i = 0; i < zoneCount * 4; i += 4) {
uint8_t xo = BM_W * zoneMap[i] / LAYOUT_MAP_DIV;
uint8_t yo = BM_H * zoneMap[i+1] / LAYOUT_MAP_DIV;
uint8_t w = BM_W * zoneMap[i+2] / LAYOUT_MAP_DIV;
uint8_t h = (BM_H * zoneMap[i+3] + LAYOUT_MAP_DIV/2) / LAYOUT_MAP_DIV;
if (yo > 0)
memset(bm+(yo*BM_W+xo), 0xFF, w);
if (xo > 0) {
for (int y = 0; y < h; y += 1) {
bm[(yo+y)*BM_W+xo] = 0xFF;
}
}
}
}
~BaseLayoutFactory()
{
if (bitmap) {
free((void*)bitmap);
bitmap = nullptr;
}
}
const MaskBitmap* getBitmap() const override { return bitmap; }
const LayoutOption * getLayoutOptions() const override
{
return options;
}
Layout * create(Window* parent, Layout::PersistentData * persistentData) const override
{
initPersistentData(persistentData, true);
Layout * layout = new T(parent, this, persistentData, zoneCount, zoneMap);
if (layout) {
layout->create();
}
return layout;
}
Layout * load(Window* parent, Layout::PersistentData * persistentData) const override
{
initPersistentData(persistentData, false);
Layout * layout = new T(parent, this, persistentData, zoneCount, zoneMap);
if (layout) {
layout->load();
}
return layout;
}
void initPersistentData(Layout::PersistentData* persistentData,
bool setDefault) const override
{
if (setDefault) {
memset(persistentData, 0, sizeof(Layout::PersistentData));
}
if (options) {
int i = 0;
for (const LayoutOption* option = options; option->name; option++, i++) {
TRACE("LayoutFactory::initPersistentData() setting option '%s'",
STR_VAL(option->name));
// TODO compiler bug? The CPU freezes ... persistentData->options[i++]
// = option->deflt;
auto optVal = &persistentData->options[i];
if (setDefault) {
memcpy(&optVal->value, &option->deflt, sizeof(ZoneOptionValue));
}
optVal->type = zoneValueEnumFromType(option->type);
}
}
}
protected:
MaskBitmap * bitmap = nullptr;
const LayoutOption * options;
uint8_t zoneCount;
uint8_t* zoneMap;
};
@@ -24,7 +24,7 @@
#include <algorithm>
#include "color_picker.h"
#include "layout_factory_impl.h"
#include "layout.h"
#include "edgetx.h"
#include "topbar.h"
#include "view_main.h"
@@ -150,7 +150,7 @@ void ScreenSetupPage::build(Window* window)
clearLayoutOptions();
// If screen is not App Mode then save option values
auto layoutData = &g_model.screenData[customScreenIndex].layoutData;
auto layoutData = g_model.getScreenLayoutData(customScreenIndex);
auto layout = (Layout*)customScreens[customScreenIndex];
bool restoreOptions = false;
bool hasTopbar = true, hasFM = true, hasSliders = true, hasTrims = true, isMirrored = false;
@@ -204,7 +204,7 @@ void ScreenSetupPage::build(Window* window)
Window* btn =
new TextButton(line, rect_t{}, STR_REMOVE_SCREEN, [=]() -> uint8_t {
// Remove this screen from the model
LayoutFactory::disposeCustomScreen(customScreenIndex);
g_model.removeScreenLayout(customScreenIndex);
// Delete all custom screens
LayoutFactory::deleteCustomScreens();
@@ -247,8 +247,8 @@ void ScreenSetupPage::buildLayoutOptions()
int index = 0;
for (auto* option = factory->getLayoutOptions(); option->name; option++, index++) {
auto layoutData = &g_model.screenData[customScreenIndex].layoutData;
ZoneOptionValue* value = &layoutData->options[index].value;
auto layoutData = g_model.getScreenLayoutData(customScreenIndex);
LayoutOptionValue* value = &layoutData->options[index].value;
// Option label
auto line = layoutOptions->newLine(grid);
@@ -256,7 +256,7 @@ void ScreenSetupPage::buildLayoutOptions()
// Option value
switch (option->type) {
case ZoneOption::Bool:
case LayoutOption::Bool:
new ToggleSwitch(line, rect_t{},
GET_DEFAULT(value->boolValue),
[=](int newValue) {
@@ -265,7 +265,7 @@ void ScreenSetupPage::buildLayoutOptions()
});
break;
case ZoneOption::Color:
case LayoutOption::Color:
new ColorPicker(line, rect_t{}, GET_SET_DEFAULT(value->unsignedValue));
break;
@@ -23,7 +23,6 @@
#include "file_preview.h"
#include "theme_manager.h"
#include "topbar_impl.h"
#include "view_main.h"
#if LANDSCAPE
@@ -22,7 +22,7 @@
#pragma once
#include "pagegroup.h"
#include "widgets_container.h"
#include "topbar.h"
class ThemeView;
class Choice;
+193 -2
View File
@@ -25,12 +25,52 @@
#include "edgetx.h"
#include "storage/storage.h"
#include "etx_lv_theme.h"
#include "topbar_impl.h"
#include "topbar.h"
#include "view_main.h"
#include "widgets_setup.h"
#include "pagegroup.h"
#include "theme_manager.h"
#include "widget.h"
TopBar* TopbarFactory::create(Window* parent) { return new TopBar(parent); }
//-----------------------------------------------------------------------------
void TopBarPersistentData::clearZone(int idx)
{
zones[idx].clear();
}
void TopBarPersistentData::clear()
{
for (int i = 0; i < MAX_TOPBAR_ZONES; i += 1)
clearZone(i);
}
const char* TopBarPersistentData::getWidgetName(int idx)
{
return zones[idx].widgetName.c_str();
}
void TopBarPersistentData::setWidgetName(int idx, const char* s)
{
zones[idx].widgetName = s;
}
WidgetPersistentData* TopBarPersistentData::getWidgetData(int idx)
{
return &zones[idx].widgetData;
}
bool TopBarPersistentData::hasWidget(int idx)
{
return !zones[idx].widgetName.empty();
}
bool TopBarPersistentData::isWidget(int idx, const char* s)
{
return zones[idx].widgetName == s;
}
//-----------------------------------------------------------------------------
SetupTopBarWidgetsPage::SetupTopBarWidgetsPage() :
Window(ViewMain::instance(), rect_t{})
@@ -92,3 +132,154 @@ void SetupTopBarWidgetsPage::onEvent(event_t event)
Window::onEvent(event);
#endif
}
//-----------------------------------------------------------------------------
constexpr uint32_t TOPBAR_REFRESH = 1000 / 10; // 10 Hz
TopBar::TopBar(Window * parent) :
WidgetsContainer(parent, {0, 0, LCD_W, EdgeTxStyles::MENU_HEADER_HEIGHT}, MAX_TOPBAR_ZONES)
{
setWindowFlag(NO_FOCUS);
etx_solid_bg(lvobj, COLOR_THEME_SECONDARY1_INDEX);
headerIcon = new HeaderIcon(parent, ICON_EDGETX, [=]() { ViewMain::instance()->openMenu(); });
}
unsigned int TopBar::getZonesCount() const
{
unsigned int zc = 0;
for (int i = 0; i < zoneCount; i += 1)
if (g_model.topbarWidgetWidth[i] > 0)
zc += 1;
return zc;
}
rect_t TopBar::getZone(unsigned int index) const
{
coord_t x = MENU_HEADER_BUTTONS_LEFT + 1;
for (unsigned int i = 0; i < index; i += 1)
x += (g_model.topbarWidgetWidth[i] * (TOPBAR_ZONE_WIDTH + PAD_TINY));
coord_t size = ((g_model.topbarWidgetWidth[index] - 1) * (TOPBAR_ZONE_WIDTH + PAD_TINY) + TOPBAR_ZONE_WIDTH);
if ((x + size) > LCD_W) size = LCD_W - x;
return {x, PAD_THREE, size, TOPBAR_ZONE_HEIGHT};
}
void TopBar::setVisible(float visible) // 0.0 -> 1.0
{
coord_t y = 0;
if (visible == 0.0) {
y = -EdgeTxStyles::MENU_HEADER_HEIGHT;
} else if (visible > 0.0 && visible < 1.0){
y = -(float)EdgeTxStyles::MENU_HEADER_HEIGHT * (1.0 - visible);
}
if (y != top()) setTop(y);
}
void TopBar::setEdgeTxButtonVisible(float visible) // 0.0 -> 1.0
{
coord_t y = 0;
if (visible == 0.0) {
y = -EdgeTxStyles::MENU_HEADER_HEIGHT;
} else if (visible > 0.0 && visible < 1.0){
y = -(float)EdgeTxStyles::MENU_HEADER_HEIGHT * (1.0 - visible);
}
if (y != headerIcon->top()) headerIcon->setTop(y);
}
coord_t TopBar::getVisibleHeight(float visible) const // 0.0 -> 1.0
{
if (visible == 0.0) {
return 0;
}
else if (visible == 1.0) {
return EdgeTxStyles::MENU_HEADER_HEIGHT;
}
float h = (float)EdgeTxStyles::MENU_HEADER_HEIGHT * visible;
return (coord_t)h;
}
void TopBar::checkEvents()
{
uint32_t now = lv_tick_get();
if (now - lastRefresh >= TOPBAR_REFRESH) {
lastRefresh = now;
WidgetsContainer::checkEvents();
}
}
void TopBar::removeWidget(unsigned int index)
{
if (index >= zoneCount) return;
bool mark = false;
// If user manually removes 'system' widgets, mark name so widget does not get reloaded on restart
if ((index == (unsigned int)(zoneCount - 1)) && g_model.getTopbarData()->isWidget(index, "Date Time"))
mark = true;
if ((index == (unsigned int)(zoneCount - 2)) && g_model.getTopbarData()->isWidget(index, "Radio Info"))
mark = true;
#if defined(INTERNAL_GPS)
if ((index == (unsigned int)(zoneCount - 3)) && g_model.getTopbarData()->isWidget(index, "Internal GPS"))
mark = true;
#endif
// If user manually removes 'system' widgets, mark name so widget does not get reloaded on restart
if (mark)
g_model.getTopbarData()->setWidgetName(index, "---");
g_model.getTopbarData()->clearZone(index);
WidgetsContainer::removeWidget(index);
}
void TopBar::load()
{
unsigned int count = getZonesCount();
for (unsigned int i = 0; i < count; i++) {
// remove old widget
if (widgets[i]) {
widgets[i]->deleteLater();
widgets[i] = nullptr;
}
}
for (unsigned int i = 0; i < count; i++) {
// and load new one if required
if (g_model.getTopbarData()->hasWidget(i)) {
widgets[i] = WidgetFactory::newWidget(g_model.getTopbarData()->getWidgetName(i), this, getZone(i), -1, i);
}
}
}
Widget* TopBar::createWidget(unsigned int index,
const WidgetFactory* factory)
{
if (index >= zoneCount) return nullptr;
// remove old one if existing
removeWidget(index);
Widget* widget = nullptr;
if (factory) {
g_model.getTopbarData()->setWidgetName(index, factory->getName());
widget = factory->create(this, getZone(index), -1, index);
}
widgets[index] = widget;
if (widget) widget->attach(this);
return widget;
}
void TopBar::create()
{
g_model.getTopbarData()->clear();
}
//-----------------------------------------------------------------------------
+47 -7
View File
@@ -23,14 +23,9 @@
#include "layout.h"
class ScreenMenu;
class TopBar;
class HeaderIcon;
class TopbarFactory
{
public:
static TopBar* create(Window* parent);
};
//-----------------------------------------------------------------------------
class SetupTopBarWidgetsPage : public Window
{
@@ -46,3 +41,48 @@ class SetupTopBarWidgetsPage : public Window
void onEvent(event_t event) override;
void deleteLater(bool detach = true, bool trash = true) override;
};
//-----------------------------------------------------------------------------
class TopBar: public WidgetsContainer
{
public:
explicit TopBar(Window * parent);
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "TopBar";
}
#endif
unsigned int getZonesCount() const override;
rect_t getZone(unsigned int index) const override;
void setVisible(float visible);
void setEdgeTxButtonVisible(float visible);
coord_t getVisibleHeight(float visible) const; // 0.0 -> 1.0
void checkEvents() override;
bool isTopBar() override { return true; }
void removeWidget(unsigned int index) override;
Widget* createWidget(unsigned int index, const WidgetFactory* factory) override;
void create();
void load();
static LAYOUT_VAL_SCALED(HDR_DATE_XO, 48)
static constexpr coord_t TOPBAR_ZONE_HEIGHT = EdgeTxStyles::MENU_HEADER_HEIGHT - 2 * PAD_THREE;
protected:
uint32_t lastRefresh = 0;
HeaderIcon* headerIcon = nullptr;
};
//-----------------------------------------------------------------------------
@@ -1,123 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "topbar_impl.h"
#include "edgetx.h"
#include "theme_manager.h"
#include "view_main.h"
constexpr uint32_t TOPBAR_REFRESH = 1000 / 10; // 10 Hz
TopBar::TopBar(Window * parent) :
TopBarBase(parent, {0, 0, LCD_W, EdgeTxStyles::MENU_HEADER_HEIGHT}, &g_model.topbarData)
{
etx_solid_bg(lvobj, COLOR_THEME_SECONDARY1_INDEX);
headerIcon = new HeaderIcon(parent, ICON_EDGETX, [=]() { ViewMain::instance()->openMenu(); });
}
unsigned int TopBar::getZonesCount() const
{
unsigned int zoneCount = 0;
for (int i = 0; i < MAX_TOPBAR_ZONES; i += 1)
if (g_model.topbarWidgetWidth[i] > 0)
zoneCount += 1;
return zoneCount;
}
rect_t TopBar::getZone(unsigned int index) const
{
coord_t x = MENU_HEADER_BUTTONS_LEFT + 1;
for (unsigned int i = 0; i < index; i += 1)
x += (g_model.topbarWidgetWidth[i] * (TOPBAR_ZONE_WIDTH + PAD_TINY));
coord_t size = ((g_model.topbarWidgetWidth[index] - 1) * (TOPBAR_ZONE_WIDTH + PAD_TINY) + TOPBAR_ZONE_WIDTH);
if ((x + size) > LCD_W) size = LCD_W - x;
return {x, PAD_THREE, size, TOPBAR_ZONE_HEIGHT};
}
void TopBar::setVisible(float visible) // 0.0 -> 1.0
{
coord_t y = 0;
if (visible == 0.0) {
y = -EdgeTxStyles::MENU_HEADER_HEIGHT;
} else if (visible > 0.0 && visible < 1.0){
y = -(float)EdgeTxStyles::MENU_HEADER_HEIGHT * (1.0 - visible);
}
if (y != top()) setTop(y);
}
void TopBar::setEdgeTxButtonVisible(float visible) // 0.0 -> 1.0
{
coord_t y = 0;
if (visible == 0.0) {
y = -EdgeTxStyles::MENU_HEADER_HEIGHT;
} else if (visible > 0.0 && visible < 1.0){
y = -(float)EdgeTxStyles::MENU_HEADER_HEIGHT * (1.0 - visible);
}
if (y != headerIcon->top()) headerIcon->setTop(y);
}
coord_t TopBar::getVisibleHeight(float visible) const // 0.0 -> 1.0
{
if (visible == 0.0) {
return 0;
}
else if (visible == 1.0) {
return EdgeTxStyles::MENU_HEADER_HEIGHT;
}
float h = (float)EdgeTxStyles::MENU_HEADER_HEIGHT * visible;
return (coord_t)h;
}
void TopBar::checkEvents()
{
uint32_t now = lv_tick_get();
if (now - lastRefresh >= TOPBAR_REFRESH) {
lastRefresh = now;
TopBarBase::checkEvents();
}
}
void TopBar::removeWidget(unsigned int index)
{
bool mark = false;
// If user manually removes 'system' widgets, mark name so widget does not get reloaded on restart
if ((index == MAX_TOPBAR_ZONES - 1) && (strncmp(persistentData->zones[index].widgetName, "Date Time", WIDGET_NAME_LEN) == 0))
mark = true;
if ((index == MAX_TOPBAR_ZONES - 2) && (strncmp(persistentData->zones[index].widgetName, "Radio Info", WIDGET_NAME_LEN) == 0))
mark = true;
#if defined(INTERNAL_GPS)
if ((index == MAX_TOPBAR_ZONES - 3) && (strncmp(persistentData->zones[index].widgetName, "Internal GPS", WIDGET_NAME_LEN) == 0))
mark = true;
#endif
WidgetsContainerImpl::removeWidget(index);
// If user manually removes 'system' widgets, mark name so widget does not get reloaded on restart
if (mark)
strcpy(persistentData->zones[index].widgetName, "--");
}
@@ -1,69 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "topbar.h"
#include "layout_factory_impl.h"
class HeaderIcon;
typedef WidgetsContainerImpl<MAX_TOPBAR_ZONES, MAX_TOPBAR_OPTIONS> TopBarBase;
class TopBar: public TopBarBase
{
public:
explicit TopBar(Window * parent);
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "TopBar";
}
#endif
void load() override
{
TopBarBase::load();
}
unsigned int getZonesCount() const override;
rect_t getZone(unsigned int index) const override;
void setVisible(float visible);
void setEdgeTxButtonVisible(float visible);
coord_t getVisibleHeight(float visible) const; // 0.0 -> 1.0
void checkEvents() override;
bool isTopBar() override { return true; }
void removeWidget(unsigned int index) override;
static LAYOUT_VAL_SCALED(HDR_DATE_XO, 48)
static constexpr coord_t TOPBAR_ZONE_HEIGHT = EdgeTxStyles::MENU_HEADER_HEIGHT - 2 * PAD_THREE;
protected:
uint32_t lastRefresh = 0;
HeaderIcon* headerIcon = nullptr;
};
@@ -23,10 +23,11 @@
#include "model_select.h"
#include "edgetx.h"
#include "topbar_impl.h"
#include "topbar.h"
#include "quick_menu.h"
#include "view_channels.h"
#include "screen_setup.h"
#include "widget.h"
static void tile_view_deleted_cb(lv_event_t* e)
{
@@ -94,7 +95,7 @@ ViewMain::ViewMain() :
nullptr);
// create last to be on top
topbar = TopbarFactory::create(this);
topbar = new TopBar(this);
}
ViewMain::~ViewMain() { _instance = nullptr; }
@@ -408,7 +409,7 @@ bool ViewMain::hasTopbar()
bool ViewMain::hasTopbar(unsigned view)
{
if (view < MAX_CUSTOM_SCREENS)
return g_model.screenData[view].layoutData.options[LAYOUT_OPTION_TOPBAR].value.boolValue;
return g_model.getScreenLayoutData(view)->options[LAYOUT_OPTION_TOPBAR].value.boolValue;
return false;
}
+2 -1
View File
@@ -24,9 +24,10 @@
#include "topbar.h"
#include "window.h"
class QuickMenu;
class SetupWidgetsPage;
class SetupTopBarWidgetsPage;
class QuickMenu;
class TopBar;
class ViewMain : public NavWindow
{
+141 -20
View File
@@ -30,11 +30,131 @@
#include "touch.h"
#endif
//-----------------------------------------------------------------------------
inline WidgetOptionValueEnum widgetValueEnumFromType(WidgetOption::Type type)
{
switch(type) {
case WidgetOption::String:
case WidgetOption::File:
return WOV_String;
case WidgetOption::Integer:
return WOV_Signed;
case WidgetOption::Bool:
return WOV_Bool;
case WidgetOption::Source:
return WOV_Source;
case WidgetOption::Color:
return WOV_Color;
default:
return WOV_Unsigned;
}
}
void WidgetPersistentData::addEntry(int idx)
{
if (idx >= (int)options.size()) {
WidgetOptionValueTyped wov;
wov.type = WOV_Unsigned;
wov.value.unsignedValue = 0;
while ((int)options.size() <= idx)
options.push_back(wov);
}
}
bool WidgetPersistentData::hasOption(int idx)
{
return idx < (int)options.size();
}
void WidgetPersistentData::setDefault(int idx, const WidgetOption* opt, bool forced)
{
addEntry(idx);
auto optType = widgetValueEnumFromType(opt->type);
if (forced || options[idx].type != optType) {
// reset to default value
options[idx].type = optType;
memcpy((void*)&options[idx].value, (void*)&opt->deflt, sizeof(WidgetOptionValue));
}
}
void WidgetPersistentData::clear()
{
options.clear();
}
WidgetOptionValueEnum WidgetPersistentData::getType(int idx)
{
addEntry(idx);
return options[idx].type;
}
void WidgetPersistentData::setType(int idx, WidgetOptionValueEnum typ)
{
addEntry(idx);
options[idx].type = typ;
}
int32_t WidgetPersistentData::getSignedValue(int idx)
{
addEntry(idx);
return options[idx].value.signedValue;
}
void WidgetPersistentData::setSignedValue(int idx, int32_t newValue)
{
addEntry(idx);
options[idx].value.signedValue = newValue;
}
uint32_t WidgetPersistentData::getUnsignedValue(int idx)
{
addEntry(idx);
return options[idx].value.unsignedValue;
}
void WidgetPersistentData::setUnsignedValue(int idx, uint32_t newValue)
{
addEntry(idx);
options[idx].value.unsignedValue = newValue;
}
bool WidgetPersistentData::getBoolValue(int idx)
{
addEntry(idx);
return options[idx].value.boolValue;
}
void WidgetPersistentData::setBoolValue(int idx, bool newValue)
{
addEntry(idx);
options[idx].value.boolValue = newValue;
}
std::string WidgetPersistentData::getString(int idx)
{
addEntry(idx);
return options[idx].value.stringValue;
}
void WidgetPersistentData::setString(int idx, const char* s)
{
addEntry(idx);
options[idx].value.stringValue = s;
}
//-----------------------------------------------------------------------------
Widget::Widget(const WidgetFactory* factory, Window* parent, const rect_t& rect,
WidgetPersistentData* persistentData) :
int screenNum, int zoneNum) :
ButtonBase(parent, rect, nullptr, window_create),
factory(factory),
persistentData(persistentData)
screenNum(screenNum), zoneNum(zoneNum)
{
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE);
@@ -146,7 +266,7 @@ bool Widget::onLongPress()
return true;
}
const ZoneOption* Widget::getOptionDefinitions() const
const WidgetOption* Widget::getOptionDefinitions() const
{
return getFactory()->getDefaultOptions();
}
@@ -196,6 +316,10 @@ void Widget::enableFocus(bool enable)
}
}
WidgetPersistentData* Widget::getPersistentData() { return g_model.getWidgetData(screenNum, zoneNum); }
//-----------------------------------------------------------------------------
std::list<const WidgetFactory*>& WidgetFactory::getRegisteredWidgets()
{
static std::list<const WidgetFactory*> widgets;
@@ -236,35 +360,32 @@ void WidgetFactory::registerWidget(const WidgetFactory* factory)
}
Widget* WidgetFactory::newWidget(const char* name, Window* parent,
const rect_t& rect,
WidgetPersistentData* persistentData)
const rect_t& rect, int screenNum, int zoneNum)
{
const WidgetFactory* factory = getWidgetFactory(name);
if (factory) {
return factory->create(parent, rect, persistentData, false);
return factory->create(parent, rect, screenNum, zoneNum, false);
}
return nullptr;
}
void WidgetFactory::initPersistentData(Widget::PersistentData* persistentData,
bool setDefault) const
Widget* WidgetFactory::create(Window* parent, const rect_t& rect,
int screenNum, int zoneNum,
bool init) const
{
if (setDefault) {
memset(persistentData, 0, sizeof(Widget::PersistentData));
auto widgetData = g_model.getWidgetData(screenNum, zoneNum);
if (init) {
widgetData->clear();
parseOptionDefaults();
}
if (options) {
int i = 0;
for (const ZoneOption* option = options; option->name; option++, i++) {
TRACE("WidgetFactory::initPersistentData() setting option '%s'",
option->name);
auto optVal = &persistentData->options[i];
auto optType = zoneValueEnumFromType(option->type);
if (setDefault || optVal->type != optType) {
// reset to default value
memcpy(&optVal->value, &option->deflt, sizeof(ZoneOptionValue));
optVal->type = optType;
}
for (const WidgetOption* option = options; option->name; option++, i++) {
TRACE("WidgetFactory::create() setting option '%s'", option->name);
widgetData->setDefault(i, option, init);
}
}
return createNew(parent, rect, screenNum, zoneNum);
}
+63 -27
View File
@@ -22,37 +22,69 @@
#pragma once
#include <string.h>
#include <list>
#if !defined(BACKUP)
#include <vector>
#endif
#include "button.h"
#include "widgets_container.h"
#include "storage/yaml/yaml_defs.h"
#include "datastructs_screen.h"
class WidgetFactory;
//-----------------------------------------------------------------------------
struct WidgetOption
{
// First two entries must match luaScriptInputType enum
// TODO: should be cleaned up
enum Type {
Integer,
Source,
Bool,
String,
TextSize,
Timer,
Switch,
Color,
Align,
Slider,
Choice,
File,
};
const char * name;
Type type;
WidgetOptionValue deflt;
WidgetOptionValue min;
WidgetOptionValue max;
const char * displayName;
std::string fileSelectPath;
#if !defined(BACKUP)
std::vector<std::string> choiceValues;
#endif
};
//-----------------------------------------------------------------------------
class Widget : public ButtonBase
{
public:
typedef WidgetPersistentData PersistentData;
Widget(const WidgetFactory* factory, Window* parent, const rect_t& rect,
WidgetPersistentData* persistentData);
int screenNum, int zoneNum);
~Widget() override = default;
const WidgetFactory* getFactory() const { return factory; }
const ZoneOption* getOptionDefinitions() const;
const WidgetOption* getOptionDefinitions() const;
bool hasOptions() const { return getOptionDefinitions() && getOptionDefinitions()->name; }
virtual const char* getErrorMessage() const { return nullptr; }
ZoneOptionValue* getOptionValue(unsigned int index) const
{
return &persistentData->options[index].value;
}
PersistentData* getPersistentData() { return persistentData; }
WidgetPersistentData* getPersistentData();
#if defined(DEBUG_WINDOWS)
std::string getName() const override { return "Widget"; }
@@ -89,7 +121,8 @@ class Widget : public ButtonBase
protected:
const WidgetFactory* factory;
PersistentData* persistentData;
int screenNum;
int zoneNum;
bool fullscreen = false;
bool fsAllowed = true;
bool closeFS = false;
@@ -104,10 +137,12 @@ class Widget : public ButtonBase
void openMenu();
};
//-----------------------------------------------------------------------------
class WidgetFactory
{
public:
explicit WidgetFactory(const char* name, const ZoneOption* options = nullptr,
explicit WidgetFactory(const char* name, const WidgetOption* options = nullptr,
const char* displayName = nullptr) :
name(name), displayName(displayName), options(options)
{
@@ -118,7 +153,7 @@ class WidgetFactory
const char* getName() const { return name; }
const ZoneOption* getDefaultOptions() const { return options; }
const WidgetOption* getDefaultOptions() const { return options; }
virtual const void parseOptionDefaults() const {}
const char* getDisplayName() const
@@ -126,12 +161,11 @@ class WidgetFactory
return displayName ? displayName : name;
}
void initPersistentData(Widget::PersistentData* persistentData,
bool setDefault) const;
Widget* create(Window* parent, const rect_t& rect,
int screenNum, int zoneNum,
bool init = true) const;
virtual Widget* create(Window* parent, const rect_t& rect,
Widget::PersistentData* persistentData,
bool init = true) const = 0;
virtual Widget* createNew(Window* parent, const rect_t& rect, int screenNum, int zoneNum) const = 0;
virtual bool isLuaWidgetFactory() const { return false; }
@@ -140,29 +174,31 @@ class WidgetFactory
static void unregisterWidget(const WidgetFactory* factory);
static const WidgetFactory* getWidgetFactory(const char* name);
static Widget* newWidget(const char* name, Window* parent, const rect_t& rect,
Widget::PersistentData* persistentData);
int screenNum, int zoneNum);
protected:
const char* name = nullptr;
const char* displayName = nullptr;
const ZoneOption* options = nullptr;
const WidgetOption* options = nullptr;
};
//-----------------------------------------------------------------------------
template <class T>
class BaseWidgetFactory : public WidgetFactory
{
public:
BaseWidgetFactory(const char* name, const ZoneOption* options,
BaseWidgetFactory(const char* name, const WidgetOption* options,
const char* displayName = nullptr) :
WidgetFactory(name, options, displayName)
{
}
Widget* create(Window* parent, const rect_t& rect,
Widget::PersistentData* persistentData,
bool init = true) const override
Widget* createNew(Window* parent, const rect_t& rect,
int screenNum, int zoneNum) const override
{
initPersistentData(persistentData, init);
return new T(this, parent, rect, persistentData);
return new T(this, parent, rect, screenNum, zoneNum);
}
};
//-----------------------------------------------------------------------------
@@ -53,96 +53,93 @@ WidgetSettings::WidgetSettings(Widget* w) :
widget->getFactory()->parseOptionDefaults();
auto opt = widget->getOptionDefinitions();
auto* widgetData = widget->getPersistentData();
while (opt && opt->name != nullptr) {
auto line = form->newLine(grid);
new StaticText(line, rect_t{},
opt->displayName ? opt->displayName : opt->name);
auto optVal = widget->getOptionValue(optIdx);
switch (opt->type) {
case ZoneOption::Integer:
case WidgetOption::Integer:
(new NumberEdit(
line, rect_t{}, opt->min.signedValue,
opt->max.signedValue,
[=]() -> int {
return optVal->signedValue;
return widgetData->getSignedValue(optIdx);
},
[=](int32_t newValue) {
optVal->signedValue = newValue;
widgetData->setSignedValue(optIdx, newValue);
SET_DIRTY();
}))
->setDefault(opt->deflt.signedValue);
break;
case ZoneOption::Source:
case WidgetOption::Source:
new SourceChoice(
line, rect_t{}, 0, MIXSRC_LAST_TELEM,
[=]() -> int16_t {
return (int16_t)optVal->unsignedValue;
return widgetData->getUnsignedValue(optIdx);
},
[=](int16_t newValue) {
optVal->unsignedValue =
(uint32_t)newValue;
widgetData->setUnsignedValue(optIdx, (uint32_t)newValue);
SET_DIRTY();
});
break;
case ZoneOption::Bool:
case WidgetOption::Bool:
new ToggleSwitch(
line, rect_t{},
[=]() -> uint8_t {
return (uint8_t)optVal->boolValue;
return (uint8_t)widgetData->getBoolValue(optIdx);
},
[=](int8_t newValue) {
optVal->boolValue = newValue;
widgetData->setBoolValue(optIdx, newValue);
SET_DIRTY();
});
break;
case ZoneOption::String:
new ModelTextEdit(line, rect_t{},
optVal->stringValue,
sizeof(optVal->stringValue));
case WidgetOption::String:
new ModelStringEdit(line, rect_t{}, widgetData->getString(optIdx),
[=](const char* s) {
widgetData->setString(optIdx, s);
});
break;
case ZoneOption::TextSize:
case WidgetOption::TextSize:
new Choice(
line, rect_t{}, STR_FONT_SIZES, 0, FONTS_COUNT - 1,
[=]() -> int { // getValue
return (int)optVal->unsignedValue;
return widgetData->getUnsignedValue(optIdx);
},
[=](int newValue) { // setValue
optVal->unsignedValue =
(uint32_t)newValue;
widgetData->setUnsignedValue(optIdx, (uint32_t)newValue);
SET_DIRTY();
});
break;
case ZoneOption::Align:
case WidgetOption::Align:
new Choice(
line, rect_t{}, STR_ALIGN_OPTS, 0, ALIGN_COUNT - 1,
[=]() -> int { // getValue
return (int)optVal->unsignedValue;
return widgetData->getUnsignedValue(optIdx);
},
[=](int newValue) { // setValue
optVal->unsignedValue =
(uint32_t)newValue;
widgetData->setUnsignedValue(optIdx, (uint32_t)newValue);
SET_DIRTY();
});
break;
case ZoneOption::Timer: // Unsigned
case WidgetOption::Timer: // Unsigned
{
auto tmChoice = new Choice(
line, rect_t{}, 0, TIMERS - 1,
[=]() -> int { // getValue
return (int)optVal->unsignedValue;
return widgetData->getUnsignedValue(optIdx);
},
[=](int newValue) { // setValue
optVal->unsignedValue =
(uint32_t)newValue;
widgetData->setUnsignedValue(optIdx, (uint32_t)newValue);
SET_DIRTY();
});
@@ -151,61 +148,62 @@ WidgetSettings::WidgetSettings(Widget* w) :
});
} break;
case ZoneOption::Switch:
case WidgetOption::Switch:
new SwitchChoice(
line, rect_t{},
opt->min.signedValue, // min
opt->max.signedValue, // max
[=]() -> int16_t { // getValue
return optVal->signedValue;
return widgetData->getSignedValue(optIdx);
},
[=](int16_t newValue) { // setValue
optVal->signedValue = newValue;
widgetData->setSignedValue(optIdx, newValue);
SET_DIRTY();
});
break;
case ZoneOption::Color:
case WidgetOption::Color:
new ColorPicker(
line, rect_t{},
[=]() -> uint32_t { // getValue
return optVal->unsignedValue;
return widgetData->getUnsignedValue(optIdx);
},
[=](uint32_t newValue) { // setValue
optVal->unsignedValue = newValue;
widgetData->setUnsignedValue(optIdx, newValue);
SET_DIRTY();
});
break;
case ZoneOption::Slider:
case WidgetOption::Slider:
new Slider(
line, SLIDER_W, opt->min.signedValue, opt->max.signedValue,
[=]() { return optVal->unsignedValue; },
[=]() {
return widgetData->getUnsignedValue(optIdx);
},
[=](uint32_t newValue) {
optVal->unsignedValue = newValue;
widgetData->setUnsignedValue(optIdx, newValue);
SET_DIRTY();
});
break;
case ZoneOption::Choice:
case WidgetOption::Choice:
new Choice(line, rect_t{}, opt->choiceValues, 0, opt->choiceValues.size() - 1,
[=]() { return optVal->unsignedValue - 1; },
[=]() {
return widgetData->getUnsignedValue(optIdx) - 1;
},
[=](uint32_t newValue) {
optVal->unsignedValue = newValue + 1;
widgetData->setUnsignedValue(optIdx, newValue + 1);
SET_DIRTY();
});
break;
case ZoneOption::File:
new FileChoice(line, rect_t{}, opt->fileSelectPath, nullptr, LEN_ZONE_OPTION_STRING,
case WidgetOption::File:
new FileChoice(line, rect_t{}, opt->fileSelectPath, nullptr, FF_MAX_LFN,
[=]() {
char s[LEN_ZONE_OPTION_STRING + 1];
strncpy(s, optVal->stringValue, LEN_ZONE_OPTION_STRING);
s[LEN_ZONE_OPTION_STRING] = 0;
return std::string(s);
return widgetData->getString(optIdx);
},
[=](std::string s) {
strncpy(optVal->stringValue, s.c_str(), LEN_ZONE_OPTION_STRING);
widgetData->setString(optIdx, s.c_str());
SET_DIRTY();
});
break;
@@ -0,0 +1,93 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "widgets_container.h"
#include "widget.h"
WidgetsContainer::WidgetsContainer(Window* parent, const rect_t& rect, uint8_t zoneCount) :
Window(parent, rect), zoneCount(zoneCount)
{
widgets = new Widget*[zoneCount];
for (int i = 0; i < zoneCount; i += 1) widgets[i] = nullptr;
}
void WidgetsContainer::deleteLater(bool detach, bool trash)
{
if (deleted()) return;
for (int i = 0; i < zoneCount; i += 1)
if (widgets[i]) widgets[i]->deleteLater();
if (widgets) delete[] widgets;
widgets = nullptr;
Window::deleteLater(detach, trash);
}
Widget* WidgetsContainer::getWidget(unsigned int index)
{
if (index < zoneCount) return widgets[index];
return nullptr;
}
void WidgetsContainer::removeWidget(unsigned int index)
{
if (index >= zoneCount) return;
if (widgets[index]) {
widgets[index]->deleteLater();
}
widgets[index] = nullptr;
}
void WidgetsContainer::removeAllWidgets()
{
for (unsigned int i = 0; i < zoneCount; i++)
removeWidget(i);
}
void WidgetsContainer::updateZones()
{
for (int i = 0; i < zoneCount; i++) {
if (widgets[i]) {
auto zone = getZone(i);
widgets[i]->setRect(zone);
widgets[i]->updateZoneRect(zone);
}
}
}
void WidgetsContainer::showWidgets(bool visible)
{
for (int i = 0; i < zoneCount; i++) {
if (widgets[i]) {
widgets[i]->show(visible);
}
}
}
void WidgetsContainer::runBackground()
{
for (int i = 0; i < zoneCount; i++) {
if (widgets[i]) {
widgets[i]->background();
}
}
}
@@ -22,75 +22,34 @@
#pragma once
#include "window.h"
#include "zone.h"
#define WIDGET_NAME_LEN 20
#define MAX_WIDGET_OPTIONS 10
static LAYOUT_VAL_SCALED(MENU_HEADER_BUTTONS_LEFT, 47)
#if LCD_W == 800 // TODO: handle this better
static constexpr int TOPBAR_ZONE_WIDTH = 102;
#else
static LAYOUT_VAL_SCALED(TOPBAR_ZONE_WIDTH, 70)
#endif
static constexpr int MAX_TOPBAR_ZONES = (LCD_W - MENU_HEADER_BUTTONS_LEFT - 1 + TOPBAR_ZONE_WIDTH / 2) / TOPBAR_ZONE_WIDTH;
#define MAX_TOPBAR_OPTIONS 1 // just because of VC++ which doesn't like 0-size arrays :(
// Common 'ZoneOptionValue's among all layouts
enum {
LAYOUT_OPTION_TOPBAR = 0,
LAYOUT_OPTION_FM,
LAYOUT_OPTION_SLIDERS,
LAYOUT_OPTION_TRIMS,
LAYOUT_OPTION_MIRRORED,
LAYOUT_OPTION_LAST_DEFAULT=LAYOUT_OPTION_MIRRORED
};
class Widget;
class WidgetFactory;
struct WidgetPersistentData {
ZoneOptionValueTyped options[MAX_WIDGET_OPTIONS] USE_IDX;
};
struct ZonePersistentData {
char widgetName[WIDGET_NAME_LEN];
WidgetPersistentData widgetData;
};
template<int N, int O>
struct WidgetsContainerPersistentData {
ZonePersistentData zones[N];
ZoneOptionValueTyped options[O];
};
#if !defined(YAML_GENERATOR)
typedef WidgetsContainerPersistentData<MAX_TOPBAR_ZONES, MAX_TOPBAR_OPTIONS> TopBarPersistentData;
#else
struct TopBarPersistentData {
ZonePersistentData zones[MAX_TOPBAR_ZONES];
ZoneOptionValueTyped options[MAX_TOPBAR_OPTIONS];
};
#endif
class WidgetsContainer: public Window
{
public:
using Window::Window;
virtual unsigned int getZonesCount() const = 0;
virtual rect_t getZone(unsigned int index) const = 0;
virtual Widget * createWidget(unsigned int index, const WidgetFactory * factory) = 0;
virtual Widget * getWidget(unsigned int index) = 0;
virtual void removeWidget(unsigned int index) = 0;
virtual void updateZones() = 0;
virtual void showWidgets(bool visible = true) = 0;
virtual void hideWidgets() { showWidgets(false); }
virtual void runBackground() = 0;
public:
WidgetsContainer(Window* parent, const rect_t& rect, uint8_t zoneCount);
virtual bool isLayout() { return false; }
virtual bool isAppMode() const { return false; }
bool isWidgetsContainer() override { return true; }
virtual unsigned int getZonesCount() const = 0;
virtual rect_t getZone(unsigned int index) const = 0;
virtual Widget * createWidget(unsigned int index, const WidgetFactory * factory) = 0;
Widget* getWidget(unsigned int index);
virtual void removeWidget(unsigned int index);
void removeAllWidgets();
void updateZones();
void showWidgets(bool visible = true);
void hideWidgets() { showWidgets(false); }
void runBackground();
virtual bool isLayout() { return false; }
virtual bool isAppMode() const { return false; }
bool isWidgetsContainer() override { return true; }
void deleteLater(bool detach = true, bool trash = true) override;
protected:
uint8_t zoneCount = 0;
Widget** widgets = nullptr;
};
@@ -1,165 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "strhelpers.h"
#include "widget.h"
template <int N, int O>
class WidgetsContainerImpl : public WidgetsContainer
{
public:
typedef WidgetsContainerPersistentData<N, O> PersistentData;
WidgetsContainerImpl(Window* parent, const rect_t& rect,
PersistentData* persistentData) :
WidgetsContainer(parent, rect), persistentData(persistentData)
{
setWindowFlag(NO_FOCUS);
}
Widget* createWidget(unsigned int index,
const WidgetFactory* factory) override
{
if (index >= N) return nullptr;
// remove old one if existing
removeWidget(index);
Widget* widget = nullptr;
if (factory) {
strAppend(persistentData->zones[index].widgetName, factory->getName(),
WIDGET_NAME_LEN);
widget = factory->create(this, getZone(index),
&persistentData->zones[index].widgetData);
}
widgets[index] = widget;
if (widget) widget->attach(this);
return widget;
}
void removeWidget(unsigned int index) override
{
if (index >= N) return;
if (widgets[index]) {
widgets[index]->deleteLater();
}
widgets[index] = nullptr;
memset(persistentData->zones[index].widgetName, 0,
sizeof(ZonePersistentData::widgetName));
memset(&persistentData->zones[index].widgetData, 0,
sizeof(Widget::PersistentData));
}
Widget* getWidget(unsigned int index) override
{
if (index < N) return widgets[index];
return nullptr;
}
virtual void create() { memset(persistentData, 0, sizeof(PersistentData)); }
void removeAllWidgets()
{
for (unsigned int i = 0; i < N; i++)
removeWidget(i);
}
virtual void load()
{
unsigned int count = getZonesCount();
for (unsigned int i = 0; i < count; i++) {
// remove old widget
if (widgets[i]) {
widgets[i]->deleteLater();
widgets[i] = nullptr;
}
}
for (unsigned int i = 0; i < count; i++) {
// and load new one if required
if (persistentData->zones[i].widgetName[0]) {
char name[WIDGET_NAME_LEN + 1];
memset(name, 0, sizeof(name));
strAppend(name, persistentData->zones[i].widgetName, WIDGET_NAME_LEN);
widgets[i] = WidgetFactory::newWidget(
name, this, getZone(i), &persistentData->zones[i].widgetData);
}
}
}
inline ZoneOptionValue* getOptionValue(unsigned int index) const
{
return &persistentData->options[index].value;
}
unsigned int getZonesCount() const override = 0;
rect_t getZone(unsigned int index) const override = 0;
virtual void background()
{
for (int i = 0; i < N; i++) {
if (widgets[i]) {
widgets[i]->background();
}
}
}
void updateZones() override
{
for (int i = 0; i < N; i++) {
if (widgets[i]) {
auto zone = getZone(i);
widgets[i]->setRect(zone);
widgets[i]->updateZoneRect(zone);
}
}
}
void showWidgets(bool visible = true) override
{
for (int i = 0; i < N; i++) {
if (widgets[i]) {
widgets[i]->show(visible);
}
}
}
void runBackground() override
{
for (int i = 0; i < N; i++) {
if (widgets[i]) {
widgets[i]->background();
}
}
}
protected:
PersistentData* persistentData;
Widget* widgets[N] = {nullptr};
};
-121
View File
@@ -1,121 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include <inttypes.h>
#include "storage/yaml/yaml_defs.h"
#include <vector>
#define LEN_ZONE_OPTION_STRING 12
#define OPTION_VALUE_UNSIGNED(x) ZoneOptionValue{ .unsignedValue = (x) }
#define OPTION_VALUE_SIGNED(x) ZoneOptionValue{ .signedValue = (x) }
#define OPTION_VALUE_BOOL(x) ZoneOptionValue{ .boolValue = (x) }
#define OPTION_VALUE_STRING(...) ZoneOptionValue{ .stringValue = { __VA_ARGS__ } }
union ZoneOptionValue
{
uint32_t unsignedValue;
int32_t signedValue;
uint32_t boolValue;
char stringValue[LEN_ZONE_OPTION_STRING];
CUST_ATTR(source, r_zov_source, w_zov_source);
CUST_ATTR(color, r_zov_color, w_zov_color);
};
enum ZoneOptionValueEnum {
ZOV_Unsigned=0,
ZOV_Signed,
ZOV_Bool,
ZOV_String,
ZOV_Source,
ZOV_Color
};
struct ZoneOption
{
// First two entries must match luaScriptInputType enum
// TODO: should be cleaned up
enum Type {
Integer,
Source,
Bool,
String,
TextSize,
Timer,
Switch,
Color,
Align,
Slider,
Choice,
File,
};
const char * name;
Type type;
ZoneOptionValue deflt;
ZoneOptionValue min;
ZoneOptionValue max;
const char * displayName;
std::string fileSelectPath;
std::vector<std::string> choiceValues;
};
enum ZoneOptionAlign
{
ALIGN_LEFT,
ALIGN_CENTER,
ALIGN_RIGHT,
// this one MUST be last
ALIGN_COUNT
};
struct ZoneOptionValueTyped
{
ZoneOptionValueEnum type;
ZoneOptionValue value FUNC(select_zov);
};
inline ZoneOptionValueEnum zoneValueEnumFromType(ZoneOption::Type type)
{
switch(type) {
case ZoneOption::String:
case ZoneOption::File:
return ZOV_String;
case ZoneOption::Integer:
return ZOV_Signed;
case ZoneOption::Bool:
return ZOV_Bool;
case ZoneOption::Source:
return ZOV_Source;
case ZoneOption::Color:
return ZOV_Color;
default:
return ZOV_Unsigned;
}
}
@@ -25,7 +25,7 @@
#include "sliders.h"
#include "etx_lv_theme.h"
#include "trims.h"
#include "topbar_impl.h"
#include "topbar.h"
extern inline tmr10ms_t getTicks() { return g_tmr10ms; }
@@ -116,7 +116,7 @@ void RadioTrainerPage::build(Window* form)
}
// Trainer calibration
auto btn = new TextButton(line, rect_t{}, std::string(STR_MENUCALIBRATION),
auto btn = new TextButton(line, rect_t{}, STR_MENUCALIBRATION,
[=]() -> uint8_t {
memcpy(g_eeGeneral.trainer.calib, trainerInput,
sizeof(g_eeGeneral.trainer.calib));
@@ -47,20 +47,17 @@ PageDef screensMenuItems[] = {
TRACE("Add screen: add screen: newIdx = %d", newIdx);
auto& screen = customScreens[newIdx];
auto& screenData = g_model.screenData[newIdx];
const LayoutFactory* factory = defaultLayout;
if (factory) {
TRACE("Add screen: add screen: factory = %p", factory);
auto viewMain = ViewMain::instance();
screen = factory->create(viewMain, &screenData.layoutData);
screen = factory->create(viewMain, newIdx);
viewMain->addMainView(screen, newIdx);
strncpy(screenData.LayoutId, factory->getId(),
sizeof(screenData.LayoutId));
TRACE("Add screen: add screen: LayoutId = %s",
screenData.LayoutId);
g_model.setScreenLayoutId(newIdx, factory->getId());
TRACE("Add screen: add screen: LayoutId = %s", g_model.getScreenLayoutId(newIdx));
subMenu->onPress(newIdx + ScreenSetupPage::FIRST_SCREEN_OFFSET);
@@ -24,7 +24,7 @@
#include "theme_manager.h"
#include "etx_lv_theme.h"
#include "view_main.h"
#include "topbar_impl.h"
#include "topbar.h"
#include "model_select.h"
#include "os/time.h"
#include "view_channels.h"
@@ -56,7 +56,7 @@ extern PageDef toolsMenuItems[];
class PageGroupItem
{
public:
PageGroupItem(std::string title, QuickMenu::SubMenu subMenu = QuickMenu::NONE) :
PageGroupItem(const std::string& title, QuickMenu::SubMenu subMenu = QuickMenu::NONE) :
title(std::move(title)), icon(ICON_EDGETX), quickMenuId(subMenu), padding(PAD_SMALL)
{}
@@ -73,7 +73,7 @@ class PageGroupItem
virtual void checkEvents() {}
void setTitle(std::string value) { title = std::move(value); }
void setTitle(const std::string& value) { title = std::move(value); }
std::string getTitle() const { return title; }
void setIcon(EdgeTxIcon icon) { this->icon = icon; }
@@ -25,7 +25,7 @@
#include "../../storage/yaml/yaml_bits.h"
#include "../../storage/yaml/yaml_tree_walker.h"
#include "etx_lv_theme.h"
#include "topbar_impl.h"
#include "topbar.h"
#include "view_main.h"
#include "storage/sdcard_yaml.h"
#include "lib_file.h"
@@ -429,7 +429,7 @@ bool ThemePersistance::deleteThemeByIndex(int index)
return false;
}
bool ThemePersistance::createNewTheme(std::string name, ThemeFile& theme)
bool ThemePersistance::createNewTheme(const std::string& name, ThemeFile& theme)
{
char fullPath[FF_MAX_LFN + 1];
char* s = strAppend(fullPath, THEMES_PATH, FF_MAX_LFN);
@@ -64,10 +64,10 @@ class ThemeFile
return nullptr;
}
void setName(std::string name) { this->name = name; }
void setAuthor(std::string author) { this->author = author; }
void setInfo(std::string info) { this->info = info; }
void setPath(std::string path) { this->path = path; }
void setName(const std::string& name) { this->name = name; }
void setAuthor(const std::string& author) { this->author = author; }
void setInfo(const std::string& info) { this->info = info; }
void setPath(const std::string& path) { this->path = path; }
std::vector<ColorEntry>& getColorList() { return colorList; }
void setColor(LcdColorIndex colorIndex, uint32_t color);
@@ -107,7 +107,7 @@ class ThemePersistance
void setDefaultTheme(int index);
static char **getColorNames();
bool deleteThemeByIndex(int index);
bool createNewTheme(std::string name, ThemeFile &theme);
bool createNewTheme(const std::string& name, ThemeFile &theme);
std::vector<std::string> getNames()
{
+20 -16
View File
@@ -26,8 +26,8 @@ class GaugeWidget : public Widget
{
public:
GaugeWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect,
Widget::PersistentData* persistentData) :
Widget(factory, parent, rect, persistentData)
int screenNum, int zoneNum) :
Widget(factory, parent, rect, screenNum, zoneNum)
{
delayLoad();
}
@@ -60,9 +60,11 @@ class GaugeWidget : public Widget
int16_t getGuageValue()
{
mixsrc_t index = persistentData->options[0].value.unsignedValue;
int32_t min = persistentData->options[1].value.signedValue;
int32_t max = persistentData->options[2].value.signedValue;
auto widgetData = getPersistentData();
mixsrc_t index = widgetData->options[0].value.unsignedValue;
int32_t min = widgetData->options[1].value.signedValue;
int32_t max = widgetData->options[2].value.signedValue;
int32_t value = getValue(index);
@@ -80,7 +82,9 @@ class GaugeWidget : public Widget
{
if (!loaded) return;
mixsrc_t index = persistentData->options[0].value.unsignedValue;
auto widgetData = getPersistentData();
mixsrc_t index = widgetData->options[0].value.unsignedValue;
sourceText->setText(getSourceString(index));
if (width() < ALIGN_MAX_W)
@@ -88,10 +92,10 @@ class GaugeWidget : public Widget
else
lv_obj_clear_state(valueText->getLvObj(), LV_STATE_USER_1);
etx_bg_color_from_flags(bar, persistentData->options[3].value.unsignedValue);
etx_bg_color_from_flags(bar, widgetData->options[3].value.unsignedValue);
}
static const ZoneOption options[];
static const WidgetOption options[];
protected:
int16_t lastValue = -10000;
@@ -118,14 +122,14 @@ class GaugeWidget : public Widget
static LAYOUT_VAL_SCALED(ALIGN_MAX_W, 90)
};
const ZoneOption GaugeWidget::options[] = {
{STR_SOURCE, ZoneOption::Source, OPTION_VALUE_UNSIGNED(1)},
{STR_MIN, ZoneOption::Integer, OPTION_VALUE_SIGNED(-RESX),
OPTION_VALUE_SIGNED(-RESX), OPTION_VALUE_SIGNED(RESX)},
{STR_MAX, ZoneOption::Integer, OPTION_VALUE_SIGNED(RESX),
OPTION_VALUE_SIGNED(-RESX), OPTION_VALUE_SIGNED(RESX)},
{STR_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_WARNING_INDEX)},
{nullptr, ZoneOption::Bool}};
const WidgetOption GaugeWidget::options[] = {
{STR_SOURCE, WidgetOption::Source, 1},
{STR_MIN, WidgetOption::Integer, WIDGET_OPTION_VALUE_SIGNED(-RESX),
WIDGET_OPTION_VALUE_SIGNED(-RESX), WIDGET_OPTION_VALUE_SIGNED(RESX)},
{STR_MAX, WidgetOption::Integer, WIDGET_OPTION_VALUE_SIGNED(RESX),
WIDGET_OPTION_VALUE_SIGNED(-RESX), WIDGET_OPTION_VALUE_SIGNED(RESX)},
{STR_COLOR, WidgetOption::Color, COLOR2FLAGS(COLOR_THEME_WARNING_INDEX)},
{nullptr, WidgetOption::Bool}};
BaseWidgetFactory<GaugeWidget> gaugeWidget("Gauge", GaugeWidget::options,
STR_WIDGET_GAUGE);
+18 -17
View File
@@ -29,10 +29,9 @@
class ModelBitmapWidget : public Widget
{
public:
ModelBitmapWidget(const WidgetFactory* factory, Window* parent,
const rect_t& rect,
Widget::PersistentData* persistentData) :
Widget(factory, parent, rect, persistentData)
ModelBitmapWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect,
int screenNum, int zoneNum) :
Widget(factory, parent, rect, screenNum, zoneNum)
{
etx_obj_add_style(lvobj, styles->bg_opacity_transparent, LV_PART_MAIN);
etx_obj_add_style(lvobj, styles->bg_opacity_cover,
@@ -71,18 +70,20 @@ class ModelBitmapWidget : public Widget
{
if (!loaded) return;
auto widgetData = getPersistentData();
isLarge = rect.h >= LARGE_H && rect.w >= LARGE_W;
// get font size from options[1]
etx_font(label->getLvObj(),
(FontIndex)persistentData->options[1].value.unsignedValue);
(FontIndex)widgetData->options[1].value.unsignedValue);
// set font colour from options[0], if use theme color option off
if (persistentData->options[4].value.boolValue) {
if (widgetData->options[4].value.boolValue) {
etx_txt_color(label->getLvObj(), COLOR_THEME_SECONDARY1_INDEX,
LV_PART_MAIN);
} else {
etx_txt_color_from_flags(label->getLvObj(), persistentData->options[0].value.unsignedValue);
etx_txt_color_from_flags(label->getLvObj(), widgetData->options[0].value.unsignedValue);
}
// Set label position
@@ -92,10 +93,10 @@ class ModelBitmapWidget : public Widget
lv_obj_set_pos(label->getLvObj(), 0, 0);
// get fill color from options[3]
etx_bg_color_from_flags(lvobj, persistentData->options[3].value.unsignedValue);
etx_bg_color_from_flags(lvobj, widgetData->options[3].value.unsignedValue);
// Set background opacity from options[2]
if (persistentData->options[2].value.boolValue)
if (widgetData->options[2].value.boolValue)
lv_obj_add_state(lvobj, ETX_STATE_BG_FILL);
else
lv_obj_clear_state(lvobj, ETX_STATE_BG_FILL);
@@ -126,7 +127,7 @@ class ModelBitmapWidget : public Widget
label->show(isLarge || !image->hasImage());
}
static const ZoneOption options[];
static const WidgetOption options[];
protected:
bool isLarge = false;
@@ -143,13 +144,13 @@ class ModelBitmapWidget : public Widget
static LAYOUT_VAL_SCALED(LARGE_IMG_H, 38)
};
const ZoneOption ModelBitmapWidget::options[] = {
{STR_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX)},
{STR_SIZE, ZoneOption::TextSize, OPTION_VALUE_UNSIGNED(FONT_STD_INDEX)},
{STR_FILL_BACKGROUND, ZoneOption::Bool, OPTION_VALUE_BOOL(false)},
{STR_BG_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX)},
{STR_USE_THEME_COLOR, ZoneOption::Bool, OPTION_VALUE_BOOL(true)},
{nullptr, ZoneOption::Bool}};
const WidgetOption ModelBitmapWidget::options[] = {
{STR_COLOR, WidgetOption::Color, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX)},
{STR_SIZE, WidgetOption::TextSize, FONT_STD_INDEX},
{STR_FILL_BACKGROUND, WidgetOption::Bool, false},
{STR_BG_COLOR, WidgetOption::Color, COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX)},
{STR_USE_THEME_COLOR, WidgetOption::Bool, true},
{nullptr, WidgetOption::Bool}};
BaseWidgetFactory<ModelBitmapWidget> modelBitmapWidget(
"ModelBmp", ModelBitmapWidget::options, STR_WIDGET_MODELBMP);
+18 -17
View File
@@ -162,9 +162,9 @@ class ChannelValue : public Window
class OutputsWidget : public Widget
{
public:
OutputsWidget(const WidgetFactory* factory, Window* parent,
const rect_t& rect, Widget::PersistentData* persistentData) :
Widget(factory, parent, rect, persistentData)
OutputsWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect,
int screenNum, int zoneNum) :
Widget(factory, parent, rect, screenNum, zoneNum)
{
padAll(PAD_ZERO);
@@ -180,11 +180,13 @@ class OutputsWidget : public Widget
void update() override
{
auto widgetData = getPersistentData();
// get background color from options[2]
etx_bg_color_from_flags(lvobj, persistentData->options[2].value.unsignedValue);
etx_bg_color_from_flags(lvobj, widgetData->options[2].value.unsignedValue);
// Set background opacity from options[1]
if (persistentData->options[1].value.boolValue)
if (widgetData->options[1].value.boolValue)
lv_obj_add_state(lvobj, ETX_STATE_BG_FILL);
else
lv_obj_clear_state(lvobj, ETX_STATE_BG_FILL);
@@ -195,13 +197,13 @@ class OutputsWidget : public Widget
bool changed = false;
// Colors
LcdFlags f = persistentData->options[3].value.unsignedValue;
LcdFlags f = widgetData->options[3].value.unsignedValue;
if (f != txtColor) { txtColor = f; changed = true; }
f = persistentData->options[4].value.unsignedValue;
f = widgetData->options[4].value.unsignedValue;
if (f != barColor) { barColor = f; changed = true; }
// Setup channels
uint8_t chan = persistentData->options[0].value.unsignedValue;
uint8_t chan = widgetData->options[0].value.unsignedValue;
if (chan != firstChan) { firstChan= chan; changed = true; }
// Get size
@@ -225,7 +227,7 @@ class OutputsWidget : public Widget
}
}
static const ZoneOption options[];
static const WidgetOption options[];
protected:
coord_t lastWidth = -1;
@@ -242,14 +244,13 @@ class OutputsWidget : public Widget
static LAYOUT_VAL_SCALED(COLS_MIN_W, 300)
};
const ZoneOption OutputsWidget::options[] = {
{STR_FIRST_CHANNEL, ZoneOption::Integer, OPTION_VALUE_UNSIGNED(1),
OPTION_VALUE_UNSIGNED(1), OPTION_VALUE_UNSIGNED(32)},
{STR_FILL_BACKGROUND, ZoneOption::Bool, OPTION_VALUE_BOOL(false)},
{STR_BG_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX)},
{STR_TEXT_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_PRIMARY1_INDEX)},
{STR_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX)},
{nullptr, ZoneOption::Bool}};
const WidgetOption OutputsWidget::options[] = {
{STR_FIRST_CHANNEL, WidgetOption::Integer, {1}, {1}, {32}},
{STR_FILL_BACKGROUND, WidgetOption::Bool, false},
{STR_BG_COLOR, WidgetOption::Color, COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX)},
{STR_TEXT_COLOR, WidgetOption::Color, COLOR2FLAGS(COLOR_THEME_PRIMARY1_INDEX)},
{STR_COLOR, WidgetOption::Color, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX)},
{nullptr, WidgetOption::Bool}};
BaseWidgetFactory<OutputsWidget> outputsWidget("Outputs",
OutputsWidget::options,
+30 -27
View File
@@ -23,14 +23,14 @@
#include "edgetx.h"
#include "theme_manager.h"
#include "widget.h"
#include "widgets_container_impl.h"
#include "layout.h"
class TopBarWidget : public Widget
{
public:
TopBarWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect,
Widget::PersistentData* persistentData) :
Widget(factory, parent, rect, persistentData)
int screenNum, int zoneNum) :
Widget(factory, parent, rect, screenNum, zoneNum)
{
}
};
@@ -38,9 +38,9 @@ class TopBarWidget : public Widget
class RadioInfoWidget : public TopBarWidget
{
public:
RadioInfoWidget(const WidgetFactory* factory, Window* parent,
const rect_t& rect, Widget::PersistentData* persistentData) :
TopBarWidget(factory, parent, rect, persistentData)
RadioInfoWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect,
int screenNum, int zoneNum) :
TopBarWidget(factory, parent, rect, screenNum, zoneNum)
{
// Logs
logsIcon = new StaticIcon(this, W_LOG_X, PAD_THREE, ICON_DOT,
@@ -113,10 +113,12 @@ class RadioInfoWidget : public TopBarWidget
void update() override
{
auto widgetData = getPersistentData();
// get colors from options
etx_bg_color_from_flags(batteryFill, persistentData->options[2].value.unsignedValue, LV_PART_MAIN);
etx_bg_color_from_flags(batteryFill, persistentData->options[1].value.unsignedValue, LV_STATE_USER_1);
etx_bg_color_from_flags(batteryFill, persistentData->options[0].value.unsignedValue, LV_STATE_USER_2);
etx_bg_color_from_flags(batteryFill, widgetData->options[2].value.unsignedValue, LV_PART_MAIN);
etx_bg_color_from_flags(batteryFill, widgetData->options[1].value.unsignedValue, LV_STATE_USER_1);
etx_bg_color_from_flags(batteryFill, widgetData->options[0].value.unsignedValue, LV_STATE_USER_2);
}
void checkEvents() override
@@ -189,7 +191,7 @@ class RadioInfoWidget : public TopBarWidget
}
}
static const ZoneOption options[];
static const WidgetOption options[];
static constexpr coord_t W_AUDIO_X = 0;
static LAYOUT_VAL_SCALED(W_AUDIO_SCALE_X, 15)
@@ -229,11 +231,11 @@ class RadioInfoWidget : public TopBarWidget
#endif
};
const ZoneOption RadioInfoWidget::options[] = {
{STR_LOW_BATT_COLOR, ZoneOption::Color, RGB2FLAGS(0xF4, 0x43, 0x36)},
{STR_MID_BATT_COLOR, ZoneOption::Color, RGB2FLAGS(0xFF, 0xC1, 0x07)},
{STR_HIGH_BATT_COLOR, ZoneOption::Color, RGB2FLAGS(0x4C, 0xAF, 0x50)},
{nullptr, ZoneOption::Bool}};
const WidgetOption RadioInfoWidget::options[] = {
{STR_LOW_BATT_COLOR, WidgetOption::Color, RGB2FLAGS(0xF4, 0x43, 0x36)},
{STR_MID_BATT_COLOR, WidgetOption::Color, RGB2FLAGS(0xFF, 0xC1, 0x07)},
{STR_HIGH_BATT_COLOR, WidgetOption::Color, RGB2FLAGS(0x4C, 0xAF, 0x50)},
{nullptr, WidgetOption::Bool}};
BaseWidgetFactory<RadioInfoWidget> RadioInfoWidget("Radio Info", RadioInfoWidget::options,
STR_RADIO_INFO_WIDGET);
@@ -241,9 +243,9 @@ BaseWidgetFactory<RadioInfoWidget> RadioInfoWidget("Radio Info", RadioInfoWidget
class DateTimeWidget : public TopBarWidget
{
public:
DateTimeWidget(const WidgetFactory* factory, Window* parent,
const rect_t& rect, Widget::PersistentData* persistentData) :
TopBarWidget(factory, parent, rect, persistentData)
DateTimeWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect,
int screenNum, int zoneNum) :
TopBarWidget(factory, parent, rect, screenNum, zoneNum)
{
coord_t x = rect.w - HeaderDateTime::HDR_DATE_WIDTH - DT_XO;
dateTime = new HeaderDateTime(this, x, PAD_THREE);
@@ -252,9 +254,11 @@ class DateTimeWidget : public TopBarWidget
void update() override
{
auto widgetData = getPersistentData();
// get color from options
uint32_t color;
memcpy(&color, &persistentData->options[0].value.unsignedValue, sizeof(color));
memcpy(&color, &widgetData->options[0].value.unsignedValue, sizeof(color));
dateTime->setColor(color);
coord_t x = width() - HeaderDateTime::HDR_DATE_WIDTH - DT_XO;
dateTime->setPos(x, PAD_THREE);
@@ -263,15 +267,15 @@ class DateTimeWidget : public TopBarWidget
HeaderDateTime* dateTime = nullptr;
int8_t lastMinute = -1;
static const ZoneOption options[];
static const WidgetOption options[];
// Adjustment to make main view date/time align with model/radio settings views
static LAYOUT_VAL_SCALED(DT_XO, 1)
};
const ZoneOption DateTimeWidget::options[] = {
{STR_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_PRIMARY2_INDEX)},
{nullptr, ZoneOption::Bool}};
const WidgetOption DateTimeWidget::options[] = {
{STR_COLOR, WidgetOption::Color, COLOR2FLAGS(COLOR_THEME_PRIMARY2_INDEX)},
{nullptr, WidgetOption::Bool}};
BaseWidgetFactory<DateTimeWidget> DateTimeWidget("Date Time",
DateTimeWidget::options,
@@ -282,10 +286,9 @@ BaseWidgetFactory<DateTimeWidget> DateTimeWidget("Date Time",
class InternalGPSWidget : public TopBarWidget
{
public:
InternalGPSWidget(const WidgetFactory* factory, Window* parent,
const rect_t& rect,
Widget::PersistentData* persistentData) :
TopBarWidget(factory, parent, rect, persistentData)
InternalGPSWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect,
int screenNum, int zoneNum) :
TopBarWidget(factory, parent, rect, screenNum, zoneNum)
{
icon =
new StaticIcon(this, width() / 2 - PAD_LARGE - PAD_TINY, ICON_H,
+20 -19
View File
@@ -22,15 +22,14 @@
#include "edgetx.h"
#include "widget.h"
#define TEXT_WIDGET_DEFAULT_LABEL \
'M', 'y', ' ', 'L', 'a', 'b', 'e', 'l' // "My Label"
#define TEXT_WIDGET_DEFAULT_LABEL "My Label"
class TextWidget : public Widget
{
public:
TextWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect,
Widget::PersistentData* persistentData) :
Widget(factory, parent, rect, persistentData)
int screenNum, int zoneNum) :
Widget(factory, parent, rect, screenNum, zoneNum)
{
delayLoad();
}
@@ -52,7 +51,7 @@ class TextWidget : public Widget
update();
}
static const ZoneOption options[];
static const WidgetOption options[];
protected:
lv_style_t style;
@@ -63,38 +62,40 @@ class TextWidget : public Widget
{
if (!loaded) return;
auto widgetData = getPersistentData();
// Set text value from options
lv_label_set_text(shadow, persistentData->options[0].value.stringValue);
lv_label_set_text(label, persistentData->options[0].value.stringValue);
lv_label_set_text(shadow, widgetData->options[0].value.stringValue.c_str());
lv_label_set_text(label, widgetData->options[0].value.stringValue.c_str());
// get font color from options[1]
etx_txt_color_from_flags(label, persistentData->options[1].value.unsignedValue);
etx_txt_color_from_flags(label, widgetData->options[1].value.unsignedValue);
// get font size from options[2]
lv_style_set_text_font(
&style, getFont(persistentData->options[2].value.unsignedValue << 8));
&style, getFont(widgetData->options[2].value.unsignedValue << 8));
// get alignment from options[4]
LcdFlags alignment = persistentData->options[4].value.unsignedValue;
LcdFlags alignment = widgetData->options[4].value.unsignedValue;
lv_style_set_text_align(&style,
(alignment == ALIGN_RIGHT) ? LV_TEXT_ALIGN_RIGHT
: (alignment == ALIGN_CENTER) ? LV_TEXT_ALIGN_CENTER
: LV_TEXT_ALIGN_LEFT);
// Show or hide shadow
if (persistentData->options[3].value.boolValue)
if (widgetData->options[3].value.boolValue)
lv_obj_clear_flag(shadow, LV_OBJ_FLAG_HIDDEN);
else
lv_obj_add_flag(shadow, LV_OBJ_FLAG_HIDDEN);
}
};
const ZoneOption TextWidget::options[] = {
{STR_TEXT, ZoneOption::String,
OPTION_VALUE_STRING(TEXT_WIDGET_DEFAULT_LABEL)},
{STR_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX)},
{STR_SIZE, ZoneOption::TextSize, OPTION_VALUE_UNSIGNED(0)},
{STR_SHADOW, ZoneOption::Bool, OPTION_VALUE_BOOL(false)},
{STR_ALIGNMENT, ZoneOption::Align, OPTION_VALUE_UNSIGNED(ALIGN_LEFT)},
{nullptr, ZoneOption::Bool}};
const WidgetOption TextWidget::options[] = {
{STR_TEXT, WidgetOption::String,
WIDGET_OPTION_VALUE_STRING(TEXT_WIDGET_DEFAULT_LABEL)},
{STR_COLOR, WidgetOption::Color, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX)},
{STR_SIZE, WidgetOption::TextSize, 0},
{STR_SHADOW, WidgetOption::Bool, false},
{STR_ALIGNMENT, WidgetOption::Align, ALIGN_LEFT},
{nullptr, WidgetOption::Bool}};
BaseWidgetFactory<TextWidget> textWidget("Text", TextWidget::options,
STR_WIDGET_TEXT);
+12 -8
View File
@@ -33,8 +33,8 @@ class TimerWidget : public Widget
{
public:
TimerWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect,
Widget::PersistentData* persistentData) :
Widget(factory, parent, rect, persistentData)
int screenNum, int zoneNum) :
Widget(factory, parent, rect, screenNum, zoneNum)
{
delayLoad();
}
@@ -109,7 +109,9 @@ class TimerWidget : public Widget
Widget::checkEvents();
uint32_t index = persistentData->options[0].value.unsignedValue;
auto widgetData = getPersistentData();
uint32_t index = widgetData->options[0].value.unsignedValue;
TimerData& timerData = g_model.timers[index];
TimerState& timerState = timersStates[index];
@@ -196,7 +198,7 @@ class TimerWidget : public Widget
}
}
static const ZoneOption options[];
static const WidgetOption options[];
static LAYOUT_VAL_SCALED(SMALL_TXT_MAX_W, 100)
static LAYOUT_VAL_SCALED(SMALL_TXT_MAX_H, 40)
@@ -236,10 +238,12 @@ class TimerWidget : public Widget
{
if (!loaded) return;
auto widgetData = getPersistentData();
// Set up widget from options.
char s[16];
uint32_t index = persistentData->options[0].value.unsignedValue;
uint32_t index = widgetData->options[0].value.unsignedValue;
TimerData& timerData = g_model.timers[index];
bool hasName = ZLEN(timerData.name) > 0;
@@ -304,9 +308,9 @@ class TimerWidget : public Widget
}
};
const ZoneOption TimerWidget::options[] = {
{STR_TIMER_SOURCE, ZoneOption::Timer, OPTION_VALUE_UNSIGNED(0)},
{nullptr, ZoneOption::Bool}};
const WidgetOption TimerWidget::options[] = {
{STR_TIMER_SOURCE, WidgetOption::Timer, 0},
{nullptr, WidgetOption::Bool}};
BaseWidgetFactory<TimerWidget> timerWidget("Timer", TimerWidget::options,
STR_WIDGET_TIMER);
+21 -17
View File
@@ -30,8 +30,8 @@ class ValueWidget : public Widget
{
public:
ValueWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect,
Widget::PersistentData* persistentData) :
Widget(factory, parent, rect, persistentData)
int screenNum, int zoneNum) :
Widget(factory, parent, rect, screenNum, zoneNum)
{
delayLoad();
}
@@ -82,8 +82,10 @@ class ValueWidget : public Widget
bool changed = false;
auto widgetData = getPersistentData();
// get source from options[0]
mixsrc_t field = persistentData->options[0].value.unsignedValue;
mixsrc_t field = widgetData->options[0].value.unsignedValue;
// if value changed
auto newValue = getValue(field);
@@ -166,7 +168,7 @@ class ValueWidget : public Widget
}
}
static const ZoneOption options[];
static const WidgetOption options[];
protected:
int32_t lastValue = -10000;
@@ -188,18 +190,20 @@ class ValueWidget : public Widget
{
if (!loaded) return;
auto widgetData = getPersistentData();
// get source from options[0]
mixsrc_t field = persistentData->options[0].value.unsignedValue;
mixsrc_t field = widgetData->options[0].value.unsignedValue;
// get color from options[1]
etx_txt_color_from_flags(label, persistentData->options[1].value.unsignedValue);
etx_txt_color_from_flags(value, persistentData->options[1].value.unsignedValue);
etx_txt_color_from_flags(label, widgetData->options[1].value.unsignedValue);
etx_txt_color_from_flags(value, widgetData->options[1].value.unsignedValue);
// get label alignment from options[3]
LcdFlags lblAlign = persistentData->options[3].value.unsignedValue;
LcdFlags lblAlign = widgetData->options[3].value.unsignedValue;
// get value alignment from options[4]
LcdFlags valAlign = persistentData->options[4].value.unsignedValue;
LcdFlags valAlign = widgetData->options[4].value.unsignedValue;
lv_coord_t labelX = 0;
lv_coord_t labelY = 0;
@@ -270,7 +274,7 @@ class ValueWidget : public Widget
lv_obj_set_pos(value, valueX, valueY);
// Show / hide shadow
if (persistentData->options[2].value.boolValue) {
if (widgetData->options[2].value.boolValue) {
lv_obj_clear_flag(labelShadow, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(valueShadow, LV_OBJ_FLAG_HIDDEN);
} else {
@@ -280,13 +284,13 @@ class ValueWidget : public Widget
}
};
const ZoneOption ValueWidget::options[] = {
{STR_SOURCE, ZoneOption::Source, OPTION_VALUE_UNSIGNED(MIXSRC_FIRST_STICK)},
{STR_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_PRIMARY2_INDEX)},
{STR_SHADOW, ZoneOption::Bool, OPTION_VALUE_BOOL(false)},
{STR_ALIGN_LABEL, ZoneOption::Align, OPTION_VALUE_UNSIGNED(ALIGN_LEFT)},
{STR_ALIGN_VALUE, ZoneOption::Align, OPTION_VALUE_UNSIGNED(ALIGN_LEFT)},
{nullptr, ZoneOption::Bool}};
const WidgetOption ValueWidget::options[] = {
{STR_SOURCE, WidgetOption::Source, MIXSRC_FIRST_STICK},
{STR_COLOR, WidgetOption::Color, COLOR2FLAGS(COLOR_THEME_PRIMARY2_INDEX)},
{STR_SHADOW, WidgetOption::Bool, false},
{STR_ALIGN_LABEL, WidgetOption::Align, ALIGN_LEFT},
{STR_ALIGN_VALUE, WidgetOption::Align, ALIGN_LEFT},
{nullptr, WidgetOption::Bool}};
BaseWidgetFactory<ValueWidget> ValueWidget("Value", ValueWidget::options,
STR_WIDGET_VALUE);