CMenuOptionNumberChooser: expand localize functionality for any number

This commit is contained in:
2018-04-04 14:07:26 +02:00
parent 6656a65fb4
commit fdbddce9dd
4 changed files with 28 additions and 20 deletions

View File

@@ -1071,12 +1071,12 @@ void COsdSetup::showOsdTimeoutSetup(CMenuWidget* menu_timeout)
std::string nf("%d "); std::string nf("%d ");
nf += g_Locale->getText(LOCALE_UNIT_SHORT_SECOND); nf += g_Locale->getText(LOCALE_UNIT_SHORT_SECOND);
for (int i = 0; i < SNeutrinoSettings::TIMING_SETTING_COUNT; i++) for (int i = 0; i < SNeutrinoSettings::TIMING_SETTING_COUNT; i++)
{ {
CMenuOptionNumberChooser *ch = new CMenuOptionNumberChooser(timing_setting[i].name, &g_settings.timing[i], true, 0, 240); CMenuOptionNumberChooser *ch = new CMenuOptionNumberChooser(timing_setting[i].name, &g_settings.timing[i], true, 0, 240);
ch->setNumberFormat(nf); ch->setNumberFormat(nf);
ch->setLocalizedValue(0); ch->setLocalizedValue(0, LOCALE_OPTIONS_OFF);
ch->setLocalizedValueName(LOCALE_OPTIONS_OFF);
ch->setHint("", timing_setting[i].hint); ch->setHint("", timing_setting[i].hint);
menu_timeout->addItem(ch); menu_timeout->addItem(ch);
} }

View File

@@ -169,8 +169,7 @@ int CVfdSetup::showSetup()
{ {
// allow to set scroll_repeats // allow to set scroll_repeats
CMenuOptionNumberChooser * nc = new CMenuOptionNumberChooser(LOCALE_LCDMENU_SCROLL_REPEATS, &g_settings.lcd_scroll, vfd_enabled, 0, 999, this); CMenuOptionNumberChooser * nc = new CMenuOptionNumberChooser(LOCALE_LCDMENU_SCROLL_REPEATS, &g_settings.lcd_scroll, vfd_enabled, 0, 999, this);
nc->setLocalizedValue(0); nc->setLocalizedValue(0, LOCALE_OPTIONS_OFF);
nc->setLocalizedValueName(LOCALE_OPTIONS_OFF);
nc->setHint("", LOCALE_MENU_HINT_VFD_SCROLL); nc->setHint("", LOCALE_MENU_HINT_VFD_SCROLL);
vfds->addItem(nc); vfds->addItem(nc);
} }

View File

@@ -1612,8 +1612,7 @@ void CMenuOptionNumberChooser::init( const neutrino_locale_t& lName,
lower_bound = min_value; lower_bound = min_value;
upper_bound = max_value; upper_bound = max_value;
display_offset = print_offset; display_offset = print_offset;
localized_value = special_value; setLocalizedValue (special_value, special_value_name);
localized_value_name = special_value_name;
observ = Observ; observ = Observ;
slider_on = sliderOn; slider_on = sliderOn;
@@ -1677,18 +1676,24 @@ int CMenuOptionNumberChooser::paint(bool selected)
const char * l_option; const char * l_option;
char option_value[40]; char option_value[40];
if ((localized_value_name == NONEXISTANT_LOCALE) || ((*optionValue) != localized_value)) for (size_t i = 0; i < localized.size(); i++)
{ {
if (numberFormatFunction) { if ((localized[i].value_name == NONEXISTANT_LOCALE) || ((*optionValue) != localized[i].value))
std::string s = numberFormatFunction(*optionValue + display_offset); {
strncpy(option_value, s.c_str(), sizeof(option_value)); if (numberFormatFunction) {
} else std::string s = numberFormatFunction(*optionValue + display_offset);
sprintf(option_value, numberFormat.c_str(), *optionValue + display_offset); strncpy(option_value, s.c_str(), sizeof(option_value));
l_option = option_value; } else
sprintf(option_value, numberFormat.c_str(), *optionValue + display_offset);
l_option = option_value;
}
else
{
l_option = g_Locale->getText(localized[i].value_name);
break;
}
} }
else
l_option = g_Locale->getText(localized_value_name);
//paint item //paint item
prepareItem(selected, height); prepareItem(selected, height);

View File

@@ -323,8 +323,13 @@ private:
int display_offset; int display_offset;
int localized_value; typedef struct localized_value_t
neutrino_locale_t localized_value_name; {
int value;
neutrino_locale_t value_name;
} localized_value_struct_t;
std::vector<localized_value_t> localized;
bool slider_on; bool slider_on;
bool numeric_input; bool numeric_input;
CChangeObserver * observ; CChangeObserver * observ;
@@ -362,8 +367,7 @@ private:
void setNumberFormat(std::string format) { numberFormat = format; } void setNumberFormat(std::string format) { numberFormat = format; }
void setNumberFormat(std::string (*fun)(int)) { numberFormatFunction = fun; } void setNumberFormat(std::string (*fun)(int)) { numberFormatFunction = fun; }
void setNumericInput(bool _numeric_input) { numeric_input = _numeric_input; } void setNumericInput(bool _numeric_input) { numeric_input = _numeric_input; }
void setLocalizedValue(int special_value) { localized_value = special_value; } void setLocalizedValue(int special_value, neutrino_locale_t special_value_name) { localized.push_back({special_value, special_value_name}); }
void setLocalizedValueName(neutrino_locale_t special_value_name) { localized_value_name = special_value_name; }
}; };
class CMenuOptionChooserOptions class CMenuOptionChooserOptions