Added the window destruction command

This commit is contained in:
2025-12-31 17:03:19 +00:00
parent e6f05a18dd
commit a267911cc3
3 changed files with 32 additions and 0 deletions
+11
View File
@@ -195,6 +195,17 @@ void loop(void) {
break;
}
case CmdDestroyWindow: {
uint8_t destroyedWinID = DestroyWindow::Destroy(payload, &mainScreen);
if (destroyedWinID < 0) {
LOG_WARN(F("Failed to destroy window\n"));
break;
}
LOG_INFO(F("Succesfully destroy window: %d\n"), destroyedWinID);
break;
}
default:
LOG_WARN(F("Command: `%s` has not been implemented yet."), CommandToStr(cmd));
}
+15
View File
@@ -41,4 +41,19 @@ namespace CreateWindow {
};
namespace DestroyWindow {
void printUIDestroyWindowPacket(UIDestroyWindowPacket *win) {
LOG_INFO(F("Destroy window:\n"));
LOG_INFO(F(" WinID: %d\n"), win->WinID);
}
int8_t Destroy(uint8_t *payload, Curses::Screen *mainScreen) {
DestroyWindow::UIDestroyWindowPacket win;
memcpy(&win, payload, sizeof(DestroyWindow::UIDestroyWindowPacket));
printUIDestroyWindowPacket(&win);
UIElement *mainWindow = mainScreen->mainWindowHandle;
mainWindow->RemoveChild(win.WinID);
return win.WinID;
}
};
+6
View File
@@ -20,6 +20,12 @@ namespace CreateWindow {
};
namespace DestroyWindow {
struct UIDestroyWindowPacket {
int16_t WinID;
};
void printUIDestroyWindowPacket(UIDestroyWindowPacket *win);
int8_t Destroy(uint8_t *payload, Curses::Screen *mainScreen);
};
#endif