some clean-up (more to follow)
This commit is contained in:
@@ -21,6 +21,8 @@
|
|||||||
// No include guards here, this file may be included many times in different namespaces
|
// No include guards here, this file may be included many times in different namespaces
|
||||||
// i.e. BACKUP RAM Backup/Restore functions
|
// i.e. BACKUP RAM Backup/Restore functions
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "dataconstants.h"
|
#include "dataconstants.h"
|
||||||
@@ -986,4 +988,4 @@ static inline void check_struct()
|
|||||||
|
|
||||||
#undef CHKSIZE
|
#undef CHKSIZE
|
||||||
}
|
}
|
||||||
#endif /* BACKUP */
|
#endif /* BACKUP */
|
||||||
|
|||||||
@@ -34,7 +34,14 @@ void ScreenMenu::updateTabs()
|
|||||||
|
|
||||||
for (int index = 0; index < MAX_CUSTOM_SCREENS; index++) {
|
for (int index = 0; index < MAX_CUSTOM_SCREENS; index++) {
|
||||||
if (customScreens[index]) {
|
if (customScreens[index]) {
|
||||||
addTab(new ScreenSetupPage(this, index));
|
|
||||||
|
auto tab = new ScreenSetupPage(this, customScreens[index], g_model.screenData[index]);
|
||||||
|
std::string title(STR_MAIN_VIEW_X);
|
||||||
|
title.back() = index + '1';
|
||||||
|
tab->setTitle(title);
|
||||||
|
tab->setIcon(ICON_THEME_VIEW1 + index);
|
||||||
|
|
||||||
|
addTab(tab);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
addTab(new ScreenAddPage(this, index));
|
addTab(new ScreenAddPage(this, index));
|
||||||
|
|||||||
@@ -26,23 +26,38 @@
|
|||||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||||
|
|
||||||
ScreenAddPage::ScreenAddPage(ScreenMenu * menu, uint8_t pageIndex):
|
ScreenAddPage::ScreenAddPage(ScreenMenu * menu, uint8_t pageIndex):
|
||||||
PageTab("", ICON_THEME_ADD_VIEW),
|
PageTab(),
|
||||||
menu(menu),
|
menu(menu),
|
||||||
pageIndex(pageIndex)
|
pageIndex(pageIndex)
|
||||||
{
|
{
|
||||||
setTitle(STR_ADD_MAIN_VIEW);
|
setTitle(STR_ADD_MAIN_VIEW);
|
||||||
|
setIcon(ICON_THEME_ADD_VIEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenAddPage::build(FormWindow * window)
|
void ScreenAddPage::build(FormWindow * window)
|
||||||
{
|
{
|
||||||
auto button = new TextButton(window, {LCD_W / 2 - 100, (window->height() - 24) / 2, 200, 24}, STR_ADD_MAIN_VIEW);
|
rect_t buttonRect = {LCD_W / 2 - 100, (window->height() - 24) / 2, 200, 24};
|
||||||
|
auto button = new TextButton(window, buttonRect, STR_ADD_MAIN_VIEW);
|
||||||
button->setPressHandler([=]() {
|
button->setPressHandler([=]() {
|
||||||
|
|
||||||
|
auto& screen = customScreens[pageIndex];
|
||||||
|
auto& screenData = g_model.screenData[pageIndex];
|
||||||
|
|
||||||
const LayoutFactory * factory = getRegisteredLayouts().front();
|
const LayoutFactory * factory = getRegisteredLayouts().front();
|
||||||
customScreens[pageIndex] = factory->create(&g_model.screenData[pageIndex].layoutData);
|
|
||||||
strncpy(g_model.screenData[pageIndex].layoutName, factory->getId(), sizeof(g_model.screenData[pageIndex].layoutName));
|
screen = factory->create(&screenData.layoutData);
|
||||||
|
strncpy(screenData.layoutName, factory->getId(), sizeof(screenData.layoutName));
|
||||||
|
|
||||||
|
auto tab = new ScreenSetupPage(menu, screen, screenData);
|
||||||
|
std::string title(STR_MAIN_VIEW_X);
|
||||||
|
title.back() = pageIndex + '0';
|
||||||
|
tab->setTitle(title);
|
||||||
|
tab->setIcon(ICON_THEME_VIEW1 + pageIndex);
|
||||||
|
|
||||||
menu->removeTab(pageIndex);
|
menu->removeTab(pageIndex);
|
||||||
menu->addTab(new ScreenSetupPage(menu, pageIndex));
|
menu->addTab(tab);
|
||||||
menu->setCurrentTab(pageIndex);
|
menu->setCurrentTab(pageIndex);
|
||||||
|
|
||||||
if (pageIndex < MAX_CUSTOM_SCREENS - 1) {
|
if (pageIndex < MAX_CUSTOM_SCREENS - 1) {
|
||||||
menu->addTab(new ScreenAddPage(menu, pageIndex + 1));
|
menu->addTab(new ScreenAddPage(menu, pageIndex + 1));
|
||||||
}
|
}
|
||||||
@@ -124,22 +139,20 @@ class LayoutChoice: public FormField {
|
|||||||
std::function<void(const LayoutFactory *)> setValue;
|
std::function<void(const LayoutFactory *)> setValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
ScreenSetupPage::ScreenSetupPage(ScreenMenu * menu, uint8_t pageIndex):
|
ScreenSetupPage::ScreenSetupPage(ScreenMenu * menu, Layout*& screen, CustomScreenData& screenData):
|
||||||
PageTab("", ICON_THEME_VIEW1 + pageIndex),
|
PageTab(),
|
||||||
menu(menu),
|
menu(menu),
|
||||||
pageIndex(pageIndex)
|
screen(screen),
|
||||||
|
screenData(screenData)
|
||||||
{
|
{
|
||||||
char title[] = "Main view X";
|
|
||||||
title[sizeof(title) - 2] = '1' + pageIndex;
|
|
||||||
setTitle(title);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class SetupWidgetsPageSlot: public Button
|
class SetupWidgetsPageSlot: public Button
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SetupWidgetsPageSlot(FormGroup * parent, const rect_t & rect, uint8_t pageIndex, uint8_t slotIndex):
|
SetupWidgetsPageSlot(FormGroup * parent, const rect_t & rect, Layout* screen, uint8_t slotIndex):
|
||||||
Button(parent, rect),
|
Button(parent, rect),
|
||||||
pageIndex(pageIndex),
|
screen(screen),
|
||||||
slotIndex(slotIndex)
|
slotIndex(slotIndex)
|
||||||
{
|
{
|
||||||
setPressHandler([=](){
|
setPressHandler([=](){
|
||||||
@@ -152,7 +165,7 @@ class SetupWidgetsPageSlot: public Button
|
|||||||
widget->deleteLater();
|
widget->deleteLater();
|
||||||
}
|
}
|
||||||
// widget = factory->create(this, {1, 1, width() - 2, height() - 2}, &g_model.screenData[pageIndex].layoutData.zones[slotIndex].widgetData, true);
|
// widget = factory->create(this, {1, 1, width() - 2, height() - 2}, &g_model.screenData[pageIndex].layoutData.zones[slotIndex].widgetData, true);
|
||||||
customScreens[pageIndex]->createWidget(slotIndex, factory);
|
screen->createWidget(slotIndex, factory);
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -180,7 +193,7 @@ class SetupWidgetsPageSlot: public Button
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8_t pageIndex;
|
Layout * screen;
|
||||||
uint8_t slotIndex;
|
uint8_t slotIndex;
|
||||||
Window * widget = nullptr;
|
Window * widget = nullptr;
|
||||||
};
|
};
|
||||||
@@ -188,18 +201,16 @@ class SetupWidgetsPageSlot: public Button
|
|||||||
class SetupWidgetsPage: public FormWindow
|
class SetupWidgetsPage: public FormWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SetupWidgetsPage(uint8_t pageIndex):
|
SetupWidgetsPage(Layout * screen):
|
||||||
FormWindow(MainWindow::instance(), {0, 0, LCD_W, LCD_H}, OPAQUE | FORM_FORWARD_FOCUS),
|
FormWindow(MainWindow::instance(), {0, 0, LCD_W, LCD_H}, OPAQUE | FORM_FORWARD_FOCUS),
|
||||||
pageIndex(pageIndex)
|
screen(screen)
|
||||||
{
|
{
|
||||||
Layer::push(this);
|
Layer::push(this);
|
||||||
clearFocus();
|
clearFocus();
|
||||||
|
|
||||||
auto & customScreen = customScreens[pageIndex];
|
for (unsigned i = 0; i < screen->getZonesCount(); i++) {
|
||||||
|
auto rect = screen->getZone(i);
|
||||||
for (unsigned i = 0; i < customScreen->getZonesCount(); i++) {
|
new SetupWidgetsPageSlot(this, {rect.x - 1, rect.y - 1, rect.w + 2, rect.h + 2}, screen, i);
|
||||||
auto rect = customScreen->getZone(i);
|
|
||||||
new SetupWidgetsPageSlot(this, {rect.x - 1, rect.y - 1, rect.w + 2, rect.h + 2}, pageIndex, i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,7 +244,7 @@ class SetupWidgetsPage: public FormWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8_t pageIndex;
|
Layout* screen;
|
||||||
};
|
};
|
||||||
|
|
||||||
void ScreenSetupPage::build(FormWindow * window)
|
void ScreenSetupPage::build(FormWindow * window)
|
||||||
@@ -245,10 +256,10 @@ void ScreenSetupPage::build(FormWindow * window)
|
|||||||
new StaticText(window, grid.getLabelSlot(false), STR_LAYOUT);
|
new StaticText(window, grid.getLabelSlot(false), STR_LAYOUT);
|
||||||
auto layoutSlot = grid.getFieldSlot();
|
auto layoutSlot = grid.getFieldSlot();
|
||||||
layoutSlot.h = 2 * PAGE_LINE_HEIGHT - 1;
|
layoutSlot.h = 2 * PAGE_LINE_HEIGHT - 1;
|
||||||
layoutChoice = new LayoutChoice(window, layoutSlot, GET_VALUE(customScreens[pageIndex]->getFactory()), [=](const LayoutFactory *factory) {
|
layoutChoice = new LayoutChoice(window, layoutSlot, GET_VALUE(screen->getFactory()), [=](const LayoutFactory *factory) {
|
||||||
delete customScreens[pageIndex];
|
delete screen;
|
||||||
customScreens[pageIndex] = factory->create(&g_model.screenData[pageIndex].layoutData);
|
screen = factory->create(&screenData.layoutData);
|
||||||
strncpy(g_model.screenData[pageIndex].layoutName, factory->getId(), sizeof(g_model.screenData[pageIndex].layoutName));
|
strncpy(screenData.layoutName, factory->getId(), sizeof(CustomScreenData::layoutName));
|
||||||
SET_DIRTY();
|
SET_DIRTY();
|
||||||
updateLayoutOptions();
|
updateLayoutOptions();
|
||||||
});
|
});
|
||||||
@@ -257,7 +268,7 @@ void ScreenSetupPage::build(FormWindow * window)
|
|||||||
// Setup widgets button...
|
// Setup widgets button...
|
||||||
setupWidgetsButton = new TextButton(window, grid.getFieldSlot(), STR_SETUP_WIDGETS);
|
setupWidgetsButton = new TextButton(window, grid.getFieldSlot(), STR_SETUP_WIDGETS);
|
||||||
setupWidgetsButton->setPressHandler([=]() {
|
setupWidgetsButton->setPressHandler([=]() {
|
||||||
new SetupWidgetsPage(pageIndex);
|
new SetupWidgetsPage(screen);
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
grid.nextLine();
|
grid.nextLine();
|
||||||
@@ -273,8 +284,6 @@ void ScreenSetupPage::updateLayoutOptions()
|
|||||||
FormGridLayout grid;
|
FormGridLayout grid;
|
||||||
optionsWindow->clear();
|
optionsWindow->clear();
|
||||||
|
|
||||||
auto screen = customScreens[pageIndex];
|
|
||||||
|
|
||||||
// Layout options...
|
// Layout options...
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (auto * option = screen->getFactory()->getOptions(); option->name; option++, index++) {
|
for (auto * option = screen->getFactory()->getOptions(); option->name; option++, index++) {
|
||||||
@@ -299,19 +308,20 @@ void ScreenSetupPage::updateLayoutOptions()
|
|||||||
grid.nextLine();
|
grid.nextLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pageIndex > 0 || customScreens[1]) {
|
//if (pageIndex > 0 || customScreens[1]) {
|
||||||
auto button = new TextButton(optionsWindow, grid.getFieldSlot(), STR_REMOVE_SCREEN);
|
auto button = new TextButton(optionsWindow, grid.getFieldSlot(), STR_REMOVE_SCREEN);
|
||||||
button->setPressHandler([=]() {
|
button->setPressHandler([=]() {
|
||||||
if (pageIndex < MAX_CUSTOM_SCREENS - 1) {
|
// if (pageIndex < MAX_CUSTOM_SCREENS - 1) {
|
||||||
memmove(&g_model.screenData[pageIndex], &g_model.screenData[pageIndex + 1], sizeof(CustomScreenData) * (MAX_CUSTOM_SCREENS - pageIndex - 1));
|
// memmove(&g_model.screenData[pageIndex], &g_model.screenData[pageIndex + 1], sizeof(CustomScreenData) * (MAX_CUSTOM_SCREENS - pageIndex - 1));
|
||||||
}
|
// }
|
||||||
memset(&g_model.screenData[MAX_CUSTOM_SCREENS - 1], 0, sizeof(CustomScreenData));
|
// memset(&g_model.screenData[MAX_CUSTOM_SCREENS - 1], 0, sizeof(CustomScreenData));
|
||||||
|
memset(&screenData, 0, sizeof(CustomScreenData));
|
||||||
loadCustomScreens();
|
loadCustomScreens();
|
||||||
menu->updateTabs();
|
menu->updateTabs();
|
||||||
storageDirty(EE_MODEL);
|
storageDirty(EE_MODEL);
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
//}
|
||||||
|
|
||||||
optionsWindow->adjustHeight();
|
optionsWindow->adjustHeight();
|
||||||
optionsWindow->getParent()->adjustInnerHeight();
|
optionsWindow->getParent()->adjustInnerHeight();
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "menu_screen.h"
|
#include "menu_screen.h"
|
||||||
|
#include "layout.h"
|
||||||
|
#include "datastructs.h"
|
||||||
|
|
||||||
class ScreenAddPage: public PageTab {
|
class ScreenAddPage: public PageTab {
|
||||||
public:
|
public:
|
||||||
@@ -33,13 +35,14 @@ class ScreenAddPage: public PageTab {
|
|||||||
|
|
||||||
class ScreenSetupPage: public PageTab {
|
class ScreenSetupPage: public PageTab {
|
||||||
public:
|
public:
|
||||||
ScreenSetupPage(ScreenMenu * menu, uint8_t pageIndex);
|
ScreenSetupPage(ScreenMenu * menu, Layout*& screen, CustomScreenData& screenData);
|
||||||
|
|
||||||
void build(FormWindow * window) override;
|
void build(FormWindow * window) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ScreenMenu * menu;
|
ScreenMenu * menu;
|
||||||
uint8_t pageIndex;
|
Layout *& screen;
|
||||||
|
CustomScreenData& screenData;
|
||||||
FormGroup * optionsWindow = nullptr;
|
FormGroup * optionsWindow = nullptr;
|
||||||
TextButton * setupWidgetsButton = nullptr;
|
TextButton * setupWidgetsButton = nullptr;
|
||||||
FormField * layoutChoice = nullptr;
|
FormField * layoutChoice = nullptr;
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ class PageTab {
|
|||||||
friend class TabsGroup;
|
friend class TabsGroup;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
PageTab():
|
||||||
|
icon(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
PageTab(std::string title, unsigned icon):
|
PageTab(std::string title, unsigned icon):
|
||||||
title(std::move(title)),
|
title(std::move(title)),
|
||||||
icon(icon)
|
icon(icon)
|
||||||
@@ -64,6 +69,11 @@ class PageTab {
|
|||||||
title = std::move(value);
|
title = std::move(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setIcon(unsigned icon)
|
||||||
|
{
|
||||||
|
this->icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned getIcon() const
|
unsigned getIcon() const
|
||||||
{
|
{
|
||||||
return icon;
|
return icon;
|
||||||
|
|||||||
Reference in New Issue
Block a user