Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sliders change unwanted on clicking other slider #7375

Closed
ghost opened this issue Mar 7, 2024 · 5 comments
Closed

Sliders change unwanted on clicking other slider #7375

ghost opened this issue Mar 7, 2024 · 5 comments
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@ghost
Copy link

ghost commented Mar 7, 2024

Version/Branch of Dear ImGui:

1.90.4

Back-ends:

IrrImGUI

Compiler, OS:

MSVC (Windows)

Full config/build information:

No response

Details:

Look at code/video

Screenshots/Video:

error_w_sliders.webm

Minimal, Complete and Verifiable Example code:

        static int o_selection=1;
	ImGui::SetNextItemWidth(p(screenSize.Width,68));
	ImGui::SliderInt("", &o_selection, 1, 2, "");

	if(o_selection==1) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); }
	ImGui::Text(translate("Online Multiplayer").c_str());
	if(o_selection==1) { ImGui::PopStyleColor(); } else { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); }
	ImGui::SameLine();
	ImGui::SetCursorPosX(p(screenSize.Width,69)-ImGui::CalcTextSize(translate("Local Singleplayer").c_str()).x);
	ImGui::Text(translate("Local Singleplayer").c_str());
	if(o_selection==2){ ImGui::PopStyleColor(); }

	ImGui::SeparatorText(translate("Difficulty").c_str());
	static float difficulty=0.5;
	ImGui::SetNextItemWidth(p(screenSize.Width,68));
	ImGui::SliderFloat("", &difficulty, 0.5f, 10.0f);
@PathogenDavid
Copy link
Contributor

PathogenDavid commented Mar 7, 2024

@ocornut ocornut added the label/id and id stack implicit identifiers, pushid(), id stack label Mar 7, 2024
@ocornut
Copy link
Owner

ocornut commented Mar 7, 2024

ID must generally be unique as stated in FAQ. You can use "##SomeName" to hide the label. See link posted by David.

@ocornut ocornut closed this as completed Mar 7, 2024
@PathogenDavid
Copy link
Contributor

Also make sure you have asserts enabled (usually that just means running a debug build instead of release), there's one that would've alerted you to your empty ID mistake:

imgui/imgui.cpp

Lines 9902 to 9905 in 286cd5b

// [DEBUG] People keep stumbling on this problem and using "" as identifier in the root of a window instead of "##something".
// Empty identifier are valid and useful in a small amount of cases, but 99.9% of the time you want to use "##something".
// READ THE FAQ: https://dearimgui.com/faq
IM_ASSERT(id != window->ID && "Cannot have an empty ID at the root of a window. If you need an empty label, use ## and read the FAQ about how the ID Stack works!");

@ghost
Copy link
Author

ghost commented Mar 7, 2024

Ah nice! Thanks the ID is the name?

@PathogenDavid
Copy link
Contributor

Yes, but also no. You should read the full FAQ for the details.

The label and the ID are separate concepts. The ID is also influenced by the label, but also by the window which contains the widget. Additionally the visible part of the label isn't used for the ID when using ###.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
label/id and id stack implicit identifiers, pushid(), id stack
Projects
None yet
Development

No branches or pull requests

2 participants