restrict slider ui to slider fields

This commit is contained in:
GenevensiS
2025-12-13 23:06:18 +01:00
parent 3b7d4b617f
commit aa0791686e
3 changed files with 21 additions and 24 deletions
+8 -7
View File
@@ -33,13 +33,14 @@ public:
class Choice;
typedef intrusive_ptr<Choice> ChoiceP;
ChoiceP choices; ///< A choice group of possible choices
OptionalScript script; ///< Script to apply to all values
OptionalScript default_script; ///< Script that generates the default value
String initial; ///< Initial choice of a new value, or ""
String default_name; ///< Name of "default" value
map<String,Color> choice_colors; ///< Colors for the various choices (when color_cardlist)
map<String,Color> choice_colors_cardlist; ///< Colors for the various choices, for in the card list
ChoiceP choices; ///< A choice group of possible choices
OptionalScript script; ///< Script to apply to all values
OptionalScript default_script; ///< Script that generates the default value
String initial; ///< Initial choice of a new value, or ""
String default_name; ///< Name of "default" value
map<String,Color> choice_colors; ///< Colors for the various choices (when color_cardlist)
map<String,Color> choice_colors_cardlist; ///< Colors for the various choices, for in the card list
bool is_slider = false; ///< Should the UI be displayed as a slider?
void initDependencies(Context&, const Dependency&) const override;
void after_reading(Version ver) override;
+2
View File
@@ -35,6 +35,8 @@ IMPLEMENT_REFLECTION(SliderField) {
void SliderField::after_reading(Version ver) {
Field::after_reading(ver);
is_slider = true;
int choice_count = choices->choices.size();
if (maximum < minimum) swap(minimum, maximum);
+9 -15
View File
@@ -202,27 +202,21 @@ DropDownChoiceList::DropDownChoiceList(Window* parent, bool is_submenu, ValueVie
: DropDownChoiceListBase(parent, is_submenu, cve, group)
{
// determine if slider
size_t count = itemCount();
if (count > 3) {
int value;
try {
String first_item = capitalize(itemText(0));
if (first_item != _("Default")) value = std::stoi(first_item.ToStdString());
value = std::stoi(itemText(1).ToStdString());
value = std::stoi(itemText(count - 2).ToStdString());
value = std::stoi(itemText(count - 1).ToStdString());
// the choices are numbers, use a slider
is_slider = true;
// load slider images if needed
if (!slider_loaded) {
slider_loaded = true;
if (itemCount() > 1 && field().is_slider) {
is_slider = true;
// load slider images if needed
if (!slider_loaded) {
slider_loaded = true;
try {
slider_left = load_resource_image(_("slider_left"));
slider_right = load_resource_image(_("slider_right"));
slider_center = load_resource_image(_("slider_center"));
slider_tick = load_resource_image(_("slider_tick"));
}
catch (...) {
throw InternalError(_("Can't load slider resources"));
}
}
catch (...) {}
}
}