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

Add text_baseline_y to ImGui::Dummy #4549

Open
codecat opened this issue Sep 16, 2021 · 2 comments
Open

Add text_baseline_y to ImGui::Dummy #4549

codecat opened this issue Sep 16, 2021 · 2 comments
Labels

Comments

@codecat
Copy link
Contributor

codecat commented Sep 16, 2021

Version/Branch of Dear ImGui:

Version: 1.84.1
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_win32.cpp + imgui_impl_dx11.cpp
Operating System: Windows

My Issue/Question:

For custom controls, it would be useful to have access to the baseline offset from ImGui::Dummy which would be passed down to ItemSize.

imgui/imgui_widgets.cpp

Lines 1319 to 1328 in 2d0a6a4

void ImGui::Dummy(const ImVec2& size)
{
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return;
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
ItemSize(size);
ItemAdd(bb, 0);
}

Screenshots/Video

My custom control is a simple tag, which is a colored background around around some text. In the below screenshots, note the test text is an ImGui::Text after ImGui::SameLine.

Without baseline offset:
image

With baseline offset:
image

Standalone, minimal, complete and verifiable example: (see #2261)

ImGui::Begin("Example Bug");
ImGui::Dummy(ImVec2(32, 32));
ImGui::SameLine();
ImGui::Text("Hello");
ImGui::End();
@codecat
Copy link
Contributor Author

codecat commented Sep 16, 2021

As a workaround, I've included imgui_internal.h and wrote my own function:

static void ScriptUI_DummyEx(const glm::vec2& size, float text_baseline_y)
{
	//NOTE: Same as ImGui::Dummy, but with the added baseline parameter

	ImGuiWindow* window = ImGui::GetCurrentWindow();
	if (window->SkipItems) {
		return;
	}

	const ImRect bb(window->DC.CursorPos, ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y + size.y));
	ImGui::ItemSize(ImVec2(size.x, size.y), text_baseline_y);
	ImGui::ItemAdd(bb, 0);
}

@ocornut ocornut added the layout label Sep 16, 2021
@ocornut
Copy link
Owner

ocornut commented Sep 16, 2021

Hello,
For now I suggest you keep using your helper DummyEx(). I'll like to keep this open as I'm been unhappy with the amount of issues caused by text baseline features and I'd like to consider a better overall solution (maybe have baseline as a style var).

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

No branches or pull requests

2 participants