Make DriverView fields more modular

This commit is contained in:
2023-03-20 19:35:30 +01:00
parent f0254b92ee
commit c8ee51a78f
31 changed files with 1554 additions and 109 deletions

View File

@ -1,35 +1,72 @@
#include "gui/common/DataField.hpp"
#include "texts/TextKeysAndLanguages.hpp"
#include "touchgfx/Unicode.hpp"
#include <gui/containers/DriverViewField.hpp>
DriverViewField::DriverViewField()
: intDigits{0}, decimalDigits{0}, fieldValue{0} {}
: intDigits{0}, decimalDigits{0}, floatValue{0}, boolValue{0} {}
void DriverViewField::initialize() { DriverViewFieldBase::initialize(); }
void DriverViewField::setName(const touchgfx::TypedText &text) {
title.setTypedText(text);
void DriverViewField::setType(const DataFieldDescription &desc) {
title.setTypedText(desc.title);
title.invalidate();
}
void DriverViewField::setValue(float newValue) {
fieldValue = newValue;
fieldKind = desc.kind;
switch (desc.kind) {
case DataFieldKind::Numeric:
value.setTypedText(T_NUMBERWILDCARD);
break;
case DataFieldKind::Bool:
case DataFieldKind::Text:
value.setTypedText(T_DEFAULTWILDCARD);
break;
}
intDigits = desc.int_digits;
decimalDigits = desc.decimal_digits;
updateValueBuffer();
}
void DriverViewField::setPrecision(size_t intDigits, size_t decimalDigits) {
this->intDigits = intDigits;
this->decimalDigits = decimalDigits;
void DriverViewField::setValue(float newValue) {
floatValue = newValue;
updateValueBuffer();
}
void DriverViewField::setValue(const char *str) {
Unicode::strncpy(valueBuffer, str,
sizeof(valueBuffer) / sizeof(Unicode::UnicodeChar));
value.setWildcard(valueBuffer);
value.invalidate();
}
void DriverViewField::setValue(int boolValue) {
this->boolValue = boolValue;
updateValueBuffer();
}
void DriverViewField::updateValueBuffer() {
size_t width = intDigits;
if (decimalDigits != 0) {
width += decimalDigits + 1; // 1 digit for the decimal point
switch (fieldKind) {
case DataFieldKind::Numeric: {
size_t width = intDigits;
if (decimalDigits != 0) {
width += decimalDigits + 1; // 1 digit for the decimal point
}
float params[3] = {(float)width, (float)decimalDigits, floatValue};
Unicode::snprintfFloats(valueBuffer,
sizeof(valueBuffer) / sizeof(Unicode::UnicodeChar),
"%*.*f", params);
value.setWildcard(valueBuffer);
break;
}
float params[3] = {(float)width, (float)decimalDigits, fieldValue};
Unicode::snprintfFloats(valueBuffer,
sizeof(valueBuffer) / sizeof(Unicode::UnicodeChar),
"%*.*f", params);
value.setWildcard(valueBuffer);
case DataFieldKind::Bool: {
const char *str = boolValue ? "YES" : "NO";
Unicode::strncpy(valueBuffer, str,
sizeof(valueBuffer) / sizeof(valueBuffer[0]));
value.setWildcard(valueBuffer);
break;
}
case DataFieldKind::Text:
// This is updated directly in setValue()
break;
}
value.invalidate();
}