-
-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to align values to the right #257
Comments
yes, if you derive the field class and redefine its print function |
Hi Rui: Processor: ESP32
len: is the maximum number of characters on the line? Within this function len has a value of 36 but _displayWidth / _menuFontX = 128/9 ~ "14" and not 36 Where is my confusion? |
len is the remaining characters on the device line (some are just not respecting it), print should stop when len=0 i will deprecate this on AM5 in favor of device specific clipping instead of that crazy and buggy parameter passing edit: also they should return the characters remaining at line after print ( |
Hi Rui: #define _menuCantCharX 14 //Maximum number of characters in a line
template<typename T>
class menuFieldRigth :public menuField<T> { //https://github.com/neu-rah/ArduinoMenu/blob/master/examples/customField/customField/customField.ino
private:
public:
menuFieldRigth(constMEM menuFieldShadow<T>& shadow) :menuField<T>(shadow) {}
menuFieldRigth(
T& value,
constText* text,
constText* units,
T low,
T high,
T step,
T tune,
action a = doNothing,
eventMask e = noEvent,
styles s = noStyle
) :menuFieldRigth(*new menuFieldShadow<T>(value, text, units, low, high, step, tune, a, e, s)) {}
Used printTo(navRoot& root, bool sel, menuOut& out, idx_t idx, idx_t len, idx_t panelNr = 0) override {
idx_t l = prompt::printTo(root, sel, out, idx, len);
menuField<T>::reflex = menuField<T>::target();
char buffer[_menuCantCharX] = "";
String value = "";
value += ((root.navFocus == this && sel) ? (menuField<T>::tunning ? ">" : ":") : " ");
value += menuField<T>::reflex;
value += fieldBase::units();
strcat_rigth(buffer, value.c_str(), (_menuCantCharX - l) );
out.print(buffer);
return(_menuCantCharX);
}
};
void strcat_rigth(char* dest, const char* org, byte maxChars) {
byte orgLen = strlen(org);
byte destLen = strlen(dest);
while ((destLen + orgLen) < maxChars)
{
strcat(dest, " ");
dest[destLen] = SPACE_CHAR;
destLen++;
}
orgLen = 0; //ahora la uso para contar los caracteres que voy escribiendo
while ((destLen <= maxChars) && (org[orgLen] != NULL_CHAR))
{
dest[destLen] = org[orgLen];
destLen++;
orgLen++;
}
dest[destLen] = NULL_CHAR;
} I encountered a problem assigning the "° C" unit because the strlen () function counts the character ´ ° ´ as two bytes. |
@ferchinas Hi Fernando! |
i know why and i could solve it, however solution is not elegant. Its because of extended characters surrogates. some codes imply a second character, extending the character table (ie:UTF8). not elegant but possible :D |
Hello:
In "menuValues" I would like to align the text to the left and the values to the right. That's possible?
The text was updated successfully, but these errors were encountered: