fix(screen setup): changing screen layout
This commit is contained in:
@@ -145,24 +145,25 @@ createCustomScreen(const LayoutFactory* factory, unsigned customScreenIndex)
|
||||
if (!factory || (customScreenIndex >= MAX_CUSTOM_SCREENS))
|
||||
return nullptr;
|
||||
|
||||
if (customScreens[customScreenIndex]) {
|
||||
customScreens[customScreenIndex]->deleteLater(true, false);
|
||||
delete customScreens[customScreenIndex];
|
||||
auto& screen = customScreens[customScreenIndex];
|
||||
auto& screenData = g_model.screenData[customScreenIndex];
|
||||
|
||||
if (screen != nullptr) {
|
||||
screen->deleteLater(true, false);
|
||||
delete screen;
|
||||
}
|
||||
|
||||
auto screen = factory->create(
|
||||
ViewMain::instance(), &g_model.screenData[customScreenIndex].layoutData);
|
||||
customScreens[customScreenIndex] = screen;
|
||||
auto viewMain = ViewMain::instance();
|
||||
screen = factory->create(viewMain, &screenData.layoutData);
|
||||
|
||||
if (screen) {
|
||||
auto dst = g_model.screenData[customScreenIndex].LayoutId;
|
||||
auto src = factory->getId();
|
||||
strncpy(dst, src, sizeof(CustomScreenData::LayoutId));
|
||||
|
||||
return screen;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
if (!screen) return nullptr;
|
||||
viewMain->addMainView(screen, customScreenIndex);
|
||||
|
||||
auto dst = g_model.screenData[customScreenIndex].LayoutId;
|
||||
auto src = factory->getId();
|
||||
strncpy(dst, src, sizeof(CustomScreenData::LayoutId));
|
||||
|
||||
return screen;
|
||||
}
|
||||
|
||||
void disposeCustomScreen(unsigned idx)
|
||||
|
||||
@@ -41,7 +41,7 @@ class LayoutChoice : public Button
|
||||
LayoutChoice(Window* parent, LayoutFactoryGetter getValue, LayoutFactorySetter setValue) :
|
||||
Button(parent, rect_t{}, nullptr, 0, 0, lv_btn_create),
|
||||
getValue(std::move(getValue)),
|
||||
setValue(std::move(setValue))
|
||||
_setValue(std::move(setValue))
|
||||
{
|
||||
canvas = lv_canvas_create(lvobj);
|
||||
lv_obj_center(canvas);
|
||||
@@ -69,7 +69,7 @@ class LayoutChoice : public Button
|
||||
protected:
|
||||
lv_obj_t* canvas = nullptr;
|
||||
std::function<const LayoutFactory*()> getValue;
|
||||
std::function<void(const LayoutFactory*)> setValue;
|
||||
std::function<void(const LayoutFactory*)> _setValue;
|
||||
|
||||
void update()
|
||||
{
|
||||
@@ -86,6 +86,12 @@ class LayoutChoice : public Button
|
||||
void* buf = (void*)(bitmap + 4);
|
||||
lv_canvas_set_buffer(canvas, buf, w, h, LV_IMG_CF_ALPHA_8BIT);
|
||||
}
|
||||
|
||||
void setValue(const LayoutFactory* layout)
|
||||
{
|
||||
if (_setValue) _setValue(layout);
|
||||
update();
|
||||
}
|
||||
};
|
||||
|
||||
ScreenAddPage::ScreenAddPage(ScreenMenu * menu, uint8_t pageIndex):
|
||||
|
||||
Reference in New Issue
Block a user