Registered widgets limit removed (#3899)
This commit is contained in:
@@ -210,28 +210,26 @@ bool menuWidgetSettings(event_t event)
|
|||||||
bool menuWidgetChoice(event_t event)
|
bool menuWidgetChoice(event_t event)
|
||||||
{
|
{
|
||||||
static Widget * previousWidget;
|
static Widget * previousWidget;
|
||||||
|
static Widget * currentWidget;
|
||||||
|
static std::list<const WidgetFactory *>::iterator iterator;
|
||||||
static Widget::PersistentData tempData;
|
static Widget::PersistentData tempData;
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case EVT_ENTRY:
|
case EVT_ENTRY:
|
||||||
{
|
{
|
||||||
const WidgetFactory * factory;
|
|
||||||
previousWidget = currentContainer->getWidget(currentZone);
|
previousWidget = currentContainer->getWidget(currentZone);
|
||||||
currentContainer->setWidget(currentZone, NULL);
|
currentContainer->setWidget(currentZone, NULL);
|
||||||
menuHorizontalPosition = 0;
|
iterator = registeredWidgets.begin();
|
||||||
if (previousWidget) {
|
if (previousWidget) {
|
||||||
factory = previousWidget->getFactory();
|
const WidgetFactory * factory = previousWidget->getFactory();
|
||||||
for (unsigned int i=0; i<countRegisteredWidgets; i++) {
|
for (std::list<const WidgetFactory *>::iterator it = registeredWidgets.begin(); it != registeredWidgets.end(); ++it) {
|
||||||
if (factory->getName() == registeredWidgets[i]->getName()) {
|
if (factory->getName() == (*it)->getName()) {
|
||||||
menuHorizontalPosition = i;
|
iterator = it;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
currentWidget = (*iterator)->create(currentContainer->getZone(currentZone), &tempData);
|
||||||
factory = registeredWidgets[0];
|
|
||||||
}
|
|
||||||
currentWidget = factory->create(currentContainer->getZone(currentZone), &tempData);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,22 +241,24 @@ bool menuWidgetChoice(event_t event)
|
|||||||
|
|
||||||
case EVT_KEY_FIRST(KEY_ENTER):
|
case EVT_KEY_FIRST(KEY_ENTER):
|
||||||
delete previousWidget;
|
delete previousWidget;
|
||||||
currentContainer->createWidget(currentZone, registeredWidgets[menuHorizontalPosition]);
|
currentContainer->createWidget(currentZone, *iterator);
|
||||||
storageDirty(EE_MODEL);
|
storageDirty(EE_MODEL);
|
||||||
popMenu();
|
popMenu();
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
case EVT_ROTARY_RIGHT:
|
case EVT_ROTARY_RIGHT:
|
||||||
if (menuHorizontalPosition < int(countRegisteredWidgets-1)) {
|
if (iterator != registeredWidgets.end() && iterator != --registeredWidgets.end()) {
|
||||||
|
++iterator;
|
||||||
delete currentWidget;
|
delete currentWidget;
|
||||||
currentWidget = registeredWidgets[++menuHorizontalPosition]->create(currentContainer->getZone(currentZone), &tempData);
|
currentWidget = (*iterator)->create(currentContainer->getZone(currentZone), &tempData);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVT_ROTARY_LEFT:
|
case EVT_ROTARY_LEFT:
|
||||||
if (menuHorizontalPosition > 0) {
|
if (iterator != registeredWidgets.begin()) {
|
||||||
|
--iterator;
|
||||||
delete currentWidget;
|
delete currentWidget;
|
||||||
currentWidget = registeredWidgets[--menuHorizontalPosition]->create(currentContainer->getZone(currentZone), &tempData);
|
currentWidget = (*iterator)->create(currentContainer->getZone(currentZone), &tempData);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,20 +20,17 @@
|
|||||||
|
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
|
|
||||||
const WidgetFactory * registeredWidgets[MAX_REGISTERED_WIDGETS]; // TODO dynamic
|
std::list<const WidgetFactory *> registeredWidgets;
|
||||||
unsigned int countRegisteredWidgets = 0;
|
|
||||||
void registerWidget(const WidgetFactory * factory)
|
void registerWidget(const WidgetFactory * factory)
|
||||||
{
|
{
|
||||||
if (countRegisteredWidgets < MAX_REGISTERED_WIDGETS) {
|
TRACE("register widget %s", factory->getName());
|
||||||
TRACE("register widget %s", factory->getName());
|
registeredWidgets.push_back(factory);
|
||||||
registeredWidgets[countRegisteredWidgets++] = factory;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const WidgetFactory * getWidgetFactory(const char * name)
|
const WidgetFactory * getWidgetFactory(const char * name)
|
||||||
{
|
{
|
||||||
for (unsigned int i=0; i<countRegisteredWidgets; i++) {
|
for (std::list<const WidgetFactory *>::iterator it = registeredWidgets.begin(); it != registeredWidgets.end();++it) {
|
||||||
const WidgetFactory * factory = registeredWidgets[i];
|
const WidgetFactory * factory = *it;
|
||||||
if (!strcmp(name, factory->getName())) {
|
if (!strcmp(name, factory->getName())) {
|
||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
#define MAX_WIDGET_OPTIONS 5
|
#define MAX_WIDGET_OPTIONS 5
|
||||||
|
|
||||||
@@ -185,9 +186,7 @@ inline const ZoneOption * Widget::getOptions() const
|
|||||||
return getFactory()->getOptions();
|
return getFactory()->getOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_REGISTERED_WIDGETS 10
|
extern std::list<const WidgetFactory *> registeredWidgets;
|
||||||
extern unsigned int countRegisteredWidgets;
|
|
||||||
extern const WidgetFactory * registeredWidgets[MAX_REGISTERED_WIDGETS];
|
|
||||||
Widget * loadWidget(const char * name, const Zone & zone, Widget::PersistentData * persistentData);
|
Widget * loadWidget(const char * name, const Zone & zone, Widget::PersistentData * persistentData);
|
||||||
|
|
||||||
#endif // _WIDGET_H_
|
#endif // _WIDGET_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user