From a267911cc3bc620341a7c123c6a0dc4ade288f63 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Wed, 31 Dec 2025 17:03:19 +0000 Subject: [PATCH] Added the window destruction command --- src/main.cpp | 11 +++++++++++ src/methods/methods.cpp | 15 +++++++++++++++ src/methods/methods.h | 6 ++++++ 3 files changed, 32 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 6b76f37..e9fb657 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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)); } diff --git a/src/methods/methods.cpp b/src/methods/methods.cpp index 7958208..7e9c7a2 100644 --- a/src/methods/methods.cpp +++ b/src/methods/methods.cpp @@ -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; + } }; diff --git a/src/methods/methods.h b/src/methods/methods.h index 7644773..b7e152d 100644 --- a/src/methods/methods.h +++ b/src/methods/methods.h @@ -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