mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-01 22:30:42 -07:00
cfg: fix combo boxes (#429)
## Link to GitHub Issue, if one exists n/a ## Description of change Combo boxes for options were not highlighting the currently selected item. Also, when there were no description provided for an option, it was still showing the empty `()` in the selected value. ## Testing
This commit is contained in:
@@ -2828,19 +2828,23 @@ namespace overlay::windows {
|
|||||||
std::string current_item = option.value_text();
|
std::string current_item = option.value_text();
|
||||||
for (auto &element : definition.elements) {
|
for (auto &element : definition.elements) {
|
||||||
if (element.first == current_item) {
|
if (element.first == current_item) {
|
||||||
|
if (!element.second.empty()) {
|
||||||
current_item += fmt::format(" ({})", element.second);
|
current_item += fmt::format(" ({})", element.second);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (current_item.empty()) {
|
if (current_item.empty()) {
|
||||||
current_item = "Default";
|
current_item = "Default";
|
||||||
}
|
}
|
||||||
if (ImGui::BeginCombo("##combo", current_item.c_str(), 0)) {
|
if (ImGui::BeginCombo("##combo", current_item.c_str(), 0)) {
|
||||||
for (auto &element : definition.elements) {
|
for (auto &element : definition.elements) {
|
||||||
bool selected = current_item == element.first;
|
|
||||||
std::string label = element.first;
|
std::string label = element.first;
|
||||||
if (!element.second.empty()) {
|
if (!element.second.empty()) {
|
||||||
label += fmt::format(" ({})", element.second);
|
label += fmt::format(" ({})", element.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool selected = current_item == label;
|
||||||
if (ImGui::Selectable(label.c_str(), selected)) {
|
if (ImGui::Selectable(label.c_str(), selected)) {
|
||||||
this->options_dirty = true;
|
this->options_dirty = true;
|
||||||
option.value = element.first;
|
option.value = element.first;
|
||||||
|
|||||||
Reference in New Issue
Block a user