user can now created more than a string window
This commit is contained in:
+1
-1
@@ -120,7 +120,7 @@ void loop(void) {
|
|||||||
WalkieTalkie::SendData(&papers);
|
WalkieTalkie::SendData(&papers);
|
||||||
break;
|
break;
|
||||||
case CmdCreateWindow: {
|
case CmdCreateWindow: {
|
||||||
uint8_t newWindowID = Window::Create(payload, &mainScreen);
|
int8_t newWindowID = Window::Create(payload, &mainScreen);
|
||||||
if (newWindowID < 0) {
|
if (newWindowID < 0) {
|
||||||
LOG_WARN(F("Failed to add new window!\n"));
|
LOG_WARN(F("Failed to add new window!\n"));
|
||||||
break;
|
break;
|
||||||
|
|||||||
+56
-6
@@ -1,11 +1,13 @@
|
|||||||
#include "methods.h"
|
#include "methods.h"
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
#include "UIBar.h"
|
||||||
#include "UIDecorations.h"
|
#include "UIDecorations.h"
|
||||||
#include "UIDrawing.h"
|
#include "UIDrawing.h"
|
||||||
#include "communication/packets.h"
|
#include "communication/packets.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "UIComponent.h"
|
#include "UIComponent.h"
|
||||||
#include "UIScreen.h"
|
#include "UIScreen.h"
|
||||||
|
#include "values.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -64,7 +66,6 @@ namespace Window {
|
|||||||
|
|
||||||
int8_t Create(uint8_t *payload, Curses::Screen *mainScreen) {
|
int8_t Create(uint8_t *payload, Curses::Screen *mainScreen) {
|
||||||
// Load the payload into a struct
|
// Load the payload into a struct
|
||||||
// UICreateWindowPacket* win;
|
|
||||||
UICreateWindowPacket win;
|
UICreateWindowPacket win;
|
||||||
// Maybe find a better way to copy this - if we had metadata to the payload
|
// Maybe find a better way to copy this - if we had metadata to the payload
|
||||||
// for example
|
// for example
|
||||||
@@ -72,20 +73,43 @@ namespace Window {
|
|||||||
printUIWindowPacket(&win);
|
printUIWindowPacket(&win);
|
||||||
|
|
||||||
UIElement *mainWindow = mainScreen->mainWindowHandle;
|
UIElement *mainWindow = mainScreen->mainWindowHandle;
|
||||||
int16_t childID = mainWindow->AddChild(STRING);
|
int16_t childID = mainWindow->AddChild((ComponentType)win.opts.WinType);
|
||||||
if (childID < 0) {
|
if (childID < 0) {
|
||||||
|
LOG_DEBUG(F("COULD NOT ADD CHILD\r\n"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
UIElement *childComponent = mainWindow->GetChild(childID);
|
UIElement *childComponent = mainWindow->GetChild(childID);
|
||||||
|
|
||||||
setTitleWithOpts(&win, childComponent, childID);
|
setTitleWithOpts(&win, childComponent, childID);
|
||||||
|
|
||||||
|
// This are universal things
|
||||||
childComponent->SetUIDecorations(win.decor);
|
childComponent->SetUIDecorations(win.decor);
|
||||||
childComponent->SetUIDimensions(UIDimensions(win.dims.x, win.dims.y,
|
childComponent->SetUIDimensions(UIDimensions(win.dims.x, win.dims.y,
|
||||||
win.dims.width, win.dims.height));
|
win.dims.width, win.dims.height));
|
||||||
childComponent->SetDisplay(mainScreen->display);
|
childComponent->SetDisplay(mainScreen->display);
|
||||||
|
|
||||||
childComponent->drawBox();
|
// NOTE: if I move to a composition style thing I guess I can do all this
|
||||||
|
// setup at start up time.
|
||||||
|
// I can also just have a base void* chunk of data with options I send to
|
||||||
|
// each UI type and the UI type handles it somehow, we'll see
|
||||||
|
// Handle each type of window
|
||||||
|
switch ((ComponentType)win.opts.WinType) {
|
||||||
|
case STRING:
|
||||||
|
LOG_DEBUG(F("Setting up the STRING type UIWindow\r\n"));
|
||||||
|
childComponent->drawBox();
|
||||||
|
break;
|
||||||
|
case BAR: {
|
||||||
|
LOG_DEBUG(F("Setting up the BAR type UIWindow\r\n"));
|
||||||
|
UIBar* bar = (UIBar*)childComponent;
|
||||||
|
|
||||||
|
bar->range = 9;
|
||||||
|
bar->drawBox();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
childComponent->Update(win.opts.PreviewValue, true);
|
childComponent->Update(win.opts.PreviewValue, true);
|
||||||
|
|
||||||
return childID;
|
return childID;
|
||||||
@@ -109,8 +133,22 @@ namespace Window {
|
|||||||
// Update the windows dimensions
|
// Update the windows dimensions
|
||||||
win->dims = pkt.dims;
|
win->dims = pkt.dims;
|
||||||
|
|
||||||
|
LOG_DEBUG(F("Win Type is: %d\r\n"), win->type);
|
||||||
|
|
||||||
// Redraw the window
|
// Redraw the window
|
||||||
win->drawBox();
|
switch ((ComponentType)win->type) {
|
||||||
|
case STRING:
|
||||||
|
win->drawBox();
|
||||||
|
break;
|
||||||
|
case BAR:
|
||||||
|
{
|
||||||
|
LOG_DEBUG(F("Updating UIBar dimensions\r\n"));
|
||||||
|
UIBar* bar = (UIBar*)win;
|
||||||
|
bar->drawBox();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
win->Redraw();
|
win->Redraw();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -137,7 +175,19 @@ namespace Window {
|
|||||||
win->decor = pkt.data.decor;
|
win->decor = pkt.data.decor;
|
||||||
setTitleWithOpts(&pkt.data, win, pkt.WinID);
|
setTitleWithOpts(&pkt.data, win, pkt.WinID);
|
||||||
|
|
||||||
win->drawBox();
|
switch ((ComponentType)win->type) {
|
||||||
|
case STRING:
|
||||||
|
win->drawBox();
|
||||||
|
break;
|
||||||
|
case BAR:
|
||||||
|
{
|
||||||
|
LOG_DEBUG(F("Updating UIBar\r\n"));
|
||||||
|
UIBar* bar = (UIBar*)win;
|
||||||
|
bar->drawBox();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
win->Update(pkt.data.opts.PreviewValue, true);
|
win->Update(pkt.data.opts.PreviewValue, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user