Add three general-purpose fields to DriverView
This commit is contained in:
35
TouchGFX/gui/src/containers/DriverViewField.cpp
Normal file
35
TouchGFX/gui/src/containers/DriverViewField.cpp
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user