Added the window update command

- some other small misc stuff
This commit is contained in:
2026-02-12 23:04:28 +00:00
parent 61a310516b
commit 0f41e348c2
6 changed files with 60 additions and 6 deletions
+2
View File
@@ -10,6 +10,8 @@ char* CommandToStr(Command id) {
return (char*)"CmdCreateWindow"; return (char*)"CmdCreateWindow";
case CmdDestroyWindow: case CmdDestroyWindow:
return (char*)"CmdDestroyWindow"; return (char*)"CmdDestroyWindow";
case CmdUpdateWinDims:
return (char*)"CmdUpdateWinDims";
default: default:
return (char*)"CmdUnknown"; return (char*)"CmdUnknown";
} }
+2 -1
View File
@@ -8,7 +8,8 @@ typedef enum : uint8_t {
CmdRequestID = 1, CmdRequestID = 1,
CmdAckID = 2, CmdAckID = 2,
CmdCreateWindow = 3, CmdCreateWindow = 3,
CmdDestroyWindow = 4 CmdDestroyWindow = 4,
CmdUpdateWinDims = 5
} Command; } Command;
char* CommandToStr(Command id); char* CommandToStr(Command id);
+1
View File
@@ -1,6 +1,7 @@
#ifndef __PACKETS__ #ifndef __PACKETS__
#define __PACKETS__ #define __PACKETS__
#include "UIDimensions.h"
#include <stdint.h> #include <stdint.h>
typedef uint8_t PacketType; typedef uint8_t PacketType;
+5
View File
@@ -132,6 +132,11 @@ void loop(void) {
break; break;
} }
case CmdUpdateWinDims: {
LOG_INFO(F("Updating Win\n"));
Window::UpdateDims(payload, &mainScreen);
break;
}
case CmdDestroyWindow: { case CmdDestroyWindow: {
uint8_t destroyedWinID = Window::Destroy(payload, &mainScreen); uint8_t destroyedWinID = Window::Destroy(payload, &mainScreen);
if (destroyedWinID < 0) { if (destroyedWinID < 0) {
+41 -5
View File
@@ -1,5 +1,7 @@
#include "methods.h" #include "methods.h"
#include "Arduino.h" #include "Arduino.h"
#include "UIDrawing.h"
#include "communication/packets.h"
#include "logger.h" #include "logger.h"
#include "UIComponent.h" #include "UIComponent.h"
#include "UIScreen.h" #include "UIScreen.h"
@@ -8,13 +10,17 @@
namespace Window { namespace Window {
// Window creation // 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) { void printUIWindowPacket(UICreateWindowPacket *win) {
LOG_INFO(F("New window:\n")); LOG_INFO(F("New window:\n"));
LOG_INFO(F(" Dimensions:\n")); printUIDimsPacket(&win->dims);
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);
LOG_INFO(F(" Decorations:\n")); LOG_INFO(F(" Decorations:\n"));
LOG_INFO(F(" HasBorder : %d\n"), win->decor.hasBorder); LOG_INFO(F(" HasBorder : %d\n"), win->decor.hasBorder);
LOG_INFO(F(" BGColour : %d\n"), win->decor.bgColor); LOG_INFO(F(" BGColour : %d\n"), win->decor.bgColor);
@@ -26,6 +32,12 @@ namespace Window {
LOG_INFO(F(" Title: %s\n"), win->title); 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() {} UICreateWindowPacket::UICreateWindowPacket() {}
int8_t Create(uint8_t *payload, Curses::Screen *mainScreen) { int8_t Create(uint8_t *payload, Curses::Screen *mainScreen) {
@@ -56,6 +68,30 @@ namespace Window {
return childID; 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 // Window destruction
void printUIDestroyWindowPacket(UIDestroyWindowPacket *win) { void printUIDestroyWindowPacket(UIDestroyWindowPacket *win) {
LOG_INFO(F("Destroy window:\n")); LOG_INFO(F("Destroy window:\n"));
+9
View File
@@ -28,6 +28,15 @@ namespace Window {
void printUIDestroyWindowPacket(UIDestroyWindowPacket *win); void printUIDestroyWindowPacket(UIDestroyWindowPacket *win);
int8_t Destroy(uint8_t *payload, Curses::Screen *mainScreen); 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 { namespace Screen {