diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index fd6a13668..7f3302dbb 100644 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -474,7 +474,7 @@ coord_t BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char * s, uint8_ coord_t BitmapBuffer::drawNumber(coord_t x, coord_t y, int32_t val, LcdFlags flags, uint8_t len, const char * prefix, const char * suffix) { char str[48+1]; // max=16 for the prefix, 16 chars for the number, 16 chars for the suffix - char *s = str+32; + char *s = str + 32; *s = '\0'; int idx = 0; int mode = MODE(flags); @@ -487,13 +487,13 @@ coord_t BitmapBuffer::drawNumber(coord_t x, coord_t y, int32_t val, LcdFlags fla *--s = '0' + (val % 10); ++idx; val /= 10; - if (mode!=0 && idx==mode) { + if (mode != 0 && idx == mode) { mode = 0; *--s = '.'; - if (val==0) + if (val == 0) *--s = '0'; } - } while (val!=0 || mode>0 || (mode==MODE(LEADING0) && idx 0 || (mode == MODE(LEADING0) && idx < len)); if (neg) *--s = '-'; // TODO needs check on all string lengths ... diff --git a/radio/src/thirdparty/libopenui/src/button.h b/radio/src/thirdparty/libopenui/src/button.h index a1bf1f0ee..ce310310a 100644 --- a/radio/src/thirdparty/libopenui/src/button.h +++ b/radio/src/thirdparty/libopenui/src/button.h @@ -28,7 +28,7 @@ constexpr WindowFlags BUTTON_CHECKED = FORM_FLAGS_LAST << 2; constexpr WindowFlags BUTTON_CHECKED_ON_FOCUS = FORM_FLAGS_LAST << 3; constexpr WindowFlags BUTTON_DISABLED = FORM_FLAGS_LAST << 4; -class Button : public FormField { +class Button: public FormField { public: Button(FormGroup * parent, const rect_t & rect, std::function pressHandler = nullptr, WindowFlags windowFlags = 0): FormField(parent, rect, windowFlags), @@ -104,7 +104,7 @@ class Button : public FormField { void onPress(); }; -class TextButton : public Button { +class TextButton: public Button { public: TextButton(FormGroup * parent, const rect_t & rect, std::string text, std::function pressHandler = nullptr, WindowFlags windowFlags = BUTTON_BACKGROUND): Button(parent, rect, pressHandler, windowFlags | OPAQUE), diff --git a/radio/src/thirdparty/libopenui/src/modal_window.h b/radio/src/thirdparty/libopenui/src/modal_window.h index 9faa6143c..13322c1aa 100644 --- a/radio/src/thirdparty/libopenui/src/modal_window.h +++ b/radio/src/thirdparty/libopenui/src/modal_window.h @@ -52,7 +52,7 @@ class ModalWindow: public Window return true; } - bool onTouchEnd(coord_t x, coord_t y) + bool onTouchEnd(coord_t x, coord_t y) override { if (!Window::onTouchEnd(x, y)) { deleteLater(); @@ -60,7 +60,7 @@ class ModalWindow: public Window return true; } - bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY) + bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY) override { Window::onTouchSlide(x, y, startX, startY, slideX, slideY); return true; diff --git a/radio/src/thirdparty/libopenui/src/slider.h b/radio/src/thirdparty/libopenui/src/slider.h index 7f00b9837..cf35fbfa8 100644 --- a/radio/src/thirdparty/libopenui/src/slider.h +++ b/radio/src/thirdparty/libopenui/src/slider.h @@ -22,7 +22,7 @@ #include "form.h" -class Slider : public FormField { +class Slider: public FormField { public: Slider(Window * parent, const rect_t & rect, int32_t vmin, int32_t vmax, std::function getValue, std::function setValue): FormField(parent, rect), diff --git a/radio/src/thirdparty/libopenui/src/static.h b/radio/src/thirdparty/libopenui/src/static.h index 46ae5e06d..4b509aa8f 100644 --- a/radio/src/thirdparty/libopenui/src/static.h +++ b/radio/src/thirdparty/libopenui/src/static.h @@ -23,7 +23,7 @@ #include "window.h" #include "button.h" // TODO just for BUTTON_BACKGROUND -class StaticText : public Window { +class StaticText: public Window { public: StaticText(Window * parent, const rect_t & rect, std::string text = "", WindowFlags windowFlags = 0, LcdFlags textFlags = 0) : Window(parent, rect, windowFlags, textFlags), @@ -108,4 +108,59 @@ class StaticBitmap: public Window { const BitmapBuffer * bitmap = nullptr; }; +class DynamicText: public StaticText +{ + public: + DynamicText(Window * parent, const rect_t & rect, std::function textHandler): + StaticText(parent, rect), + textHandler(std::move(textHandler)) + { + } + + void checkEvents() override + { + std::string newText = textHandler(); + if (newText != text) { + text = newText; + invalidate(); + } + } + + protected: + std::function textHandler; +}; + +template +class DynamicNumber: public Window +{ + public: + DynamicNumber(Window * parent, const rect_t & rect, std::function numberHandler, LcdFlags textFlags = 0, const char * prefix = nullptr, const char * suffix = nullptr): + Window(parent, rect, 0, textFlags), + numberHandler(std::move(numberHandler)), + prefix(prefix), + suffix(suffix) + { + } + + void paint(BitmapBuffer * dc) override + { + dc->drawNumber(0, FIELD_PADDING_TOP, value, textFlags, 0, prefix, suffix); + } + + void checkEvents() override + { + T newValue = numberHandler(); + if (value != newValue) { + value = newValue; + invalidate(); + } + } + + protected: + T value = 0; + std::function numberHandler; + const char * prefix; + const char * suffix; +}; + #endif diff --git a/radio/src/thirdparty/libopenui/src/window.h b/radio/src/thirdparty/libopenui/src/window.h index b8c1285ef..946b2e9e5 100644 --- a/radio/src/thirdparty/libopenui/src/window.h +++ b/radio/src/thirdparty/libopenui/src/window.h @@ -357,7 +357,7 @@ class Window { std::function closeHandler; std::function focusHandler; - void attach(Window * window); + void attach(Window * window); void addChild(Window * window) {