diff options
| author | Philip Dubé <159546+serprex@users.noreply.github.com> | 2026-06-19 15:03:46 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-19 15:03:46 +0000 |
| commit | 00a51c65076e0306910ea78fc86c89beb26da71e (patch) | |
| tree | 2e0d9e47ead74d4870d7777bf0306d028e9505e1 /soh | |
| parent | 497d34570b16e195665dcdf626cf187f0a705708 (diff) | |
fix imgui id conflicts (#6764) (#6771)
ImGui derives a control's ID from its visible label, and the menu search
page renders every widget in a single scope. Randomizer options that share
a label with an enhancement (e.g. "Blue Fire Arrows") therefore produced an
ID conflict on the search page.
Append a "##Randomizer" suffix to randomizer widget labels so their ImGui ID
is unique. The option's own name is left untouched since it is used as a
serialization key (spoiler logs, settings lookup); only the menu widget gets
the suffix.
SliderInt/SliderFloat draw their label themselves via ImGui::Text/CalcTextSize,
which (unlike ImGui's labeled widgets) don't strip a "##" suffix, so add a
visibleLabel with the suffix chopped off for display while keeping the full
label for the unique ID.
Co-authored-by: briaguya <70942617+briaguya0@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'soh')
| -rw-r--r-- | soh/soh/Enhancements/randomizer/option.cpp | 2 | ||||
| -rw-r--r-- | soh/soh/SohGui/UIWidgets.cpp | 28 |
2 files changed, 17 insertions, 13 deletions
diff --git a/soh/soh/Enhancements/randomizer/option.cpp b/soh/soh/Enhancements/randomizer/option.cpp index e6723da96..8ae4f1b3b 100644 --- a/soh/soh/Enhancements/randomizer/option.cpp +++ b/soh/soh/Enhancements/randomizer/option.cpp @@ -215,7 +215,7 @@ Option::Option(size_t key_, std::string name_, std::vector<std::string> options_ } void Option::AddWidget(WidgetPath& path) { - auto widget = SohGui::mSohMenu->AddWidget(path, name, widgetType) + auto widget = SohGui::mSohMenu->AddWidget(path, name + "##Randomizer", widgetType) .Callback(callback) .PreFunc([this](WidgetInfo& info) { info.isHidden = this->IsHidden(); diff --git a/soh/soh/SohGui/UIWidgets.cpp b/soh/soh/SohGui/UIWidgets.cpp index 5a9cafe62..4154fde36 100644 --- a/soh/soh/SohGui/UIWidgets.cpp +++ b/soh/soh/SohGui/UIWidgets.cpp @@ -522,6 +522,8 @@ void PopStyleSlider() { bool SliderInt(const char* label, int32_t* value, const IntSliderOptions& options) { bool dirty = false; + std::string visibleLabelStr = std::string(label).substr(0, std::string(label).find("#")); + const char* visibleLabel = visibleLabelStr.c_str(); std::string invisibleLabelStr = "##" + std::string(label); const char* invisibleLabel = invisibleLabelStr.c_str(); ImGui::PushID(label); @@ -530,11 +532,11 @@ bool SliderInt(const char* label, int32_t* value, const IntSliderOptions& option PushStyleSlider(options.color); float width = (options.size == ImVec2(0, 0)) ? ImGui::GetContentRegionAvail().x : options.size.x; if (options.labelPosition == LabelPositions::Near || options.labelPosition == LabelPositions::Far) { - width = width - (ImGui::CalcTextSize(label).x + ImGui::GetStyle().FramePadding.x); + width = width - (ImGui::CalcTextSize(visibleLabel).x + ImGui::GetStyle().FramePadding.x); } ImGui::AlignTextToFramePadding(); if (options.alignment == ComponentAlignments::Right) { - ImGui::Text(label, *value); + ImGui::Text(visibleLabel, *value); if (options.labelPosition == LabelPositions::Above) { ImGui::NewLine(); ImGui::SameLine(ImGui::GetContentRegionAvail().x - width); @@ -545,7 +547,7 @@ bool SliderInt(const char* label, int32_t* value, const IntSliderOptions& option } } else if (options.alignment == ComponentAlignments::Left) { if (options.labelPosition == LabelPositions::Above) { - ImGui::Text(label, *value); + ImGui::Text(visibleLabel, *value); } } if (options.showButtons) { @@ -590,11 +592,11 @@ bool SliderInt(const char* label, int32_t* value, const IntSliderOptions& option if (options.alignment == ComponentAlignments::Left) { if (options.labelPosition == LabelPositions::Near) { ImGui::SameLine(); - ImGui::Text(label, *value); + ImGui::Text(visibleLabel, *value); } else if (options.labelPosition == LabelPositions::Far || options.labelPosition == LabelPositions::None) { - ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x + + ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(visibleLabel).x + ImGui::GetStyle().ItemSpacing.x); - ImGui::Text(label, *value); + ImGui::Text(visibleLabel, *value); } } PopStyleSlider(); @@ -654,6 +656,8 @@ void ClampFloat(float* value, float min, float max, float step) { bool SliderFloat(const char* label, float* value, const FloatSliderOptions& options) { bool dirty = false; + std::string visibleLabelStr = std::string(label).substr(0, std::string(label).find("#")); + const char* visibleLabel = visibleLabelStr.c_str(); std::string invisibleLabelStr = "##" + std::string(label); const char* invisibleLabel = invisibleLabelStr.c_str(); float valueToDisplay = options.isPercentage ? *value * 100.0f : *value; @@ -663,14 +667,14 @@ bool SliderFloat(const char* label, float* value, const FloatSliderOptions& opti ImGui::BeginGroup(); ImGui::BeginDisabled(options.disabled); PushStyleSlider(options.color); - float labelSpacing = ImGui::CalcTextSize(label).x + ImGui::GetStyle().ItemSpacing.x; + float labelSpacing = ImGui::CalcTextSize(visibleLabel).x + ImGui::GetStyle().ItemSpacing.x; float width = (options.size == ImVec2(0, 0)) ? ImGui::GetContentRegionAvail().x : options.size.x; if (options.labelPosition == LabelPositions::Near || options.labelPosition == LabelPositions::Far) { - width = width - (ImGui::CalcTextSize(label).x + ImGui::GetStyle().FramePadding.x); + width = width - (ImGui::CalcTextSize(visibleLabel).x + ImGui::GetStyle().FramePadding.x); } ImGui::AlignTextToFramePadding(); if (options.alignment == ComponentAlignments::Right) { - ImGui::Text(label, *value); + ImGui::Text(visibleLabel, *value); if (options.labelPosition == LabelPositions::Above) { ImGui::NewLine(); ImGui::SameLine(ImGui::GetContentRegionAvail().x - width); @@ -683,7 +687,7 @@ bool SliderFloat(const char* label, float* value, const FloatSliderOptions& opti } } else if (options.alignment == ComponentAlignments::Left) { if (options.labelPosition == LabelPositions::Above) { - ImGui::Text(label, *value); + ImGui::Text(visibleLabel, *value); } } if (options.showButtons) { @@ -722,10 +726,10 @@ bool SliderFloat(const char* label, float* value, const FloatSliderOptions& opti if (options.alignment == ComponentAlignments::Left) { if (options.labelPosition == LabelPositions::Near) { ImGui::SameLine(); - ImGui::Text(label, *value); + ImGui::Text(visibleLabel, *value); } else if (options.labelPosition == LabelPositions::Far || options.labelPosition == LabelPositions::None) { ImGui::SameLine(ImGui::GetContentRegionAvail().x - labelSpacing); - ImGui::Text(label, *value); + ImGui::Text(visibleLabel, *value); } } PopStyleSlider(); |
