#pragma once #include #include #include // Maximum number of widgets static constexpr size_t MAX_WIDGETS = 32; static constexpr size_t MAX_TEXT_LEN = 32; enum class WidgetType : uint8_t { LABEL = 0, BUTTON = 1, // Future: GAUGE, IMAGE, ARC, etc. }; // Text source: static text or KNX group address enum class TextSource : uint8_t { STATIC = 0, // Static text KNX_DPT_TEMP = 1, // KNX Temperature (DPT 9.001) KNX_DPT_SWITCH = 2, // KNX Switch (DPT 1.001) KNX_DPT_PERCENT = 3, // KNX Percent (DPT 5.001) KNX_DPT_TEXT = 4, // KNX Text (DPT 16.000) }; // Color as RGB888 struct Color { uint8_t r, g, b; uint32_t toLvColor() const { return (r << 16) | (g << 8) | b; } static Color fromHex(uint32_t hex) { return { .r = static_cast((hex >> 16) & 0xFF), .g = static_cast((hex >> 8) & 0xFF), .b = static_cast(hex & 0xFF) }; } }; // Shadow configuration struct ShadowConfig { int8_t offsetX; int8_t offsetY; uint8_t blur; uint8_t spread; Color color; bool enabled; }; // Widget configuration struct WidgetConfig { // Basic properties uint8_t id; // Unique ID (0-255) WidgetType type; int16_t x, y; int16_t width, height; bool visible; // Text properties TextSource textSource; char text[MAX_TEXT_LEN]; // Static text or format string uint16_t knxAddress; // KNX group address (if textSource != STATIC) uint8_t fontSize; // Font size index (0=14, 1=18, 2=22, 3=28, 4=36, 5=48) // Colors Color textColor; Color bgColor; uint8_t bgOpacity; // 0-255 uint8_t borderRadius; // Shadow ShadowConfig shadow; // Button specific bool isToggle; // For buttons: toggle mode uint16_t knxAddressWrite; // KNX address to write on click // Serialization size (fixed for NVS storage) static constexpr size_t SERIALIZED_SIZE = 64; void serialize(uint8_t* buf) const; void deserialize(const uint8_t* buf); // Create default label static WidgetConfig createLabel(uint8_t id, int16_t x, int16_t y, const char* text); // Create KNX-bound label static WidgetConfig createKnxLabel(uint8_t id, int16_t x, int16_t y, TextSource source, uint16_t knxAddr, const char* format); // Create button static WidgetConfig createButton(uint8_t id, int16_t x, int16_t y, const char* text, uint16_t knxAddrWrite, bool toggle); }; // Screen configuration (holds all widgets) struct ScreenConfig { Color backgroundColor; uint8_t widgetCount; WidgetConfig widgets[MAX_WIDGETS]; void clear(); int addWidget(const WidgetConfig& widget); // Returns widget ID or -1 bool removeWidget(uint8_t id); WidgetConfig* findWidget(uint8_t id); const WidgetConfig* findWidget(uint8_t id) const; };