feat(colorlcd): Value widget text alignment options (#3080)
* Adds option to align value widget label and value to left, center or right border of the widget zone. * Cpn sync * Typofix thx to @Eldenroot * fix: Add `TW` translation * fix: Two spaces for indent --------- Co-authored-by: elecpower <neilh713@tpg.com.au>
This commit is contained in:
@@ -107,7 +107,7 @@ WidgetSettings::WidgetSettings(Window* parent, Widget* widget) :
|
||||
case ZoneOption::File:
|
||||
break;
|
||||
|
||||
case ZoneOption::TextSize: {
|
||||
case ZoneOption::TextSize:
|
||||
new Choice(
|
||||
line, rect_t{}, STR_FONT_SIZES, 0, FONTS_COUNT - 1,
|
||||
[=]() -> int { // getValue
|
||||
@@ -119,7 +119,20 @@ WidgetSettings::WidgetSettings(Window* parent, Widget* widget) :
|
||||
SET_DIRTY();
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case ZoneOption::Align:
|
||||
new Choice(
|
||||
line, rect_t{}, STR_ALIGN_OPTS, 0, ALIGN_COUNT - 1,
|
||||
[=]() -> int { // getValue
|
||||
return (int)widget->getOptionValue(optIdx)->unsignedValue;
|
||||
},
|
||||
[=](int newValue) { // setValue
|
||||
widget->getOptionValue(optIdx)->unsignedValue =
|
||||
(uint32_t)newValue;
|
||||
SET_DIRTY();
|
||||
});
|
||||
break;
|
||||
|
||||
case ZoneOption::Timer: // Unsigned
|
||||
{
|
||||
auto tmChoice = new Choice(
|
||||
|
||||
@@ -41,16 +41,44 @@ class ValueWidget: public Widget
|
||||
// get color from options[1]
|
||||
LcdFlags color = COLOR2FLAGS(persistentData->options[1].value.unsignedValue);
|
||||
|
||||
// get label alignment from options[3]
|
||||
LcdFlags label_alignment = persistentData->options[3].value.unsignedValue;
|
||||
|
||||
// get value alignment from options[4]
|
||||
LcdFlags value_alignment = persistentData->options[4].value.unsignedValue;
|
||||
|
||||
coord_t xValue, yValue, xLabel, yLabel;
|
||||
LcdFlags attrValue, attrLabel = 0;
|
||||
|
||||
if (width() < 120 && height() < 50) {
|
||||
xValue = 0;
|
||||
yValue = 14;
|
||||
xLabel = 0;
|
||||
switch (label_alignment) {
|
||||
case ALIGN_RIGHT:
|
||||
xLabel = width() - NUMBERS_PADDING;
|
||||
attrLabel = RIGHT;
|
||||
break;
|
||||
case ALIGN_CENTER:
|
||||
xLabel = width()/2;
|
||||
attrLabel = CENTERED;
|
||||
break;
|
||||
default: // ALIGN_LEFT:
|
||||
xLabel = 0;
|
||||
attrLabel = LEFT;
|
||||
}
|
||||
yLabel = 0;
|
||||
attrValue = LEFT | NO_UNIT | FONT(L);
|
||||
attrLabel = LEFT;
|
||||
switch (value_alignment) {
|
||||
case ALIGN_RIGHT:
|
||||
xValue = width() - NUMBERS_PADDING;
|
||||
attrValue = RIGHT | NO_UNIT | FONT(L);
|
||||
break;
|
||||
case ALIGN_CENTER:
|
||||
xValue = width()/2 - NUMBERS_PADDING;
|
||||
attrValue = CENTERED | NO_UNIT | FONT(L);
|
||||
break;
|
||||
default: // ALIGN_LEFT:
|
||||
xValue = 0;
|
||||
attrValue = LEFT | NO_UNIT | FONT(L);
|
||||
}
|
||||
yValue = 14;
|
||||
}
|
||||
else if (height() < 50) {
|
||||
xValue = width() - NUMBERS_PADDING;
|
||||
@@ -60,25 +88,57 @@ class ValueWidget: public Widget
|
||||
attrValue = RIGHT | NO_UNIT | FONT(L);
|
||||
}
|
||||
else {
|
||||
xValue = NUMBERS_PADDING;
|
||||
yValue = 18;
|
||||
xLabel = NUMBERS_PADDING;
|
||||
switch (label_alignment) {
|
||||
case ALIGN_RIGHT:
|
||||
xLabel = width() - NUMBERS_PADDING;
|
||||
attrLabel = RIGHT;
|
||||
break;
|
||||
case ALIGN_CENTER:
|
||||
xLabel = width()/2 - NUMBERS_PADDING;
|
||||
attrLabel = CENTERED;
|
||||
break;
|
||||
default: // ALIGN_LEFT:
|
||||
xLabel = NUMBERS_PADDING;
|
||||
attrLabel = LEFT;
|
||||
}
|
||||
yLabel = 2;
|
||||
switch (value_alignment) {
|
||||
case ALIGN_RIGHT:
|
||||
xValue = width() - NUMBERS_PADDING;
|
||||
break;
|
||||
case ALIGN_CENTER:
|
||||
xValue = width()/2;
|
||||
break;
|
||||
default: // ALIGN_LEFT:
|
||||
xValue = NUMBERS_PADDING;
|
||||
}
|
||||
yValue = 18;
|
||||
LcdFlags valalign = LEFT;
|
||||
switch (value_alignment) {
|
||||
case ALIGN_RIGHT:
|
||||
valalign = RIGHT;
|
||||
break;
|
||||
case ALIGN_CENTER:
|
||||
valalign = CENTERED;
|
||||
break;
|
||||
default: // ALIGN_LEFT:
|
||||
valalign = LEFT;
|
||||
}
|
||||
if (field >= MIXSRC_FIRST_TELEM) {
|
||||
if (isGPSSensor(1 + (field - MIXSRC_FIRST_TELEM) / 3)) {
|
||||
attrValue = LEFT | FONT(L) | PREC1;
|
||||
attrValue = valalign | FONT(L) | PREC1;
|
||||
}
|
||||
else {
|
||||
attrValue = LEFT | FONT(XL);
|
||||
attrValue = valalign | FONT(XL);
|
||||
}
|
||||
}
|
||||
#if defined(INTERNAL_GPS)
|
||||
else if (field == MIXSRC_TX_GPS) {
|
||||
attrValue = LEFT | FONT(L) | PREC1;
|
||||
attrValue = valalign | FONT(L) | PREC1;
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
attrValue = LEFT | FONT(XL);
|
||||
attrValue = valalign | FONT(XL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,6 +207,8 @@ const ZoneOption ValueWidget::options[] = {
|
||||
{ STR_SOURCE, ZoneOption::Source, OPTION_VALUE_UNSIGNED(MIXSRC_Rud) },
|
||||
{ STR_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(COLOR_THEME_PRIMARY2) },
|
||||
{ STR_SHADOW, ZoneOption::Bool, OPTION_VALUE_BOOL(false) },
|
||||
{ STR_ALIGN_LABEL, ZoneOption::Align, OPTION_VALUE_UNSIGNED(ALIGN_LEFT) },
|
||||
{ STR_ALIGN_VALUE, ZoneOption::Align, OPTION_VALUE_UNSIGNED(ALIGN_LEFT) },
|
||||
{ nullptr, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
|
||||
@@ -69,7 +69,8 @@ struct ZoneOption
|
||||
TextSize,
|
||||
Timer,
|
||||
Switch,
|
||||
Color
|
||||
Color,
|
||||
Align
|
||||
};
|
||||
|
||||
const char * name;
|
||||
@@ -80,6 +81,17 @@ struct ZoneOption
|
||||
const char * displayName;
|
||||
};
|
||||
|
||||
enum ZoneOptionAlign
|
||||
{
|
||||
ALIGN_LEFT,
|
||||
ALIGN_CENTER,
|
||||
ALIGN_RIGHT,
|
||||
|
||||
// this one MUST be last
|
||||
ALIGN_COUNT
|
||||
};
|
||||
|
||||
|
||||
struct ZoneOptionValueTyped
|
||||
{
|
||||
ZoneOptionValueEnum type;
|
||||
@@ -109,6 +121,7 @@ inline ZoneOptionValueEnum zoneValueEnumFromType(ZoneOption::Type type)
|
||||
case ZoneOption::Timer:
|
||||
case ZoneOption::Switch:
|
||||
case ZoneOption::TextSize:
|
||||
case ZoneOption::Align:
|
||||
default:
|
||||
return ZOV_Unsigned;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user