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
+170 -142
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());
@@ -32,208 +32,236 @@ 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) {
{ }
void checkEvents() override
{
Window::checkEvents();
if (previousTraceWr != s_traceWr) {
previousTraceWr = s_traceWr;
invalidate();
}
}
void paint(BitmapBuffer *dc) override
{
// Axis
dc->drawHorizontalLine(0, height() - 2, width(),
SOLID | COLOR_THEME_SECONDARY1);
dc->drawVerticalLine(0, 0, height(), SOLID, COLOR_THEME_SECONDARY1);
for (coord_t i = 0; i < width(); i += 6) {
dc->drawVerticalLine(i, height() - 4, 3, SOLID | COLOR_THEME_SECONDARY1);
} }
void checkEvents() override // Curve
{ uint16_t traceRd = s_traceWr > width() ? s_traceWr - width() : 0;
Window::checkEvents(); coord_t prev_yv = (coord_t)-1;
if (previousTraceWr != s_traceWr) { for (coord_t i = 1; i <= width() && traceRd < s_traceWr; i++, traceRd++) {
previousTraceWr = s_traceWr; uint8_t h = s_traceBuf[traceRd % width()];
invalidate(); coord_t yv = height() - 2 - 3 * h;
if (prev_yv != (coord_t)-1) {
if (prev_yv < yv) {
for (int y = prev_yv; y <= yv; y++) {
dc->drawBitmapPattern(i, y, LBM_POINT, COLOR_THEME_SECONDARY1);
}
} else {
for (int y = yv; y <= prev_yv; y++) {
dc->drawBitmapPattern(i, y, LBM_POINT, COLOR_THEME_SECONDARY1);
}
}
} else {
dc->drawBitmapPattern(i, yv, LBM_POINT, COLOR_THEME_SECONDARY1);
} }
prev_yv = yv;
} }
};
void paint(BitmapBuffer * dc) override protected:
{ unsigned previousTraceWr = 0;
// Axis
dc->drawHorizontalLine(0, height() - 2, width(), SOLID | COLOR_THEME_SECONDARY1);
dc->drawVerticalLine(0, 0, height(), SOLID, COLOR_THEME_SECONDARY1);
for (coord_t i=0; i < width(); i+=6) {
dc->drawVerticalLine(i,height() - 4, 3, SOLID | COLOR_THEME_SECONDARY1);
}
// Curve
uint16_t traceRd = s_traceWr > width() ? s_traceWr - width() : 0;
coord_t prev_yv = (coord_t)-1;
for (coord_t i=1; i<=width() && traceRd<s_traceWr; i++, traceRd++) {
uint8_t h = s_traceBuf[traceRd % width()];
coord_t yv = height() - 2 - 3*h;
if (prev_yv != (coord_t)-1) {
if (prev_yv < yv) {
for (int y=prev_yv; y<=yv; y++) {
dc->drawBitmapPattern(i, y, LBM_POINT, COLOR_THEME_SECONDARY1);
}
}
else {
for (int y=yv; y<=prev_yv; y++) {
dc->drawBitmapPattern(i, y, LBM_POINT, COLOR_THEME_SECONDARY1);
}
}
}
else {
dc->drawBitmapPattern(i, yv, LBM_POINT, COLOR_THEME_SECONDARY1);
}
prev_yv = yv;
}
};
protected:
unsigned previousTraceWr = 0;
}; };
void StatisticsViewPage::build(FormWindow * window) void StatisticsViewPage::build(FormWindow *window)
{ {
FormGridLayout grid; FormGridLayout grid;
grid.spacer(PAGE_PADDING); grid.spacer(PAGE_PADDING);
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);
return getTimerString(g_eeGeneral.globalTimer + sessionTimer, TIMEHOUR); new DynamicText(
}); window, grid.getFieldSlot(3, 2),
[] {
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(
[=]() -> uint8_t { window, grid.getLineSlot(), STR_MENUTORESET,
g_eeGeneral.globalTimer = 0; [=]() -> uint8_t {
storageDirty(EE_GENERAL); g_eeGeneral.globalTimer = 0;
sessionTimer = 0; storageDirty(EE_GENERAL);
return 0; sessionTimer = 0;
}, BUTTON_BACKGROUND | NO_FOCUS); return 0;
},
BUTTON_BACKGROUND);
} }
void DebugViewPage::build(FormWindow * window) void DebugViewPage::build(FormWindow *window)
{ {
FormGridLayout grid; FormGridLayout grid;
grid.spacer(PAGE_PADDING); grid.spacer(PAGE_PADDING);
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(
[=]() -> uint8_t { window, grid.getLineSlot(), STR_MENUTORESET,
maxMixerDuration = 0; [=]() -> uint8_t {
maxMixerDuration = 0;
#if defined(LUA) #if defined(LUA)
maxLuaInterval = 0; maxLuaInterval = 0;
maxLuaDuration = 0; maxLuaDuration = 0;
#endif #endif
return 0; return 0;
}, BUTTON_BACKGROUND | NO_FOCUS); },
BUTTON_BACKGROUND);
} }
+38 -40
View File
@@ -21,65 +21,63 @@
#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},
numberHandler);
} }
new DynamicNumber<uint32_t>(this,
{prefixSize, 0, rect.w - prefixSize, rect.h},
numberHandler, COLOR_THEME_PRIMARY1);
}
protected: protected:
const char * prefix; const char* prefix;
const char * suffix; const char* suffix;
}; };
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: {
StatisticsViewPageGroup(); public:
StatisticsViewPageGroup();
}; };
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: {
DebugViewMenu(); public:
DebugViewMenu();
}; };