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

VB-style NumericUpDown Emulation #8486

Open
kilohercas opened this issue Mar 11, 2025 · 3 comments
Open

VB-style NumericUpDown Emulation #8486

kilohercas opened this issue Mar 11, 2025 · 3 comments

Comments

@kilohercas
Copy link

kilohercas commented Mar 11, 2025

Version/Branch of Dear ImGui:

Version 1.XX, Branch: XXX (master/docking/etc.)

Back-ends:

dear imgui, v1.91.9 WIP

Compiler, OS:

windows 11 visual studio 22

Full config/build information:

Newest example code just with very little modifications, like single window. That's about all.

Details:

Hello. I am trying to rewrite my .NET c# application with graphs due to performance and inconsistency issues running my high update rate code. So far I am very happy with ImGui, i can get at least 20% performance increase ( limited by USB communication) with near zero processor load ( instead of pinned thread to the max on .NET C#)

Problem I am having i need to emulate numeric up down with limits and changes should come from few places:

  1. Writing int32 it must be changed only on enter event (or cursor goes out of control box)
  2. mouse scroll wheel for increment and decrement
  3. arrows for increment and decrement

Problem I am having is that I can't get all features to work, only can get some working before others start mysteriously failing. Bu the looks of it, it seems that I can't set input control to value, and it's just overwrites changes I made.
Here is my best working code so far:

`
static int32_t value = 0;
static int32_t tempValue = 0;

void ShowFiveWindowLayout()
{
const int32_t step = 1;
const int32_t minValue = 0, maxValue = 100;

    ImGui::InputInt("##", &tempValue, 1, 20, ImGuiInputTextFlags_None);

if (ImGui::IsItemActive())
{
	if (ImGui::IsKeyPressed(ImGuiKey_UpArrow))
	{
		tempValue += step;
	}
	if (ImGui::IsKeyPressed(ImGuiKey_DownArrow))
	{
		tempValue -= step;
	}
}

if (ImGui::IsItemHovered())
{
	float scroll = ImGui::GetIO().MouseWheel;
	if (scroll > 0.0f)
	{
		tempValue += step; // Scroll Up
		value = tempValue;
	}
	if (scroll < 0.0f)
	{
		tempValue -= step; // Scroll Down
		value = tempValue;
	}
}

if (ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_KeypadEnter))
{
	enterPressed = true;
}

tempValue = tempValue < minValue ? minValue : tempValue;
tempValue = tempValue > maxValue ? maxValue : tempValue;

if (ImGui::IsItemDeactivatedAfterEdit() || enterPressed)
{
	value = tempValue;
}

ImGui::Text("Current Value: %d", value);

}
`

So in this code, +- signs near control work, writing text manually and pressing enter also work, cursor going out of control also work. what does not work is arrows and mouse wheel. ( they are triggered but it just get stuck into +-1 range. Any idea how to fix this ? using chatGPT does not help, one works, other fails...

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

// Here's some code anyone can copy and paste to reproduce your issue
ImGui::Begin("Example Bug");
MoreCodeToExplainMyIssue();
ImGui::End();
@leonardovac
Copy link

This?

static int32_t value = 0;
static int32_t tempValue = 0;

void ShowFiveWindowLayout()
{
	const int32_t step = 1;
	const int32_t minValue = 0, maxValue = 100;

	ImGui::InputInt("##", &tempValue, 1, 20, ImGuiInputTextFlags_None);

	if (ImGui::IsItemHovered())
	{
		if (ImGui::IsKeyPressed(ImGuiKey_UpArrow))
		{
			tempValue += step;
		}
		if (ImGui::IsKeyPressed(ImGuiKey_DownArrow))
		{
			tempValue -= step;
		}
	}

	if (ImGui::IsItemHovered())
	{
		float scroll = ImGui::GetIO().MouseWheel;
		if (scroll > 0.0f)
		{
			tempValue += step; // Scroll Up
			value = tempValue;
		}
		if (scroll < 0.0f)
		{
			tempValue -= step; // Scroll Down
			value = tempValue;
		}
	}

	tempValue = tempValue < minValue ? minValue : tempValue;
	tempValue = tempValue > maxValue ? maxValue : tempValue;

	if (ImGui::IsItemDeactivatedAfterEdit() || !ImGui::IsItemHovered() || ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_KeypadEnter))
	{
		value = tempValue;
	}

	ImGui::Text("Current Value: %d", value);

}

@kilohercas
Copy link
Author

Hi,
Thank you for your time on this case.
But same problem. placing enter works, pressing +- works,but mouse wheel and arrows gives +-1 and that it....
I don't understand why enter works, but not arrows or mouse.

added project, sorry for the mess, still just trying to understand how to do things.

LLMPSSE (2).zip

@kilohercas
Copy link
Author

Any more ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants