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

Popup Modal window initial size ? #3239

Closed
DaveInDev opened this issue May 17, 2020 · 2 comments
Closed

Popup Modal window initial size ? #3239

DaveInDev opened this issue May 17, 2020 · 2 comments

Comments

@DaveInDev
Copy link

Version: Dear ImGui 1.77 WIP (17601)
Branch: master
Back-ends: SFML
Compiler: VS2019 c++
Operating System: win10x64

Hi Omar,

I really have problem with sizing objects...

Here is the code of a little confirmation popup (a window with a variable title and yes/no buttons that returns 0 if nothing if clicked, 1 if no, 2 if yes)

The problem is that the popup width is sized to the 2 buttons, not to the title bar. Is there a way to autosize this correctly at first appearing (the title can have variable length) ?

image

	Uint8 Confirm(const std::string& title)
	{
		static bool showWindow = false;
		Uint8 ret = 0;
		std::string s = title + "###confirm";

		if (!showWindow)
		{
			ImGui::OpenPopup(s.c_str());
			showWindow = true;
		}

		if (ImGui::BeginPopupModal(s.c_str(),nullptr))
		{
			if (ImGui::Button("Yes"))
			{
				showWindow = false;
				ImGui::CloseCurrentPopup();
				ret = 2;
			}

			ImGui::SameLine();

			if (ImGui::Button("No"))
			{
				showWindow = false;
				ImGui::CloseCurrentPopup();
				ret = 1;
			}
			ImGui::EndPopup();
		}

		return(ret);
	}

@ocornut
Copy link
Owner

ocornut commented May 18, 2020

Hello,

It's been always the case that title bar width doesn't contribute to width calculation.
(e.g. #176 (comment))

I don't imagine we should allocate a window flag for that, we could decide it would be a global style flag however it would be ambiguous and misleading when switching single windows to be using tabs in the docking branch, so I'm not sure this is a good idea right now.

You can enforce a minimum automatic width for the window by using, e.g.

ImGui::Begin(...)
ImGui::SetCursorPosX(some_width)
ImGui::SetCursorPosX(0.0f)
[...]

That will feed into the auto calculated width.
some_width may be CalcTextSize(title).x + GetFrameHeight() * number_of_visible button.

Not suggesting this is a great solution but it might be good enough in your case?

@DaveInDev
Copy link
Author

Hi Omar,
Thanks for your answer.
I do not understand why a global flag would not be desirable : I still do not find very "nice" that a simple window opens with its title truncated... But you know the code repercussions better than me ;-)
Anyway, thanks for the trick, it does the job !

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