Fixed layout options
This commit is contained in:
@@ -273,10 +273,10 @@ void ScreenAddPage::build(FormWindow * window)
|
|||||||
auto pageIndex = this->pageIndex;
|
auto pageIndex = this->pageIndex;
|
||||||
auto menu = this->menu;
|
auto menu = this->menu;
|
||||||
|
|
||||||
button->setPressHandler([menu,pageIndex]() -> uint8_t {
|
button->setPressHandler([menu, pageIndex]() -> uint8_t {
|
||||||
|
|
||||||
auto newPageIdx = menu->getTabs();
|
// First page is "User interface", subtract it
|
||||||
auto newIdx = newPageIdx - 2;
|
auto newIdx = pageIndex - 1;
|
||||||
|
|
||||||
auto& screen = customScreens[newIdx];
|
auto& screen = customScreens[newIdx];
|
||||||
auto& screenData = g_model.screenData[newIdx];
|
auto& screenData = g_model.screenData[newIdx];
|
||||||
@@ -316,6 +316,40 @@ ScreenSetupPage::ScreenSetupPage(ScreenMenu * menu, unsigned pageIndex, unsigned
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void updateLayoutOptions(FormGroup* optionsWindow, unsigned customScreenIndex) // TODO
|
||||||
|
{
|
||||||
|
FormGridLayout grid;
|
||||||
|
optionsWindow->clear();
|
||||||
|
|
||||||
|
// Layout options...
|
||||||
|
int index = 0;
|
||||||
|
auto factory = customScreens[customScreenIndex]->getFactory();
|
||||||
|
if (factory) {
|
||||||
|
for (auto * option = factory->getOptions(); option->name; option++, index++) {
|
||||||
|
ZoneOptionValue * value = customScreens[customScreenIndex]->getOptionValue(index);
|
||||||
|
|
||||||
|
// Option label
|
||||||
|
new StaticText(optionsWindow, grid.getLabelSlot(false), option->name);
|
||||||
|
|
||||||
|
// Option value
|
||||||
|
switch (option->type) {
|
||||||
|
case ZoneOption::Bool:
|
||||||
|
new CheckBox(optionsWindow, grid.getFieldSlot(), GET_SET_DEFAULT(value->boolValue));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ZoneOption::Color:
|
||||||
|
new ColorEdit(optionsWindow, grid.getFieldSlot(), GET_SET_DEFAULT(value->unsignedValue));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
grid.nextLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
optionsWindow->adjustHeight();
|
||||||
|
}
|
||||||
|
|
||||||
void ScreenSetupPage::build(FormWindow * window)
|
void ScreenSetupPage::build(FormWindow * window)
|
||||||
{
|
{
|
||||||
FormGridLayout grid;
|
FormGridLayout grid;
|
||||||
@@ -327,39 +361,48 @@ void ScreenSetupPage::build(FormWindow * window)
|
|||||||
auto layoutSlot = grid.getFieldSlot();
|
auto layoutSlot = grid.getFieldSlot();
|
||||||
layoutSlot.h = 2 * PAGE_LINE_HEIGHT - 1;
|
layoutSlot.h = 2 * PAGE_LINE_HEIGHT - 1;
|
||||||
|
|
||||||
|
// Dynamic options window...
|
||||||
auto idx = customScreenIndex;
|
auto idx = customScreenIndex;
|
||||||
|
rect_t optRect = {0, grid.getWindowHeight(), window->width(), 0};
|
||||||
|
auto optionsWindow = new FormGroup(window, optRect, FORWARD_SCROLL | FORM_FORWARD_FOCUS);
|
||||||
|
|
||||||
LayoutChoice::LayoutFactoryGetter getFactory = GET_VALUE(customScreens[idx]->getFactory());
|
LayoutChoice::LayoutFactoryGetter getFactory = GET_VALUE(customScreens[idx]->getFactory());
|
||||||
LayoutChoice::LayoutFactorySetter setLayout = [idx](const LayoutFactory *factory) {
|
LayoutChoice::LayoutFactorySetter setLayout = [idx, optionsWindow](const LayoutFactory *factory) {
|
||||||
|
// delete any options potentially accessing
|
||||||
|
// the old custom screen
|
||||||
|
optionsWindow->clear();
|
||||||
createCustomScreen(factory, idx);
|
createCustomScreen(factory, idx);
|
||||||
|
updateLayoutOptions(optionsWindow, idx);
|
||||||
SET_DIRTY();
|
SET_DIRTY();
|
||||||
};
|
};
|
||||||
|
|
||||||
auto layoutChoice = new LayoutChoice(window, layoutSlot, getFactory, setLayout);
|
auto layoutChoice = new LayoutChoice(window, layoutSlot, getFactory, setLayout);
|
||||||
grid.nextLine(layoutChoice->height());
|
grid.nextLine(layoutChoice->height());
|
||||||
TRACE("layoutChoice = %p", layoutChoice);
|
|
||||||
|
|
||||||
// Setup widgets button...
|
// Setup widgets button...
|
||||||
auto setupWidgetsButton = new TextButton(window, grid.getFieldSlot(), STR_SETUP_WIDGETS);
|
auto setupWidgetsButton = new TextButton(window, grid.getFieldSlot(), STR_SETUP_WIDGETS);
|
||||||
TRACE("setupWidgetsButton = %p", setupWidgetsButton);
|
|
||||||
|
|
||||||
auto menu = this->menu;
|
auto menu = this->menu;
|
||||||
setupWidgetsButton->setPressHandler([idx,menu]() -> uint8_t {
|
setupWidgetsButton->setPressHandler([idx, menu]() -> uint8_t {
|
||||||
new SetupWidgetsPage(menu, idx);
|
new SetupWidgetsPage(menu, idx);
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
grid.nextLine();
|
grid.nextLine();
|
||||||
|
|
||||||
// Dynamic options window...
|
// place the options window at the right spot
|
||||||
// rect_t r = {0, grid.getWindowHeight(), LCD_W, 0};
|
optionsWindow->setTop(grid.getWindowHeight());
|
||||||
// auto optionsWindow = new FormGroup(window, r, FORWARD_SCROLL | FORM_FORWARD_FOCUS);
|
updateLayoutOptions(optionsWindow, idx);
|
||||||
// grid.addWindow(optionsWindow);
|
grid.addWindow(optionsWindow);
|
||||||
// updateLayoutOptions();
|
|
||||||
|
// fix focus order due to early insertion
|
||||||
|
FormField::link(setupWidgetsButton, optionsWindow);
|
||||||
|
window->setLastField(optionsWindow);
|
||||||
|
|
||||||
// Prevent removing the last page
|
// Prevent removing the last page
|
||||||
if (customScreens[1] != nullptr) {
|
if (customScreens[1] != nullptr) {
|
||||||
auto button = new TextButton(window, grid.getFieldSlot(), STR_REMOVE_SCREEN);
|
auto button = new TextButton(window, grid.getFieldSlot(), STR_REMOVE_SCREEN);
|
||||||
auto menu = this->menu;
|
auto menu = this->menu;
|
||||||
button->setPressHandler([menu,idx]() -> uint8_t {
|
button->setPressHandler([menu, idx]() -> uint8_t {
|
||||||
|
|
||||||
// Set the current tab to "User interface" to trigger body clearing
|
// Set the current tab to "User interface" to trigger body clearing
|
||||||
menu->setCurrentTab(0);
|
menu->setCurrentTab(0);
|
||||||
@@ -388,44 +431,8 @@ void ScreenSetupPage::build(FormWindow * window)
|
|||||||
storageDirty(EE_MODEL);
|
storageDirty(EE_MODEL);
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// fix focus order due to early insertion
|
||||||
|
FormField::link(button, layoutChoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
// optionsWindow->adjustHeight();
|
|
||||||
// optionsWindow->getParent()->adjustInnerHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScreenSetupPage::updateLayoutOptions() // TODO
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
FormGridLayout grid;
|
|
||||||
optionsWindow->clear();
|
|
||||||
|
|
||||||
// Layout options...
|
|
||||||
int index = 0;
|
|
||||||
auto factory = customScreen[customScreenIndex]->getFactory();
|
|
||||||
if (factory) {
|
|
||||||
for (auto * option = factory->getOptions(); option->name; option++, index++) {
|
|
||||||
ZoneOptionValue * value = customScreens[customScreenIndex]->getOptionValue(index);
|
|
||||||
|
|
||||||
// Option label
|
|
||||||
new StaticText(optionsWindow, grid.getLabelSlot(false), option->name);
|
|
||||||
|
|
||||||
// Option value
|
|
||||||
switch (option->type) {
|
|
||||||
case ZoneOption::Bool:
|
|
||||||
new CheckBox(optionsWindow, grid.getFieldSlot(), GET_SET_DEFAULT(value->boolValue));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ZoneOption::Color:
|
|
||||||
new ColorEdit(optionsWindow, grid.getFieldSlot(), GET_SET_DEFAULT(value->unsignedValue));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
grid.nextLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,11 +52,4 @@ class ScreenSetupPage: public PageTab {
|
|||||||
ScreenMenu * menu;
|
ScreenMenu * menu;
|
||||||
unsigned pageIndex;
|
unsigned pageIndex;
|
||||||
unsigned customScreenIndex;
|
unsigned customScreenIndex;
|
||||||
|
|
||||||
// FormGroup * optionsWindow = nullptr;
|
|
||||||
// TextButton * setupWidgetsButton = nullptr;
|
|
||||||
// FormField * layoutChoice = nullptr;
|
|
||||||
|
|
||||||
void updateLayoutOptions();
|
|
||||||
//void disposeCustomScreen();
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user