Coder Social home page Coder Social logo

Comments (12)

GamingMinds-DanielC avatar GamingMinds-DanielC commented on May 31, 2024 1

Classic id conflict, see here for details:
https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-about-the-id-stack-system

It has nothing to do with proximity on the screen. You basically have submitted multiple items with the same id, reacting as one. One way you can solve it is by using ImGui::PushID( (int)row ); and ImGui::PopID(); at the start and end of your loop body.

from imgui.

ocornut avatar ocornut commented on May 31, 2024 1

FYI if you use PushID(row) you don't need to decorate label names, a simple ##DistanceDrag works.

Please browse the Tables section of the Demo as it exhibit many use cases.

from imgui.

ocornut avatar ocornut commented on May 31, 2024

Closing as answered, thank you Daniel!
Indeed the provided link should give you all answers.
I will amend the FAQ entry with a GIF to highlight the common issue.

from imgui.

ocornut avatar ocornut commented on May 31, 2024

I added code (c383795e) to generate this gif:
capture_faq_idstack_gif_0000
And added it to the FAQ entry, along with corresponding UI code.

from imgui.

AshKetshup avatar AshKetshup commented on May 31, 2024

Thanks for your time, I've been so lost lately with this problem

from imgui.

AshKetshup avatar AshKetshup commented on May 31, 2024

I'm sorry I have to reopen the issue, I'm not sure if I understood this. I tried using the PushID and PopID calls to manage this it.
I've read somewhere in a closed issue that naming a label with a pre "##" would hide the label during rendering, even tho it is true on a different row of my table ends up pasting the label without the first character. While it starts messing with the other input fields. Not sure if it is a pointer problem or something related to me using a vector<pair<float, float>> levels to this particular case. I'll be posting also a gif representing this problem.

Recording 2024-05-15 at 04 35 46

Here's my updated code:

{
	if (ImGui::Begin("Tesselation Shader Properties")) {
		if (tS.levels.size() == 0)
			tS.levels.push_back({ 0.f, 0.f });

		sortVPair(tS.levels);
		
		static ImGuiTableFlags flags = ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable;

		if (ImGui::BeginTable("table_scrolly", 2, flags, ImVec2(-FLT_MIN, 5 * ImGui::GetTextLineHeightWithSpacing()))) {
			for (size_t row = 0; row < tS.levels.size(); row++) {
				ImGui::TableNextRow();
				{
					ImGui::TableNextColumn();

					ImGui::PushID(row);
					ImGui::DragFloat("##DistanceDrag" + (row), &( tS.levels[row].first ), 1.f, 0.f, 0.f, "Distance > %.1f");
					ImGui::PopID();
				}

				{
					ImGui::TableNextColumn();

					ImGui::PushID(row);
					ImGui::DragFloat("##LevelDrag" + (row), &( tS.levels[row].second ), 1.f, 0.f, 0.f, "Level : %.1f");
					ImGui::PopID();
				}
			}

			ImGui::EndTable();

		}

		if (ImGui::Button("+"))
			tS.levels.push_back({ 0.f, 0.f });

		ImGui::SameLine();

		ImGui::BeginDisabled(tS.levels.size() <= 1);
		if (ImGui::Button("-"))
			tS.levels.pop_back();
		ImGui::EndDisabled();


		ImGui::End();
	}
}

from imgui.

GamingMinds-DanielC avatar GamingMinds-DanielC commented on May 31, 2024

Your problem is here:
"##DistanceDrag" + (row)

That is not how you construct strings in C++. That's pointer arithmetic. You basically take the string, which is a char*, then offset the pointer itself by the current value of row. So your labels for rows 0, 1 and 2 are "##DistanceDrag", "#DistanceDrag" and "DistanceDrag" respectively, which fits with the observed behavior.

If you want to build your labels with values pasted in, that's called string formatting. One of many ways: take a look at sprintf_s and use it to format a string into a local char array of sufficient size.

from imgui.

AshKetshup avatar AshKetshup commented on May 31, 2024

@GamingMinds-DanielC That does solve the label issue, for sure. I was wondering if it actually had something to do to pointer arithmetic. Although the behaviour itself of the change of values affecting the other fields keeps going and since the smoking gun of pointer arithmetic was already found, i then don't know what might be the problem in the first place. Nice catch tho, thanks.

Btw, I ended up using std::format since I'm working with C++20.

TLDR: Labels are now actually invisible but the fields interfering with each other persists.

from imgui.

GamingMinds-DanielC avatar GamingMinds-DanielC commented on May 31, 2024

TLDR: Labels are now actually invisible but the fields interfering with each other persists.

I'm pretty sure this is your culprit: sortVPair(tS.levels);

You should avoid changing underlying values (if you swap them due to sorting, that counts) while you are actively editing them. My advice would be to sort only after an edit, ImGui::IsItemDeactivatedAfterEdit() can help with that.

from imgui.

AshKetshup avatar AshKetshup commented on May 31, 2024

Thanks, that seems to solve the case! You were right. Since I have your attention do you know how in my case I could make the element widgets stretch themselves to the full width of the cell?

from imgui.

GamingMinds-DanielC avatar GamingMinds-DanielC commented on May 31, 2024

Since I have your attention do you know how in my case I could make the element widgets stretch themselves to the full width of the cell?

Never tried if that works in table cells, but you can try ImGui::SetNextItemWidth(-FLT_MIN). Slightly negative as an offset to the available size. If that doesn't work, you need to calculate or know the size yourself and can use that as a positive value.

from imgui.

AshKetshup avatar AshKetshup commented on May 31, 2024

Thanks to you both. Its all up and running. Thanks for your help!

from imgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.