better type handling for windows - also allows the user to actually use the bar elements

This commit is contained in:
2026-03-13 14:37:39 +00:00
parent 36cdd67f23
commit f49d3cd3e1
4 changed files with 26 additions and 15 deletions
+14 -4
View File
@@ -1,11 +1,17 @@
#include "UIBar.h"
#include "UIComponent.h"
#include "UIDrawing.h"
#include <stdio.h>
UIBar::UIBar() {
this->type = BAR;
};
UIBar::UIBar() {};
UIBar::UIBar(Arduino_GFX *d, UIDimensions dims, UIDecorations decor,
char *title)
: UIElement(d, dims, decor, title) {}
: UIElement(d, dims, decor, title) {
this->type = BAR;
}
void UIBar::Update(const char *v, bool forceRedraw) {
unsigned long time = millis();
@@ -68,7 +74,7 @@ void UIBar::renderBlank() {
this->display->print("!RANGE");
}
void UIBar::Box() {
void UIBar::drawBox() {
// If the range was not set, we cannot draw our ruler
if (this->range <= 0) {
this->renderBlank();
@@ -105,4 +111,8 @@ void UIBar::Box() {
}
}
void UIBar::Redraw() {}
void UIBar::Redraw() {
char val[8];
sprintf(val, "%d", this->value);
this->Update(val, true);
}
+2 -1
View File
@@ -2,6 +2,7 @@
#define _UI_BAR
#include "UIComponent.h"
#include "values.h"
struct UIBar : UIElement {
// This might be the only when where its more efficient to have the data
@@ -16,7 +17,7 @@ struct UIBar : UIElement {
void Redraw() override;
void DrawBar(uint32_t *oldValue, uint32_t *newValue);
void renderBlank();
void Box();
void drawBox();
};
#endif
+5 -6
View File
@@ -1,5 +1,6 @@
#include "UIComponent.h"
#include "values.h"
#include "logger.h"
#include "windowPool.h"
// #include "u8g2.h"
#include "Arduino.h"
@@ -141,18 +142,17 @@ void UIElement::replaceString(char *oldVal, char *newVal) {
int16_t UIElement::AddChild(ComponentType t) {
if (childrenCount >= MAX_CHILDREN) {
Serial2.println("Failed to add child: childrenCount exceeds MAX_CHILDREN");
Serial2.print( childrenCount);
Serial2.print( " >= ");
Serial2.print( MAX_CHILDREN);
LOG_ERROR(F("Failed to add child: childrenCount exceeds MAX_CHILDREN\r\n"));
LOG_ERROR(F(" %d >= %d\r\n"), childrenCount, MAX_CHILDREN);
return -1;
}
int16_t newElem = WindowPool::Allocate(t);
if (newElem < 0) {
Serial2.println("Failed to allocate new component");
LOG_ERROR(F("Failed to allocate new component\r\n"));
return -1;
}
LOG_DEBUG(F("Successfully allocated component: %d\r\n"), newElem);
this->children[this->curChildIndex] = newElem;
this->childrenCount++;
@@ -172,4 +172,3 @@ UIElement* UIElement::GetChild(int16_t childID) {
std::uint8_t UIElement::ChildrenCount() {
return this->childrenCount;
}
+5 -4
View File
@@ -1,4 +1,5 @@
#include "windowPool.h"
#include "logger.h"
#include "UIComponent.h"
#include "UIBar.h"
#include "UIString.h"
@@ -24,10 +25,8 @@ namespace WindowPool {
int16_t Allocate(ComponentType t) {
int16_t nextIndex = getNextIndex();
if (nextIndex < 0) {
Serial2.println("Failed to allocate comp: poolIndex exceeds MAX_WINDOWS");
Serial2.print( nextIndex);
Serial2.print( " >= ");
Serial2.println( MAX_WINDOWS);
LOG_ERROR(F("Failed to allocate comp: poolIndex exceeds MAX_WINDOWS\r\n"));
LOG_ERROR(F(" %d >= %d\r\n"), nextIndex, MAX_WINDOWS);
return -1;
}
@@ -35,7 +34,9 @@ namespace WindowPool {
switch(pool[nextIndex].type) {
case BAR:
LOG_DEBUG(F("PRE allocing\r\n"));
pool[nextIndex].bar = new UIBar();
LOG_DEBUG(F("POST allocing type: \r\n"), pool[nextIndex].type);
break;
case STRING:
pool[nextIndex].str = new UIString();