Fix static initialization order problem with Horus GUI (#4141)

* [480x272] Fix static initialization order problem with Layout, Theme, & Widget factories.

* [480x272] Fix return from drawTimerMode().

* [480x272] Remove use of macros for registered Layout, Widget, & Theme class lists; remove extern declarations (cosmetic).

* [480x272] Convert Layout and Theme registry to dynamic lists (still max. of 10 each);
  Hide indicator arrow when user is at start/end of available widgets in spinner UI;
  Add some sanity checking to pointer usage in screens_setup;
  Add an (arbitrary) limit of 20 Widgets;
  And a line break! :)
This commit is contained in:
Max Paperno
2016-12-17 23:29:26 +01:00
committed by Bertrand Songis
parent d4d3d51a9d
commit bce42bb25c
8 changed files with 137 additions and 87 deletions
+14 -10
View File
@@ -20,22 +20,26 @@
#include "opentx.h"
const LayoutFactory * registeredLayouts[MAX_REGISTERED_LAYOUTS]; // TODO dynamic
unsigned int countRegisteredLayouts = 0;
std::list<const LayoutFactory *> & getRegisteredLayouts()
{
static std::list<const LayoutFactory *> layouts;
return layouts;
}
void registerLayout(const LayoutFactory * factory)
{
if (countRegisteredLayouts < MAX_REGISTERED_LAYOUTS) {
if (getRegisteredLayouts().size() < MAX_REGISTERED_LAYOUTS) {
TRACE("register layout %s", factory->getName());
registeredLayouts[countRegisteredLayouts++] = factory;
getRegisteredLayouts().push_back(factory);
}
}
const LayoutFactory * getLayoutFactory(const char * name)
{
for (unsigned int i=0; i<countRegisteredLayouts; i++) {
const LayoutFactory * factory = registeredLayouts[i];
if (!strcmp(name, factory->getName())) {
return factory;
std::list<const LayoutFactory *>::const_iterator it = getRegisteredLayouts().cbegin();
for (; it != getRegisteredLayouts().cend(); ++it) {
if (!strcmp(name, (*it)->getName())) {
return (*it);
}
}
return NULL;
@@ -60,8 +64,8 @@ void loadCustomScreens()
customScreens[i] = loadLayout(name, &g_model.screenData[i].layoutData);
}
if (customScreens[0] == NULL) {
customScreens[0] = registeredLayouts[0]->create(&g_model.screenData[0].layoutData);
if (customScreens[0] == NULL && getRegisteredLayouts().size()) {
customScreens[0] = getRegisteredLayouts().front()->create(&g_model.screenData[0].layoutData);
}
topbar->load();