fixed model select & create model
This commit is contained in:
@@ -37,7 +37,7 @@ void registerLayout(const LayoutFactory * factory)
|
||||
|
||||
const LayoutFactory * getLayoutFactory(const char * name)
|
||||
{
|
||||
std::list<const LayoutFactory *>::const_iterator it = getRegisteredLayouts().cbegin();
|
||||
auto it = getRegisteredLayouts().cbegin();
|
||||
for (; it != getRegisteredLayouts().cend(); ++it) {
|
||||
if (!strcmp(name, (*it)->getId())) {
|
||||
return (*it);
|
||||
@@ -55,21 +55,48 @@ Layout * loadLayout(const char * name, Layout::PersistentData * persistentData)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void deleteCustomScreens()
|
||||
{
|
||||
for (unsigned int i = 0; i < MAX_CUSTOM_SCREENS; i++) {
|
||||
auto& screen = customScreens[i];
|
||||
if (screen) {
|
||||
screen->detach();
|
||||
delete screen;
|
||||
screen = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern const LayoutFactory * defaultLayout;
|
||||
|
||||
void loadDefaultLayout()
|
||||
{
|
||||
auto& screen = customScreens[0];
|
||||
auto& screenData = g_model.screenData[0];
|
||||
|
||||
if (screen == nullptr && defaultLayout != nullptr) {
|
||||
strcpy(screenData.layoutName, defaultLayout->getName());
|
||||
screen = defaultLayout->create(&screenData.layoutData);
|
||||
if (screen) {
|
||||
screen->attach(ViewMain::instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loadCustomScreens()
|
||||
{
|
||||
for (unsigned int i = 0; i < MAX_CUSTOM_SCREENS; i++) {
|
||||
delete customScreens[i];
|
||||
char name[LAYOUT_NAME_LEN + 1];
|
||||
memset(name, 0, sizeof(name));
|
||||
strncpy(name, g_model.screenData[i].layoutName, LAYOUT_NAME_LEN);
|
||||
customScreens[i] = loadLayout(name, &g_model.screenData[i].layoutData);
|
||||
|
||||
auto& screen = customScreens[i];
|
||||
screen = loadLayout(g_model.screenData[i].layoutName,
|
||||
&g_model.screenData[i].layoutData);
|
||||
|
||||
if (screen) {
|
||||
screen->attach(ViewMain::instance);
|
||||
}
|
||||
}
|
||||
|
||||
if (customScreens[0] == nullptr && getRegisteredLayouts().size()) {
|
||||
customScreens[0] = getRegisteredLayouts().front()->create(&g_model.screenData[0].layoutData);
|
||||
}
|
||||
|
||||
customScreens[g_model.view]->attach(ViewMain::instance);
|
||||
//customScreens[g_model.view]->attach(ViewMain::instance);
|
||||
}
|
||||
|
||||
void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode)
|
||||
|
||||
@@ -123,6 +123,11 @@ class BaseLayoutFactory: public LayoutFactory
|
||||
};
|
||||
|
||||
Layout * loadLayout(const char * name, Layout::PersistentData * persistentData);
|
||||
|
||||
// intented for new models
|
||||
void loadDefaultLayout();
|
||||
|
||||
// intended for existing models
|
||||
void loadCustomScreens();
|
||||
|
||||
void drawTrimsAndSliders(Layout::PersistentData * persistentData);
|
||||
|
||||
@@ -211,17 +211,23 @@ class ModelSelectFooter: public Window {
|
||||
dc->drawSolidFilledRect(0, 0, width(), height(), DISABLE_COLOR);
|
||||
uint32_t size = sdGetSize() / 100;
|
||||
coord_t x = 7;
|
||||
dc->drawMask(7, 4, modelselSdFreeBitmap, DEFAULT_COLOR);
|
||||
x += modelselSdFreeBitmap->width() + 3;
|
||||
if (modelselSdFreeBitmap) {
|
||||
dc->drawMask(7, 4, modelselSdFreeBitmap, DEFAULT_COLOR);
|
||||
x += modelselSdFreeBitmap->width() + 3;
|
||||
}
|
||||
x = dc->drawNumber(x, 3, size, PREC1|FONT(XS), 0, nullptr, "GB");
|
||||
x += 20;
|
||||
dc->drawMask(x, 4, modelselModelQtyBitmap, DEFAULT_COLOR);
|
||||
x += modelselModelQtyBitmap->width() + 3;
|
||||
if (modelselModelQtyBitmap) {
|
||||
dc->drawMask(x, 4, modelselModelQtyBitmap, DEFAULT_COLOR);
|
||||
x += modelselModelQtyBitmap->width() + 3;
|
||||
}
|
||||
x = dc->drawNumber(x, 3, modelslist.getModelsCount(), FONT(XS));
|
||||
if (currentModel) {
|
||||
x += 20;
|
||||
dc->drawMask(x, 4, modelselModelNameBitmap, DEFAULT_COLOR);
|
||||
x += modelselModelNameBitmap->width() + 3;
|
||||
if (modelselModelNameBitmap) {
|
||||
dc->drawMask(x, 4, modelselModelNameBitmap, DEFAULT_COLOR);
|
||||
x += modelselModelNameBitmap->width() + 3;
|
||||
}
|
||||
dc->drawText(x, 3, currentModel->modelFilename, FONT(XS) | DEFAULT_COLOR);
|
||||
}
|
||||
}
|
||||
@@ -275,8 +281,7 @@ class ModelCategoryPageBody: public FormWindow {
|
||||
loadModel(g_eeGeneral.currModelFilename, false);
|
||||
storageDirty(EE_GENERAL);
|
||||
storageCheck(true);
|
||||
// chainMenu(menuMainView);
|
||||
postModelLoad(true);
|
||||
|
||||
modelslist.setCurrentModel(model);
|
||||
update(); // modelslist.getModelIndex(modelCell));
|
||||
});
|
||||
@@ -368,6 +373,7 @@ ModelSelectMenu::ModelSelectMenu():
|
||||
{
|
||||
modelslist.load();
|
||||
|
||||
TRACE("TabsGroup: %p", this);
|
||||
for (auto category: modelslist.getCategories()) {
|
||||
addTab(new ModelCategoryPage(category));
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ void ViewMain::openMenu()
|
||||
menu->addLine(STR_MONITOR_SCREENS, []() {
|
||||
new ChannelsViewMenu();
|
||||
});
|
||||
menu->addLine(STR_RESET_SUBMENU, [menu, this]() {
|
||||
menu->addLine(STR_RESET_SUBMENU, [this]() {
|
||||
Menu * resetMenu = new Menu(this);
|
||||
resetMenu->addLine(STR_RESET_FLIGHT, []() {
|
||||
flightReset();
|
||||
|
||||
@@ -511,12 +511,8 @@ void modelDefault(uint8_t id)
|
||||
strAppendUnsigned(strAppend(g_model.header.name, STR_MODEL), id + 1, 2);
|
||||
|
||||
#if defined(COLORLCD)
|
||||
extern const LayoutFactory * defaultLayout;
|
||||
delete customScreens[0];
|
||||
customScreens[0] = defaultLayout->create(&g_model.screenData[0].layoutData);
|
||||
strcpy(g_model.screenData[0].layoutName, "Layout2P1");
|
||||
// extern const WidgetFactory * defaultWidget;
|
||||
// customScreens[0]->createWidget(0, defaultWidget);
|
||||
loadDefaultLayout();
|
||||
|
||||
// enable switch warnings
|
||||
for (int i = 0; i < NUM_SWITCHES; i++) {
|
||||
g_model.switchWarningState |= (1 << (3*i));
|
||||
|
||||
Reference in New Issue
Block a user