split SetupWidgetsPage

This commit is contained in:
Raphael Coeffic
2022-06-11 15:38:08 +02:00
committed by Raphael Coeffic
parent 0677c3e703
commit 7c63b86cfe
7 changed files with 229 additions and 153 deletions
+1
View File
@@ -87,6 +87,7 @@ set(GUI_SRC
view_text.cpp
menu_screen.cpp
screen_user_interface.cpp
widgets_setup.cpp
screen_setup.cpp
switch_warn_dialog.cpp
LvglWrapper.cpp
+1 -144
View File
@@ -26,12 +26,12 @@
#include "topbar.h"
#include "libopenui.h"
#include "layouts/layout_factory_impl.h"
#include "widgets_setup.h"
#define SET_DIRTY() storageDirty(EE_MODEL)
#define BUTTON_HEIGHT 30
#define BUTTON_WIDTH 75
class LayoutChoice: public FormField
{
public:
@@ -109,149 +109,6 @@ class LayoutChoice: public FormField
std::function<void(const LayoutFactory *)> setValue;
};
SetupWidgetsPageSlot::SetupWidgetsPageSlot(FormGroup * parent, const rect_t & rect, WidgetsContainer* container, uint8_t slotIndex):
Button(parent, rect)
{
setPressHandler([parent, container, slotIndex]() -> uint8_t {
Menu * menu = new Menu(parent);
menu->addLine(TR_SELECT_WIDGET, [=]() {
Menu * menu = new Menu(parent);
for (auto factory: getRegisteredWidgets()) {
menu->addLine(factory->getDisplayName(), [=]() {
container->createWidget(slotIndex, factory);
auto widget = container->getWidget(slotIndex);
if(widget->getOptions() && widget->getOptions()->name)
new WidgetSettings(parent, widget);
});
}
});
if (container->getWidget(slotIndex)) {
auto widget = container->getWidget(slotIndex);
if(widget->getOptions() && widget->getOptions()->name)
menu->addLine(TR_WIDGET_SETTINGS, [=]() {
new WidgetSettings(parent, widget);
});
menu->addLine(STR_REMOVE_WIDGET, [=]() {
container->removeWidget(slotIndex);
});
}
return 0;
});
}
void SetupWidgetsPageSlot::paint(BitmapBuffer * dc)
{
if (hasFocus()) {
dc->drawRect(0, 0, width()-1, height()-1, 2, STASHED, COLOR_THEME_FOCUS);
}
else {
dc->drawSolidRect(0, 0, width()-1, height()-1, 2, COLOR_THEME_PRIMARY3);
}
}
class SetupWidgetsPage: public FormWindow
{
public:
SetupWidgetsPage(ScreenMenu* menu, uint8_t customScreenIdx):
FormWindow(ViewMain::instance(), {0, 0, 0, 0}, FORM_FORWARD_FOCUS),
menu(menu),
customScreenIdx(customScreenIdx)
{
Layer::push(this);
// attach this custom screen here so we can display it
auto screen = customScreens[customScreenIdx];
if (screen) {
setRect(screen->getRect());
auto viewMain = ViewMain::instance();
savedView = viewMain->getCurrentMainView();
viewMain->setCurrentMainView(customScreenIdx);
viewMain->bringToTop();
}
for (unsigned i = 0; i < screen->getZonesCount(); i++) {
auto rect = screen->getZone(i);
auto widget = new SetupWidgetsPageSlot(this, rect, customScreens[customScreenIdx], i);
if (i == 0) widget->setFocus();
}
#if defined(HARDWARE_TOUCH)
new Button(
this, {0, 0, MENU_HEADER_BACK_BUTTON_WIDTH, MENU_HEADER_BACK_BUTTON_HEIGHT},
[this]() -> uint8_t {
this->deleteLater();
return 1;
},
NO_FOCUS | FORM_NO_BORDER);
#endif
}
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "SetupWidgetsPage(idx=" + std::to_string(customScreenIdx) + ")";
}
#endif
void deleteLater(bool detach = true, bool trash = true) override
{
#if defined(HARDWARE_TOUCH)
Keyboard::hide();
#endif
auto screen = customScreens[customScreenIdx];
if (screen) {
auto viewMain = ViewMain::instance();
viewMain->setCurrentMainView(savedView);
}
FormWindow::deleteLater(detach, trash);
// restore screen setting tab on top
menu->bringToTop();
Layer::pop(this);
}
#if defined(HARDWARE_TOUCH)
bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY,
coord_t slideX, coord_t slideY) override
{
FormWindow::onTouchSlide(x, y, startX, startY, slideX, slideY);
return true;
}
bool onTouchEnd(coord_t x, coord_t y) override
{
FormWindow::onTouchEnd(x, y);
return true;
}
#endif
#if defined(HARDWARE_KEYS)
void onEvent(event_t event) override
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
if (event == EVT_KEY_LONG(KEY_EXIT) || event == EVT_KEY_BREAK(KEY_EXIT)) {
killEvents(event);
deleteLater();
}
}
#endif
protected:
ScreenMenu* menu;
uint8_t customScreenIdx;
unsigned savedView = 0;
// void paint(BitmapBuffer * dc) override
// {
// //ViewMain::instance()->fullPaint(dc);
// //dc->clear(COLOR_THEME_SECONDARY3);
// }
};
ScreenAddPage::ScreenAddPage(ScreenMenu * menu, uint8_t pageIndex):
PageTab(),
menu(menu),
-8
View File
@@ -47,11 +47,3 @@ class ScreenSetupPage: public PageTab {
unsigned pageIndex;
unsigned customScreenIndex;
};
class SetupWidgetsPageSlot: public Button
{
public:
SetupWidgetsPageSlot(FormGroup * parent, const rect_t & rect, WidgetsContainer* container, uint8_t slotIndex);
void paint(BitmapBuffer * dc) override;
};
+2 -1
View File
@@ -22,10 +22,11 @@
#include "opentx.h"
#include "layer.h"
#include "view_main.h"
#include "screen_setup.h"
#include "storage/storage.h"
#include "topbar.h"
#include "topbar_impl.h"
#include "menu_screen.h"
#include "widgets_setup.h"
Topbar * TopbarFactory::create(Window * parent)
+157
View File
@@ -0,0 +1,157 @@
/*
* 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_setup.h"
#include "menu_screen.h"
#include "view_main.h"
#include "widget_settings.h"
#include "widget.h"
#include "layer.h"
#include "menu.h"
#include "gui.h"
#include "translations.h"
SetupWidgetsPageSlot::SetupWidgetsPageSlot(FormGroup* parent,
const rect_t& rect,
WidgetsContainer* container,
uint8_t slotIndex) :
Button(parent, rect)
{
setPressHandler([parent, container, slotIndex]() -> uint8_t {
Menu* menu = new Menu(parent);
menu->addLine(STR_SELECT_WIDGET, [=]() {
Menu* menu = new Menu(parent);
for (auto factory : getRegisteredWidgets()) {
menu->addLine(factory->getDisplayName(), [=]() {
container->createWidget(slotIndex, factory);
auto widget = container->getWidget(slotIndex);
if (widget->getOptions() && widget->getOptions()->name)
new WidgetSettings(parent, widget);
});
}
});
if (container->getWidget(slotIndex)) {
auto widget = container->getWidget(slotIndex);
if (widget->getOptions() && widget->getOptions()->name)
menu->addLine(STR_WIDGET_SETTINGS,
[=]() { new WidgetSettings(parent, widget); });
menu->addLine(STR_REMOVE_WIDGET,
[=]() { container->removeWidget(slotIndex); });
}
return 0;
});
}
void SetupWidgetsPageSlot::paint(BitmapBuffer* dc)
{
if (hasFocus()) {
dc->drawRect(0, 0, width() - 1, height() - 1, 2, STASHED,
COLOR_THEME_FOCUS);
} else {
dc->drawSolidRect(0, 0, width() - 1, height() - 1, 2, COLOR_THEME_PRIMARY3);
}
}
SetupWidgetsPage::SetupWidgetsPage(ScreenMenu* menu, uint8_t customScreenIdx) :
FormWindow(ViewMain::instance(), {0, 0, 0, 0}, FORM_FORWARD_FOCUS),
menu(menu),
customScreenIdx(customScreenIdx)
{
Layer::push(this);
// attach this custom screen here so we can display it
auto screen = customScreens[customScreenIdx];
if (screen) {
setRect(screen->getRect());
auto viewMain = ViewMain::instance();
savedView = viewMain->getCurrentMainView();
viewMain->setCurrentMainView(customScreenIdx);
viewMain->bringToTop();
}
for (unsigned i = 0; i < screen->getZonesCount(); i++) {
auto rect = screen->getZone(i);
auto widget =
new SetupWidgetsPageSlot(this, rect, customScreens[customScreenIdx], i);
if (i == 0) widget->setFocus();
}
#if defined(HARDWARE_TOUCH)
new Button(
this,
{0, 0, MENU_HEADER_BACK_BUTTON_WIDTH, MENU_HEADER_BACK_BUTTON_HEIGHT},
[this]() -> uint8_t {
this->deleteLater();
return 1;
},
NO_FOCUS | FORM_NO_BORDER);
#endif
}
void SetupWidgetsPage::deleteLater(bool detach, bool trash)
{
#if defined(HARDWARE_TOUCH)
Keyboard::hide();
#endif
auto screen = customScreens[customScreenIdx];
if (screen) {
auto viewMain = ViewMain::instance();
viewMain->setCurrentMainView(savedView);
}
FormWindow::deleteLater(detach, trash);
// restore screen setting tab on top
menu->bringToTop();
Layer::pop(this);
}
#if defined(HARDWARE_TOUCH)
bool SetupWidgetsPage::onTouchSlide(coord_t x, coord_t y, coord_t startX,
coord_t startY, coord_t slideX,
coord_t slideY)
{
FormWindow::onTouchSlide(x, y, startX, startY, slideX, slideY);
return true;
}
bool SetupWidgetsPage::onTouchEnd(coord_t x, coord_t y)
{
FormWindow::onTouchEnd(x, y);
return true;
}
#endif
#if defined(HARDWARE_KEYS)
void SetupWidgetsPage::onEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(),
event);
if (event == EVT_KEY_LONG(KEY_EXIT) || event == EVT_KEY_BREAK(KEY_EXIT)) {
killEvents(event);
deleteLater();
}
}
#endif
+67
View File
@@ -0,0 +1,67 @@
/*
* 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 "form.h"
#include "button.h"
class ScreenMenu;
class WidgetsContainer;
class SetupWidgetsPage : public FormWindow
{
public:
SetupWidgetsPage(ScreenMenu* menu, uint8_t customScreenIdx);
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "SetupWidgetsPage(idx=" + std::to_string(customScreenIdx) + ")";
}
#endif
void deleteLater(bool detach = true, bool trash = true) override;
#if defined(HARDWARE_TOUCH)
bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY,
coord_t slideX, coord_t slideY) override;
bool onTouchEnd(coord_t x, coord_t y) override;
#endif
#if defined(HARDWARE_KEYS)
void onEvent(event_t event) override;
#endif
protected:
ScreenMenu* menu;
uint8_t customScreenIdx;
unsigned savedView = 0;
};
class SetupWidgetsPageSlot : public Button
{
public:
SetupWidgetsPageSlot(FormGroup* parent, const rect_t& rect,
WidgetsContainer* container, uint8_t slotIndex);
void paint(BitmapBuffer* dc) override;
};
+1
View File
@@ -22,6 +22,7 @@
#ifndef _TELEMETRY_H_
#define _TELEMETRY_H_
#include "dataconstants.h"
#include "frsky.h"
#include "io/frsky_sport.h"
#include "crossfire.h"