Add three general-purpose fields to DriverView

This commit is contained in:
2023-03-18 22:51:13 +01:00
parent 5fe5d509a4
commit c6f237b87e
28 changed files with 536 additions and 57 deletions

View File

@ -0,0 +1,35 @@
#include "touchgfx/Unicode.hpp"
#include <gui/containers/DriverViewField.hpp>
DriverViewField::DriverViewField()
: intDigits{0}, decimalDigits{0}, fieldValue{0} {}
void DriverViewField::initialize() { DriverViewFieldBase::initialize(); }
void DriverViewField::setName(const touchgfx::TypedText &text) {
title.setTypedText(text);
title.invalidate();
}
void DriverViewField::setValue(float newValue) {
fieldValue = newValue;
updateValueBuffer();
}
void DriverViewField::setPrecision(size_t intDigits, size_t decimalDigits) {
this->intDigits = intDigits;
this->decimalDigits = decimalDigits;
updateValueBuffer();
}
void DriverViewField::updateValueBuffer() {
size_t width = intDigits;
if (decimalDigits != 0) {
width += decimalDigits + 1; // 1 digit for the decimal point
}
float params[3] = {(float)width, (float)decimalDigits, fieldValue};
Unicode::snprintfFloats(valueBuffer,
sizeof(valueBuffer) / sizeof(Unicode::UnicodeChar),
"%*.*f", params);
value.setWildcard(valueBuffer);
}