Skip to content

Commit

Permalink
chore(color): Cleanup layout refresh logic (#4074)
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz authored Oct 30, 2023
1 parent 00b1974 commit 374c782
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 46 deletions.
15 changes: 0 additions & 15 deletions radio/src/gui/colorlcd/layouts/layout_factory_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,6 @@ void Layout::paint(BitmapBuffer * dc)
}
#endif

void Layout::checkEvents()
{
LayoutBase::checkEvents();
adjustLayout();

// uint32_t now = RTOS_GET_MS();
// if (now - lastRefresh >= LAYOUT_REFRESH) {
// lastRefresh = now;
// invalidate();
// #if defined(DEBUG_WINDOWS)
// TRACE_WINDOWS("# %s refresh: %s", factory->getId(), getWindowDebugString().c_str());
// #endif
// }
}

void Layout::setTrimsVisible(bool visible)
{
decoration->setTrimsVisible(visible);
Expand Down
2 changes: 0 additions & 2 deletions radio/src/gui/colorlcd/layouts/layout_factory_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ class Layout: public LayoutBase
{
return factory;
}

void checkEvents() override;

bool hasTopbar() const {
return getOptionValue(LAYOUT_OPTION_TOPBAR)->boolValue;
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/layouts/topbar_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void TopBar::checkEvents()
uint32_t now = RTOS_GET_MS();
if (now - lastRefresh >= TOPBAR_REFRESH) {
lastRefresh = now;
invalidate();
TopBarBase::checkEvents();
}
}

Expand Down
66 changes: 38 additions & 28 deletions radio/src/gui/colorlcd/widgets/radio_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "widgets_container_impl.h"
#include "theme.h"

constexpr uint32_t WIDGET_REFRESH = 1000 / 10; // 10 Hz

#define W_AUDIO_X 0
#define W_USB_X 32
#define W_LOG_X 32
Expand Down Expand Up @@ -84,14 +86,34 @@ STATIC_LZ4_BITMAP(LBM_TOPMENU_TXBATT);
STATIC_LZ4_BITMAP(LBM_TOPMENU_TXBATT_CHARGING);
STATIC_LZ4_BITMAP(LBM_TOPMENU_ANTENNA);

class RadioInfoWidget: public Widget
class TopBarWidget : public Widget
{
protected:
public:
TopBarWidget(const WidgetFactory* factory, Window* parent,
const rect_t& rect, Widget::PersistentData* persistentData) :
Widget(factory, parent, rect, persistentData)
{
}

void checkEvents() override
{
Widget::checkEvents();
uint32_t now = RTOS_GET_MS();
if (now - lastRefresh >= WIDGET_REFRESH) {
lastRefresh = now;
invalidate();
}
}

uint32_t lastRefresh = 0;
};

class RadioInfoWidget: public TopBarWidget
{
public:
RadioInfoWidget(const WidgetFactory* factory, Window* parent,
const rect_t& rect, Widget::PersistentData* persistentData) :
Widget(factory, parent, rect, persistentData)
TopBarWidget(factory, parent, rect, persistentData)
{
}

Expand Down Expand Up @@ -159,14 +181,6 @@ class RadioInfoWidget: public Widget
dc->drawSolidFilledRect(W_AUDIO_X + 2 + 4 * i, 27, 2, 8, i >= bars ? COLOR_THEME_PRIMARY3 : COLOR_THEME_PRIMARY2);
}
}

void checkEvents() override
{
Widget::checkEvents();
invalidate();
}

static const ZoneOption options[];
};

BaseWidgetFactory<RadioInfoWidget> RadioInfoWidget("Radio Info", nullptr, "Radio Info");
Expand All @@ -178,14 +192,12 @@ BaseWidgetFactory<RadioInfoWidget> RadioInfoWidget("Radio Info", nullptr, "Radio
#define DT_OFFSET 1
#endif

class DateTimeWidget: public Widget
class DateTimeWidget: public TopBarWidget
{
protected:

public:
DateTimeWidget(const WidgetFactory* factory, Window* parent,
const rect_t& rect, Widget::PersistentData* persistentData) :
Widget(factory, parent, rect, persistentData)
TopBarWidget(factory, parent, rect, persistentData)
{
}

Expand All @@ -199,9 +211,17 @@ class DateTimeWidget: public Widget
void checkEvents() override
{
Widget::checkEvents();
invalidate();
// Only update if minute value has changed
struct gtm t;
gettime(&t);
if (t.tm_min != lastMinute) {
lastMinute = t.tm_min;
invalidate();
}
}

int8_t lastMinute = 0;

static const ZoneOption options[];
};

Expand All @@ -220,14 +240,12 @@ static const uint8_t _LBM_TOPMENU_GPS[] = {

STATIC_LZ4_BITMAP(LBM_TOPMENU_GPS);

class InternalGPSWidget: public Widget
class InternalGPSWidget: public TopBarWidget
{
protected:

public:
InternalGPSWidget(const WidgetFactory* factory, Window* parent,
const rect_t& rect, Widget::PersistentData* persistentData) :
Widget(factory, parent, rect, persistentData)
TopBarWidget(factory, parent, rect, persistentData)
{
}

Expand All @@ -244,14 +262,6 @@ class InternalGPSWidget: public Widget
(gpsData.fix) ? COLOR_THEME_PRIMARY2 : COLOR_THEME_PRIMARY3);
}
}

void checkEvents() override
{
Widget::checkEvents();
invalidate();
}

static const ZoneOption options[];
};

BaseWidgetFactory<InternalGPSWidget> InternalGPSWidget("Internal GPS", nullptr, "Internal GPS");
Expand Down
1 change: 1 addition & 0 deletions radio/src/gui/colorlcd/widgets/widgets_container_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class WidgetsContainerImpl : public WidgetsContainer
inline void setOptionValue(unsigned int index, const ZoneOptionValue& value)
{
persistentData->options[index].value = value;
adjustLayout();
}

unsigned int getZonesCount() const override = 0;
Expand Down

0 comments on commit 374c782

Please sign in to comment.