Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(color): Cleanup layout refresh logic. #4074

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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