Statistics page theming + ENTER fix (#872)

* Statistics screen theming
Basically none of the text was using theme colours.

* Formatting

* Use COLOR_THEME_PRIMARY2 for prefixes

* Remove NO_FOCUS stopping reset button from working
Fixes #841
This commit is contained in:
Peter Feerick
2021-10-06 22:14:49 +11:00
committed by GitHub
parent 03188cd333
commit 247d2b0fd8
2 changed files with 208 additions and 182 deletions
+118 -90
View File
@@ -19,12 +19,12 @@
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#include "opentx.h"
#include "libopenui.h"
#include "view_statistics.h" #include "view_statistics.h"
StatisticsViewPageGroup::StatisticsViewPageGroup(): #include "libopenui.h"
TabsGroup(ICON_STATS) #include "opentx.h"
StatisticsViewPageGroup::StatisticsViewPageGroup() : TabsGroup(ICON_STATS)
{ {
addTab(new StatisticsViewPage()); addTab(new StatisticsViewPage());
addTab(new DebugViewPage()); addTab(new DebugViewPage());
@@ -33,8 +33,7 @@ StatisticsViewPageGroup::StatisticsViewPageGroup():
class ThrottleCurveWindow : public Window class ThrottleCurveWindow : public Window
{ {
public: public:
ThrottleCurveWindow(Window * parent, const rect_t &rect) : ThrottleCurveWindow(Window *parent, const rect_t &rect) : Window(parent, rect)
Window(parent, rect)
{ {
} }
@@ -50,7 +49,8 @@ class ThrottleCurveWindow : public Window
void paint(BitmapBuffer *dc) override void paint(BitmapBuffer *dc) override
{ {
// Axis // Axis
dc->drawHorizontalLine(0, height() - 2, width(), SOLID | COLOR_THEME_SECONDARY1); dc->drawHorizontalLine(0, height() - 2, width(),
SOLID | COLOR_THEME_SECONDARY1);
dc->drawVerticalLine(0, 0, height(), SOLID, COLOR_THEME_SECONDARY1); dc->drawVerticalLine(0, 0, height(), SOLID, COLOR_THEME_SECONDARY1);
for (coord_t i = 0; i < width(); i += 6) { for (coord_t i = 0; i < width(); i += 6) {
dc->drawVerticalLine(i, height() - 4, 3, SOLID | COLOR_THEME_SECONDARY1); dc->drawVerticalLine(i, height() - 4, 3, SOLID | COLOR_THEME_SECONDARY1);
@@ -67,14 +67,12 @@ class ThrottleCurveWindow : public Window
for (int y = prev_yv; y <= yv; y++) { for (int y = prev_yv; y <= yv; y++) {
dc->drawBitmapPattern(i, y, LBM_POINT, COLOR_THEME_SECONDARY1); dc->drawBitmapPattern(i, y, LBM_POINT, COLOR_THEME_SECONDARY1);
} }
} } else {
else {
for (int y = yv; y <= prev_yv; y++) { for (int y = yv; y <= prev_yv; y++) {
dc->drawBitmapPattern(i, y, LBM_POINT, COLOR_THEME_SECONDARY1); dc->drawBitmapPattern(i, y, LBM_POINT, COLOR_THEME_SECONDARY1);
} }
} }
} } else {
else {
dc->drawBitmapPattern(i, yv, LBM_POINT, COLOR_THEME_SECONDARY1); dc->drawBitmapPattern(i, yv, LBM_POINT, COLOR_THEME_SECONDARY1);
} }
prev_yv = yv; prev_yv = yv;
@@ -92,56 +90,74 @@ void StatisticsViewPage::build(FormWindow * window)
grid.setLabelWidth(LCD_W / 4); grid.setLabelWidth(LCD_W / 4);
// Session data // Session data
new StaticText(window, grid.getLabelSlot(), STR_SESSION); new StaticText(window, grid.getLabelSlot(), STR_SESSION, 0,
new DynamicText(window, grid.getFieldSlot(3, 0), [] { COLOR_THEME_PRIMARY1);
return getTimerString(sessionTimer, TIMEHOUR); new DynamicText(
}); window, grid.getFieldSlot(3, 0),
[] { return getTimerString(sessionTimer, TIMEHOUR); },
COLOR_THEME_PRIMARY1);
// Battery data // Battery data
new StaticText(window, grid.getFieldSlot(3, 1), STR_BATT_LABEL); new StaticText(window, grid.getFieldSlot(3, 1), STR_BATT_LABEL, 0,
new DynamicText(window, grid.getFieldSlot(3, 2), [] { COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 2),
[] {
return getTimerString(g_eeGeneral.globalTimer + sessionTimer, TIMEHOUR); return getTimerString(g_eeGeneral.globalTimer + sessionTimer, TIMEHOUR);
}); },
COLOR_THEME_PRIMARY1);
grid.nextLine(); grid.nextLine();
// Throttle // Throttle
new StaticText(window, grid.getLabelSlot(), STR_THROTTLE_LABEL); new StaticText(window, grid.getLabelSlot(), STR_THROTTLE_LABEL, 0,
new DynamicText(window, grid.getFieldSlot(3, 0), [] { COLOR_THEME_PRIMARY1);
return getTimerString(s_timeCumThr, TIMEHOUR); new DynamicText(
}); window, grid.getFieldSlot(3, 0),
[] { return getTimerString(s_timeCumThr, TIMEHOUR); },
COLOR_THEME_PRIMARY1);
// Throttle % data // Throttle % data
new StaticText(window, grid.getFieldSlot(3, 1), STR_THROTTLE_PERCENT_LABEL); new StaticText(window, grid.getFieldSlot(3, 1), STR_THROTTLE_PERCENT_LABEL, 0,
new DynamicText(window, grid.getFieldSlot(3, 2), [] { COLOR_THEME_PRIMARY1);
return getTimerString(s_timeCum16ThrP/16, TIMEHOUR); new DynamicText(
}); window, grid.getFieldSlot(3, 2),
[] { return getTimerString(s_timeCum16ThrP / 16, TIMEHOUR); },
COLOR_THEME_PRIMARY1);
grid.nextLine(); grid.nextLine();
// Timers // Timers
new StaticText(window, grid.getLabelSlot(), STR_TIMER_LABEL); new StaticText(window, grid.getLabelSlot(), STR_TIMER_LABEL, 0,
new DynamicText(window, grid.getFieldSlot(3, 0), [] { COLOR_THEME_PRIMARY1);
return getTimerString(timersStates[0].val, TIMEHOUR); new DynamicText(
}, 0); window, grid.getFieldSlot(3, 0),
new DynamicText(window, grid.getFieldSlot(3, 1), [] { [] { return getTimerString(timersStates[0].val, TIMEHOUR); },
return getTimerString(timersStates[1].val, TIMEHOUR); COLOR_THEME_PRIMARY1);
}, 0); new DynamicText(
new DynamicText(window, grid.getFieldSlot(3, 2), [] { window, grid.getFieldSlot(3, 1),
return getTimerString(timersStates[2].val, TIMEHOUR); [] { return getTimerString(timersStates[1].val, TIMEHOUR); },
}, 0); COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 2),
[] { return getTimerString(timersStates[2].val, TIMEHOUR); },
COLOR_THEME_PRIMARY1);
grid.nextLine(); grid.nextLine();
// Throttle curve // Throttle curve
auto curve = new ThrottleCurveWindow(window, {5, grid.getWindowHeight(), window->width() - 10, window->height() / 2}); auto curve = new ThrottleCurveWindow(
window,
{5, grid.getWindowHeight(), window->width() - 10, window->height() / 2});
grid.spacer(curve->height() + 3); grid.spacer(curve->height() + 3);
// Reset // Reset
new TextButton (window, grid.getLineSlot(), STR_MENUTORESET, new TextButton(
window, grid.getLineSlot(), STR_MENUTORESET,
[=]() -> uint8_t { [=]() -> uint8_t {
g_eeGeneral.globalTimer = 0; g_eeGeneral.globalTimer = 0;
storageDirty(EE_GENERAL); storageDirty(EE_GENERAL);
sessionTimer = 0; sessionTimer = 0;
return 0; return 0;
}, BUTTON_BACKGROUND | NO_FOCUS); },
BUTTON_BACKGROUND);
} }
void DebugViewPage::build(FormWindow *window) void DebugViewPage::build(FormWindow *window)
@@ -151,83 +167,94 @@ void DebugViewPage::build(FormWindow * window)
grid.setLabelWidth(LCD_W / 4); grid.setLabelWidth(LCD_W / 4);
// Mixer data // Mixer data
new StaticText(window, grid.getLabelSlot(), STR_TMIXMAXMS); new StaticText(window, grid.getLabelSlot(), STR_TMIXMAXMS, 0,
new DynamicNumber<uint16_t>(window, grid.getFieldSlot(), [] { COLOR_THEME_PRIMARY1);
return DURATION_MS_PREC2(maxMixerDuration); new DynamicNumber<uint16_t>(
}, PREC2, nullptr, "ms"); window, grid.getFieldSlot(),
[] { return DURATION_MS_PREC2(maxMixerDuration); },
PREC2 | COLOR_THEME_PRIMARY1, nullptr, "ms");
grid.nextLine(); grid.nextLine();
// Free mem // Free mem
new StaticText(window, grid.getLabelSlot(), STR_FREE_MEM_LABEL); new StaticText(window, grid.getLabelSlot(), STR_FREE_MEM_LABEL, 0,
new DynamicNumber<int>(window, grid.getFieldSlot(), [] { COLOR_THEME_PRIMARY1);
return availableMemory(); new DynamicNumber<int>(
}, 0, nullptr, "b"); window, grid.getFieldSlot(), [] { return availableMemory(); },
COLOR_THEME_PRIMARY1, nullptr, "b");
grid.nextLine(); grid.nextLine();
#if defined(LUA) #if defined(LUA)
// LUA timing data // LUA timing data
new StaticText(window, grid.getLabelSlot(), STR_LUA_SCRIPTS_LABEL); new StaticText(window, grid.getLabelSlot(), STR_LUA_SCRIPTS_LABEL, 0,
new DebugInfoNumber<uint16_t>(window, grid.getFieldSlot(3, 0), [] { COLOR_THEME_PRIMARY1);
return 10 * maxLuaDuration; new DebugInfoNumber<uint16_t>(
}, 0, "[Dur] ", "ms"); window, grid.getFieldSlot(3, 0), [] { return 10 * maxLuaDuration; },
new DebugInfoNumber<uint16_t>(window, grid.getFieldSlot(3, 1), [] { COLOR_THEME_PRIMARY1, "[Dur] ", "ms");
return 10 * maxLuaInterval; new DebugInfoNumber<uint16_t>(
}, 0, "[Int] ", "ms"); window, grid.getFieldSlot(3, 1), [] { return 10 * maxLuaInterval; },
COLOR_THEME_PRIMARY1, "[Int] ", "ms");
grid.nextLine(); grid.nextLine();
// lUA memory data // lUA memory data
new DebugInfoNumber<uint32_t>(window, grid.getFieldSlot(3, 0), [] { new DebugInfoNumber<uint32_t>(
return 10 * luaGetMemUsed(lsScripts); window, grid.getFieldSlot(3, 0),
}, 0, "[S] ", nullptr); [] { return 10 * luaGetMemUsed(lsScripts); }, COLOR_THEME_PRIMARY1,
new DebugInfoNumber<uint32_t>(window, grid.getFieldSlot(3, 1), [] { "[S] ", nullptr);
return 10 * luaGetMemUsed(lsWidgets); new DebugInfoNumber<uint32_t>(
}, 0, "[W] ", nullptr); window, grid.getFieldSlot(3, 1),
new DebugInfoNumber<uint32_t>(window, grid.getFieldSlot(3, 2), [] { [] { return 10 * luaGetMemUsed(lsWidgets); }, COLOR_THEME_PRIMARY1,
return luaExtraMemoryUsage; "[W] ", nullptr);
}, 0, "[B] ", nullptr); new DebugInfoNumber<uint32_t>(
window, grid.getFieldSlot(3, 2), [] { return luaExtraMemoryUsage; },
COLOR_THEME_PRIMARY1, "[B] ", nullptr);
grid.nextLine(); grid.nextLine();
#endif #endif
// Stacks data // Stacks data
new StaticText(window, grid.getLabelSlot(), STR_FREE_STACK); new StaticText(window, grid.getLabelSlot(), STR_FREE_STACK, 0,
new DebugInfoNumber<uint32_t>(window, grid.getFieldSlot(3, 0), [] { COLOR_THEME_PRIMARY1);
return menusStack.available(); new DebugInfoNumber<uint32_t>(
}, 0, "[Menu] ", nullptr); window, grid.getFieldSlot(3, 0), [] { return menusStack.available(); },
new DebugInfoNumber<uint32_t>(window, grid.getFieldSlot(3, 1), [] { COLOR_THEME_PRIMARY1, "[Menu] ", nullptr);
return mixerStack.available(); new DebugInfoNumber<uint32_t>(
}, 0, "[Mix] ", nullptr); window, grid.getFieldSlot(3, 1), [] { return mixerStack.available(); },
new DebugInfoNumber<uint32_t>(window, grid.getFieldSlot(3, 2), [] { COLOR_THEME_PRIMARY1, "[Mix] ", nullptr);
return audioStack.available(); new DebugInfoNumber<uint32_t>(
}, 0, "[Audio] ", nullptr); window, grid.getFieldSlot(3, 2), [] { return audioStack.available(); },
COLOR_THEME_PRIMARY1, "[Audio] ", nullptr);
grid.nextLine(); grid.nextLine();
#if defined(DEBUG_LATENCY) #if defined(DEBUG_LATENCY)
new StaticText(window, grid.getLabelSlot(), STR_HEARTBEAT_LABEL); new StaticText(window, grid.getLabelSlot(), STR_HEARTBEAT_LABEL, 0,
COLOR_THEME_PRIMARY1);
if (heartbeatCapture.valid) if (heartbeatCapture.valid)
new DebugInfoNumber<uint16_t>(window, grid.getFieldSlot(3, 0), [] { new DebugInfoNumber<uint16_t>(
return heartbeatCapture.count; window, grid.getFieldSlot(3, 0), [] { return heartbeatCapture.count; },
}); COLOR_THEME_PRIMARY1);
else else
new StaticText(window, grid.getFieldSlot(),"---"); new StaticText(window, grid.getFieldSlot(), "---", 0, COLOR_THEME_PRIMARY1);
#endif #endif
#if defined(INTERNAL_GPS) #if defined(INTERNAL_GPS)
new StaticText(window, grid.getLabelSlot(), STR_INT_GPS_LABEL); new StaticText(window, grid.getLabelSlot(), STR_INT_GPS_LABEL, 0,
new DynamicText(window, grid.getFieldSlot(3, 0), [] { COLOR_THEME_PRIMARY1);
return std::string(gpsData.fix ? "[Fix] Yes" : "[Fix] No"); new DynamicText(
}); window, grid.getFieldSlot(3, 0),
new DebugInfoNumber<uint8_t>(window, grid.getFieldSlot(3, 1), [] { [] { return std::string(gpsData.fix ? "[Fix] Yes" : "[Fix] No"); },
return gpsData.numSat; COLOR_THEME_PRIMARY1);
}, 0, "[Sats] ", nullptr); new DebugInfoNumber<uint8_t>(
new DebugInfoNumber<uint16_t>(window, grid.getFieldSlot(3, 2), [] { window, grid.getFieldSlot(3, 1), [] { return gpsData.numSat; },
return gpsData.hdop; COLOR_THEME_PRIMARY1, "[Sats] ", nullptr);
}, 0, "[Hdop] ", nullptr); new DebugInfoNumber<uint16_t>(
window, grid.getFieldSlot(3, 2), [] { return gpsData.hdop; },
COLOR_THEME_PRIMARY1, "[Hdop] ", nullptr);
grid.nextLine(); grid.nextLine();
#endif #endif
// Reset // Reset
grid.nextLine(); grid.nextLine();
new TextButton (window, grid.getLineSlot(), STR_MENUTORESET, new TextButton(
window, grid.getLineSlot(), STR_MENUTORESET,
[=]() -> uint8_t { [=]() -> uint8_t {
maxMixerDuration = 0; maxMixerDuration = 0;
#if defined(LUA) #if defined(LUA)
@@ -235,5 +262,6 @@ void DebugViewPage::build(FormWindow * window)
maxLuaDuration = 0; maxLuaDuration = 0;
#endif #endif
return 0; return 0;
}, BUTTON_BACKGROUND | NO_FOCUS); },
BUTTON_BACKGROUND);
} }
+20 -22
View File
@@ -21,28 +21,30 @@
#pragma once #pragma once
#include "opentx.h"
#include "tabsgroup.h"
#include "static.h"
#include "window.h"
#include "font.h" #include "font.h"
#include "opentx.h"
#include "static.h"
#include "tabsgroup.h"
#include "window.h"
template <class T> template <class T>
class DebugInfoNumber : public Window class DebugInfoNumber : public Window
{ {
public: public:
DebugInfoNumber(Window * parent, const rect_t & rect, std::function<T()> numberHandler, LcdFlags textFlags = 0, const char * prefix = nullptr, const char * suffix = nullptr): DebugInfoNumber(Window* parent, const rect_t& rect,
Window(parent, rect, 0, textFlags), std::function<T()> numberHandler, LcdFlags textFlags = 0,
prefix(prefix), const char* prefix = nullptr, const char* suffix = nullptr) :
suffix(suffix) Window(parent, rect, 0, textFlags), prefix(prefix), suffix(suffix)
{ {
coord_t prefixSize = 0; coord_t prefixSize = 0;
if (prefix != nullptr) { if (prefix != nullptr) {
prefixSize = getTextWidth(prefix, 0, COLOR_THEME_SECONDARY1 | FONT(XS)); prefixSize = getTextWidth(prefix, 0, COLOR_THEME_PRIMARY2 | FONT(XS));
new StaticText(this, {0, 0, prefixSize, rect.h}, prefix, 0, COLOR_THEME_SECONDARY1 | FONT(XS)); new StaticText(this, {0, 0, prefixSize, rect.h}, prefix, 0,
COLOR_THEME_PRIMARY2 | FONT(XS));
} }
new DynamicNumber<uint32_t>(this, {prefixSize, 0, rect.w - prefixSize, rect.h}, new DynamicNumber<uint32_t>(this,
numberHandler); {prefixSize, 0, rect.w - prefixSize, rect.h},
numberHandler, COLOR_THEME_PRIMARY1);
} }
protected: protected:
@@ -53,16 +55,14 @@ class DebugInfoNumber : public Window
class StatisticsViewPage : public PageTab class StatisticsViewPage : public PageTab
{ {
public: public:
StatisticsViewPage() : StatisticsViewPage() : PageTab(STR_STATISTICS, ICON_STATS_THROTTLE_GRAPH) {}
PageTab(STR_STATISTICS, ICON_STATS_THROTTLE_GRAPH)
{
}
protected: protected:
void build(FormWindow* window) override; void build(FormWindow* window) override;
}; };
class StatisticsViewPageGroup: public TabsGroup { class StatisticsViewPageGroup : public TabsGroup
{
public: public:
StatisticsViewPageGroup(); StatisticsViewPageGroup();
}; };
@@ -70,16 +70,14 @@ class StatisticsViewPageGroup: public TabsGroup {
class DebugViewPage : public PageTab class DebugViewPage : public PageTab
{ {
public: public:
DebugViewPage() : DebugViewPage() : PageTab(STR_DEBUG, ICON_STATS_DEBUG) {}
PageTab(STR_DEBUG, ICON_STATS_DEBUG)
{
}
protected: protected:
void build(FormWindow* window) override; void build(FormWindow* window) override;
}; };
class DebugViewMenu: public TabsGroup { class DebugViewMenu : public TabsGroup
{
public: public:
DebugViewMenu(); DebugViewMenu();
}; };