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.
*/
#include "opentx.h"
#include "libopenui.h"
#include "view_statistics.h"
StatisticsViewPageGroup::StatisticsViewPageGroup():
TabsGroup(ICON_STATS)
#include "libopenui.h"
#include "opentx.h"
StatisticsViewPageGroup::StatisticsViewPageGroup() : TabsGroup(ICON_STATS)
{
addTab(new StatisticsViewPage());
addTab(new DebugViewPage());
@@ -32,208 +32,236 @@ StatisticsViewPageGroup::StatisticsViewPageGroup():
class ThrottleCurveWindow : public Window
{
public:
ThrottleCurveWindow(Window * parent, const rect_t &rect) :
Window(parent, rect)
{
public:
ThrottleCurveWindow(Window *parent, const rect_t &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
{
Window::checkEvents();
if (previousTraceWr != s_traceWr) {
previousTraceWr = s_traceWr;
invalidate();
// 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;
}
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);
}
};
// 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;
protected:
unsigned previousTraceWr = 0;
};
void StatisticsViewPage::build(FormWindow * window)
void StatisticsViewPage::build(FormWindow *window)
{
FormGridLayout grid;
grid.spacer(PAGE_PADDING);
grid.setLabelWidth(LCD_W / 4);
// Session data
new StaticText(window, grid.getLabelSlot(), STR_SESSION);
new DynamicText(window, grid.getFieldSlot(3, 0), [] {
return getTimerString(sessionTimer, TIMEHOUR);
});
new StaticText(window, grid.getLabelSlot(), STR_SESSION, 0,
COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 0),
[] { return getTimerString(sessionTimer, TIMEHOUR); },
COLOR_THEME_PRIMARY1);
// Battery data
new StaticText(window, grid.getFieldSlot(3, 1), STR_BATT_LABEL);
new DynamicText(window, grid.getFieldSlot(3, 2), [] {
return getTimerString(g_eeGeneral.globalTimer + sessionTimer, TIMEHOUR);
});
new StaticText(window, grid.getFieldSlot(3, 1), STR_BATT_LABEL, 0,
COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 2),
[] {
return getTimerString(g_eeGeneral.globalTimer + sessionTimer, TIMEHOUR);
},
COLOR_THEME_PRIMARY1);
grid.nextLine();
// Throttle
new StaticText(window, grid.getLabelSlot(), STR_THROTTLE_LABEL);
new DynamicText(window, grid.getFieldSlot(3, 0), [] {
return getTimerString(s_timeCumThr, TIMEHOUR);
});
new StaticText(window, grid.getLabelSlot(), STR_THROTTLE_LABEL, 0,
COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 0),
[] { return getTimerString(s_timeCumThr, TIMEHOUR); },
COLOR_THEME_PRIMARY1);
// Throttle % data
new StaticText(window, grid.getFieldSlot(3, 1), STR_THROTTLE_PERCENT_LABEL);
new DynamicText(window, grid.getFieldSlot(3, 2), [] {
return getTimerString(s_timeCum16ThrP/16, TIMEHOUR);
});
new StaticText(window, grid.getFieldSlot(3, 1), STR_THROTTLE_PERCENT_LABEL, 0,
COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 2),
[] { return getTimerString(s_timeCum16ThrP / 16, TIMEHOUR); },
COLOR_THEME_PRIMARY1);
grid.nextLine();
// Timers
new StaticText(window, grid.getLabelSlot(), STR_TIMER_LABEL);
new DynamicText(window, grid.getFieldSlot(3, 0), [] {
return getTimerString(timersStates[0].val, TIMEHOUR);
}, 0);
new DynamicText(window, grid.getFieldSlot(3, 1), [] {
return getTimerString(timersStates[1].val, TIMEHOUR);
}, 0);
new DynamicText(window, grid.getFieldSlot(3, 2), [] {
return getTimerString(timersStates[2].val, TIMEHOUR);
}, 0);
new StaticText(window, grid.getLabelSlot(), STR_TIMER_LABEL, 0,
COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 0),
[] { return getTimerString(timersStates[0].val, TIMEHOUR); },
COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 1),
[] { return getTimerString(timersStates[1].val, TIMEHOUR); },
COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 2),
[] { return getTimerString(timersStates[2].val, TIMEHOUR); },
COLOR_THEME_PRIMARY1);
grid.nextLine();
// 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);
// Reset
new TextButton (window, grid.getLineSlot(), STR_MENUTORESET,
[=]() -> uint8_t {
g_eeGeneral.globalTimer = 0;
storageDirty(EE_GENERAL);
sessionTimer = 0;
return 0;
}, BUTTON_BACKGROUND | NO_FOCUS);
new TextButton(
window, grid.getLineSlot(), STR_MENUTORESET,
[=]() -> uint8_t {
g_eeGeneral.globalTimer = 0;
storageDirty(EE_GENERAL);
sessionTimer = 0;
return 0;
},
BUTTON_BACKGROUND);
}
void DebugViewPage::build(FormWindow * window)
void DebugViewPage::build(FormWindow *window)
{
FormGridLayout grid;
grid.spacer(PAGE_PADDING);
grid.setLabelWidth(LCD_W / 4);
// Mixer data
new StaticText(window, grid.getLabelSlot(), STR_TMIXMAXMS);
new DynamicNumber<uint16_t>(window, grid.getFieldSlot(), [] {
return DURATION_MS_PREC2(maxMixerDuration);
}, PREC2, nullptr, "ms");
new StaticText(window, grid.getLabelSlot(), STR_TMIXMAXMS, 0,
COLOR_THEME_PRIMARY1);
new DynamicNumber<uint16_t>(
window, grid.getFieldSlot(),
[] { return DURATION_MS_PREC2(maxMixerDuration); },
PREC2 | COLOR_THEME_PRIMARY1, nullptr, "ms");
grid.nextLine();
// Free mem
new StaticText(window, grid.getLabelSlot(), STR_FREE_MEM_LABEL);
new DynamicNumber<int>(window, grid.getFieldSlot(), [] {
return availableMemory();
}, 0, nullptr, "b");
new StaticText(window, grid.getLabelSlot(), STR_FREE_MEM_LABEL, 0,
COLOR_THEME_PRIMARY1);
new DynamicNumber<int>(
window, grid.getFieldSlot(), [] { return availableMemory(); },
COLOR_THEME_PRIMARY1, nullptr, "b");
grid.nextLine();
#if defined(LUA)
// LUA timing data
new StaticText(window, grid.getLabelSlot(), STR_LUA_SCRIPTS_LABEL);
new DebugInfoNumber<uint16_t>(window, grid.getFieldSlot(3, 0), [] {
return 10 * maxLuaDuration;
}, 0, "[Dur] ", "ms");
new DebugInfoNumber<uint16_t>(window, grid.getFieldSlot(3, 1), [] {
return 10 * maxLuaInterval;
}, 0, "[Int] ", "ms");
new StaticText(window, grid.getLabelSlot(), STR_LUA_SCRIPTS_LABEL, 0,
COLOR_THEME_PRIMARY1);
new DebugInfoNumber<uint16_t>(
window, grid.getFieldSlot(3, 0), [] { return 10 * maxLuaDuration; },
COLOR_THEME_PRIMARY1, "[Dur] ", "ms");
new DebugInfoNumber<uint16_t>(
window, grid.getFieldSlot(3, 1), [] { return 10 * maxLuaInterval; },
COLOR_THEME_PRIMARY1, "[Int] ", "ms");
grid.nextLine();
// lUA memory data
new DebugInfoNumber<uint32_t>(window, grid.getFieldSlot(3, 0), [] {
return 10 * luaGetMemUsed(lsScripts);
}, 0, "[S] ", nullptr);
new DebugInfoNumber<uint32_t>(window, grid.getFieldSlot(3, 1), [] {
return 10 * luaGetMemUsed(lsWidgets);
}, 0, "[W] ", nullptr);
new DebugInfoNumber<uint32_t>(window, grid.getFieldSlot(3, 2), [] {
return luaExtraMemoryUsage;
}, 0, "[B] ", nullptr);
new DebugInfoNumber<uint32_t>(
window, grid.getFieldSlot(3, 0),
[] { return 10 * luaGetMemUsed(lsScripts); }, COLOR_THEME_PRIMARY1,
"[S] ", nullptr);
new DebugInfoNumber<uint32_t>(
window, grid.getFieldSlot(3, 1),
[] { return 10 * luaGetMemUsed(lsWidgets); }, COLOR_THEME_PRIMARY1,
"[W] ", nullptr);
new DebugInfoNumber<uint32_t>(
window, grid.getFieldSlot(3, 2), [] { return luaExtraMemoryUsage; },
COLOR_THEME_PRIMARY1, "[B] ", nullptr);
grid.nextLine();
#endif
// Stacks data
new StaticText(window, grid.getLabelSlot(), STR_FREE_STACK);
new DebugInfoNumber<uint32_t>(window, grid.getFieldSlot(3, 0), [] {
return menusStack.available();
}, 0, "[Menu] ", nullptr);
new DebugInfoNumber<uint32_t>(window, grid.getFieldSlot(3, 1), [] {
return mixerStack.available();
}, 0, "[Mix] ", nullptr);
new DebugInfoNumber<uint32_t>(window, grid.getFieldSlot(3, 2), [] {
return audioStack.available();
}, 0, "[Audio] ", nullptr);
new StaticText(window, grid.getLabelSlot(), STR_FREE_STACK, 0,
COLOR_THEME_PRIMARY1);
new DebugInfoNumber<uint32_t>(
window, grid.getFieldSlot(3, 0), [] { return menusStack.available(); },
COLOR_THEME_PRIMARY1, "[Menu] ", nullptr);
new DebugInfoNumber<uint32_t>(
window, grid.getFieldSlot(3, 1), [] { return mixerStack.available(); },
COLOR_THEME_PRIMARY1, "[Mix] ", nullptr);
new DebugInfoNumber<uint32_t>(
window, grid.getFieldSlot(3, 2), [] { return audioStack.available(); },
COLOR_THEME_PRIMARY1, "[Audio] ", nullptr);
grid.nextLine();
#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)
new DebugInfoNumber<uint16_t>(window, grid.getFieldSlot(3, 0), [] {
return heartbeatCapture.count;
});
new DebugInfoNumber<uint16_t>(
window, grid.getFieldSlot(3, 0), [] { return heartbeatCapture.count; },
COLOR_THEME_PRIMARY1);
else
new StaticText(window, grid.getFieldSlot(),"---");
new StaticText(window, grid.getFieldSlot(), "---", 0, COLOR_THEME_PRIMARY1);
#endif
#if defined(INTERNAL_GPS)
new StaticText(window, grid.getLabelSlot(), STR_INT_GPS_LABEL);
new DynamicText(window, grid.getFieldSlot(3, 0), [] {
return std::string(gpsData.fix ? "[Fix] Yes" : "[Fix] No");
});
new DebugInfoNumber<uint8_t>(window, grid.getFieldSlot(3, 1), [] {
return gpsData.numSat;
}, 0, "[Sats] ", nullptr);
new DebugInfoNumber<uint16_t>(window, grid.getFieldSlot(3, 2), [] {
return gpsData.hdop;
}, 0, "[Hdop] ", nullptr);
new StaticText(window, grid.getLabelSlot(), STR_INT_GPS_LABEL, 0,
COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 0),
[] { return std::string(gpsData.fix ? "[Fix] Yes" : "[Fix] No"); },
COLOR_THEME_PRIMARY1);
new DebugInfoNumber<uint8_t>(
window, grid.getFieldSlot(3, 1), [] { return gpsData.numSat; },
COLOR_THEME_PRIMARY1, "[Sats] ", nullptr);
new DebugInfoNumber<uint16_t>(
window, grid.getFieldSlot(3, 2), [] { return gpsData.hdop; },
COLOR_THEME_PRIMARY1, "[Hdop] ", nullptr);
grid.nextLine();
#endif
// Reset
grid.nextLine();
new TextButton (window, grid.getLineSlot(), STR_MENUTORESET,
[=]() -> uint8_t {
maxMixerDuration = 0;
new TextButton(
window, grid.getLineSlot(), STR_MENUTORESET,
[=]() -> uint8_t {
maxMixerDuration = 0;
#if defined(LUA)
maxLuaInterval = 0;
maxLuaDuration = 0;
maxLuaInterval = 0;
maxLuaDuration = 0;
#endif
return 0;
}, BUTTON_BACKGROUND | NO_FOCUS);
return 0;
},
BUTTON_BACKGROUND);
}
+38 -40
View File
@@ -21,65 +21,63 @@
#pragma once
#include "opentx.h"
#include "tabsgroup.h"
#include "static.h"
#include "window.h"
#include "font.h"
#include "opentx.h"
#include "static.h"
#include "tabsgroup.h"
#include "window.h"
template <class T>
class DebugInfoNumber : public Window
{
public:
DebugInfoNumber(Window * parent, const rect_t & rect, std::function<T()> numberHandler, LcdFlags textFlags = 0, const char * prefix = nullptr, const char * suffix = nullptr):
Window(parent, rect, 0, textFlags),
prefix(prefix),
suffix(suffix)
{
coord_t prefixSize = 0;
if (prefix != nullptr) {
prefixSize = getTextWidth(prefix, 0, COLOR_THEME_SECONDARY1 | FONT(XS));
new StaticText(this, {0, 0, prefixSize, rect.h}, prefix, 0, COLOR_THEME_SECONDARY1 | FONT(XS));
}
new DynamicNumber<uint32_t>(this, {prefixSize, 0, rect.w - prefixSize, rect.h},
numberHandler);
public:
DebugInfoNumber(Window* parent, const rect_t& rect,
std::function<T()> numberHandler, LcdFlags textFlags = 0,
const char* prefix = nullptr, const char* suffix = nullptr) :
Window(parent, rect, 0, textFlags), prefix(prefix), suffix(suffix)
{
coord_t prefixSize = 0;
if (prefix != nullptr) {
prefixSize = getTextWidth(prefix, 0, COLOR_THEME_PRIMARY2 | 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, COLOR_THEME_PRIMARY1);
}
protected:
const char * prefix;
const char * suffix;
protected:
const char* prefix;
const char* suffix;
};
class StatisticsViewPage : public PageTab
{
public:
StatisticsViewPage() :
PageTab(STR_STATISTICS, ICON_STATS_THROTTLE_GRAPH)
{
}
public:
StatisticsViewPage() : PageTab(STR_STATISTICS, ICON_STATS_THROTTLE_GRAPH) {}
protected:
void build(FormWindow * window) override;
protected:
void build(FormWindow* window) override;
};
class StatisticsViewPageGroup: public TabsGroup {
public:
StatisticsViewPageGroup();
class StatisticsViewPageGroup : public TabsGroup
{
public:
StatisticsViewPageGroup();
};
class DebugViewPage : public PageTab
{
public:
DebugViewPage() :
PageTab(STR_DEBUG, ICON_STATS_DEBUG)
{
}
public:
DebugViewPage() : PageTab(STR_DEBUG, ICON_STATS_DEBUG) {}
protected:
void build(FormWindow * window) override;
protected:
void build(FormWindow* window) override;
};
class DebugViewMenu: public TabsGroup {
public:
DebugViewMenu();
class DebugViewMenu : public TabsGroup
{
public:
DebugViewMenu();
};