From 0f41e348c2e9f6644ef3078ef65b0d841b129c7c Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Thu, 12 Feb 2026 23:04:28 +0000 Subject: [PATCH] Added the window update command - some other small misc stuff --- src/communication/commands.cpp | 2 ++ src/communication/commands.h | 3 ++- src/communication/packets.h | 1 + src/main.cpp | 5 ++++ src/methods/methods.cpp | 46 ++++++++++++++++++++++++++++++---- src/methods/methods.h | 9 +++++++ 6 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/communication/commands.cpp b/src/communication/commands.cpp index a1fca05..b6dbb5e 100644 --- a/src/communication/commands.cpp +++ b/src/communication/commands.cpp @@ -10,6 +10,8 @@ char* CommandToStr(Command id) { return (char*)"CmdCreateWindow"; case CmdDestroyWindow: return (char*)"CmdDestroyWindow"; + case CmdUpdateWinDims: + return (char*)"CmdUpdateWinDims"; default: return (char*)"CmdUnknown"; } diff --git a/src/communication/commands.h b/src/communication/commands.h index ba3c204..3af6021 100644 --- a/src/communication/commands.h +++ b/src/communication/commands.h @@ -8,7 +8,8 @@ typedef enum : uint8_t { CmdRequestID = 1, CmdAckID = 2, CmdCreateWindow = 3, - CmdDestroyWindow = 4 + CmdDestroyWindow = 4, + CmdUpdateWinDims = 5 } Command; char* CommandToStr(Command id); diff --git a/src/communication/packets.h b/src/communication/packets.h index e0e7afe..eb2afa9 100644 --- a/src/communication/packets.h +++ b/src/communication/packets.h @@ -1,6 +1,7 @@ #ifndef __PACKETS__ #define __PACKETS__ +#include "UIDimensions.h" #include typedef uint8_t PacketType; diff --git a/src/main.cpp b/src/main.cpp index 87a459d..0451ce6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -132,6 +132,11 @@ void loop(void) { break; } + case CmdUpdateWinDims: { + LOG_INFO(F("Updating Win\n")); + Window::UpdateDims(payload, &mainScreen); + break; + } case CmdDestroyWindow: { uint8_t destroyedWinID = Window::Destroy(payload, &mainScreen); if (destroyedWinID < 0) { diff --git a/src/methods/methods.cpp b/src/methods/methods.cpp index 1b2dac9..60ae01f 100644 --- a/src/methods/methods.cpp +++ b/src/methods/methods.cpp @@ -1,5 +1,7 @@ #include "methods.h" #include "Arduino.h" +#include "UIDrawing.h" +#include "communication/packets.h" #include "logger.h" #include "UIComponent.h" #include "UIScreen.h" @@ -8,13 +10,17 @@ namespace Window { // Window creation + void printUIDimsPacket(UIDimensions *dims) { + LOG_INFO(F(" Dimensions:\n")); + LOG_INFO(F(" X0 : %d\n"), dims->x); + LOG_INFO(F(" Y0 : %d\n"), dims->y); + LOG_INFO(F(" Width : %d\n"), dims->width); + LOG_INFO(F(" Height: %d\n"), dims->height); + } + void printUIWindowPacket(UICreateWindowPacket *win) { LOG_INFO(F("New window:\n")); - LOG_INFO(F(" Dimensions:\n")); - LOG_INFO(F(" X0 : %d\n"), win->dims.x); - LOG_INFO(F(" Y0 : %d\n"), win->dims.y); - LOG_INFO(F(" Width : %d\n"), win->dims.width); - LOG_INFO(F(" Height: %d\n"), win->dims.height); + printUIDimsPacket(&win->dims); LOG_INFO(F(" Decorations:\n")); LOG_INFO(F(" HasBorder : %d\n"), win->decor.hasBorder); LOG_INFO(F(" BGColour : %d\n"), win->decor.bgColor); @@ -26,6 +32,12 @@ namespace Window { LOG_INFO(F(" Title: %s\n"), win->title); } + void printUpdateDimsPacket(UpdateDimsPacket *pkt) { + LOG_INFO(F("NEW DIMENSIONS:\n")); + LOG_INFO(F(" TARGET WINDOW: %d\n"), pkt->wID); + printUIDimsPacket(&pkt->dims); + } + UICreateWindowPacket::UICreateWindowPacket() {} int8_t Create(uint8_t *payload, Curses::Screen *mainScreen) { @@ -56,6 +68,30 @@ namespace Window { return childID; } + bool UpdateDims(uint8_t *payload, Curses::Screen *mainScreen) { + UpdateDimsPacket pkt; + memcpy((void*)&pkt, payload, sizeof(UpdateDimsPacket)); + printUpdateDimsPacket(&pkt); + + UIElement *mainWindow = mainScreen->mainWindowHandle; + UIElement* win = mainWindow->GetChild(pkt.wID); + if (win == NULL) { + return false; + } + + // Delete the old window + fillRect(win->dims.x, win->dims.y, win->dims.width, + win->dims.height, win->decor.bgColor, win->display); + + // Update the windows dimensions + win->dims = pkt.dims; + + // Redraw the window + win->drawBox(); + + return true; + } + // Window destruction void printUIDestroyWindowPacket(UIDestroyWindowPacket *win) { LOG_INFO(F("Destroy window:\n")); diff --git a/src/methods/methods.h b/src/methods/methods.h index dcac6c4..3cc6a90 100644 --- a/src/methods/methods.h +++ b/src/methods/methods.h @@ -28,6 +28,15 @@ namespace Window { void printUIDestroyWindowPacket(UIDestroyWindowPacket *win); int8_t Destroy(uint8_t *payload, Curses::Screen *mainScreen); + + // Window Updates + struct UpdateDimsPacket { + int16_t wID; + UIDimensions dims; + }; + + void printUpdateDimsPacket(UpdateDimsPacket *pkt); + bool UpdateDims(uint8_t *payload, Curses::Screen *mainScreen); }; namespace Screen {