-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
How do I align multiline text in the center of a button? #6164
Comments
It is currently not possible. I am expecting that in a few version this will become possible. (You can workaround this by rendering text manually over the buttom, if you think this is worth the effort) |
Thank you for the reply. I understand that it is currently not possible. Are you suggesting that I should run ButtonEX() up to RenderFrame() and call SetCursorPos() and Text()? |
Use Button() with a non-visible label “##identifier” then ImDrawList::AddText() call to overlay the text. |
Thank you very much. I gonna try that. : ) |
Thank you. I am now able to do what I was intended to do. If it helps anyone who wants to do the same.
You are welcome to point out what is wrong with the code. |
You shouldn’t need to copy all that code. You can do: PushID(label); |
I think I understand your point correctly.
I am happy with what I wanted to do. What I'm wondering is that I get an error when I try to add two IVec2's together in my code. |
I fully agree it's neater that you wrap this in a helper
No worry, it is a common question (we should probably add it in the FAQ).
The reason we don't expose math operators in imgui.h is that they would conflict with user's/engine's own math operators if I'm thinking it may be neater if we allowed imgui.h to optionally define math operators as a helper for people who don't have their own. |
After defining IMGUI_DEFINE_MATH_OPERATORS, IVec2 can now be added together. I am going to try to do this with the following link. Thank you. |
This discussion prompted me to move this opt-in compile-time feature from imgui_internal.h to imgui,h: And it has been added to the FAQ: |
Just came across this. I am very new to the ImGui library and I just ran into this issue and this post helped me out tremendously, both with fixing the issue itself and learning a bit more about how the text alignment of the library works. I just wanted to share my appreciation for posting this publicly, thanks a ton! |
I'm glad to hear it was helpful. :) |
…ATH_OPERATORS) implementation from imgui_internal.h in imgui.h. (ocornut#6164, ocornut#6137, ocornut#5966, ocornut#2832)
Version/Branch of Dear ImGui:
Version: 1.89
Branch: master
Back-end/Renderer/Compiler/OS
Back-end: GLFW + OpenGL3
Compiler: g++(MinGW)
OS: windows7
My Issue/Question:
I want to align text with an icon font to the center of a button.
If I specify (0.5, 0.5) for ButtonTextAlign, I get the following.
What I am expecting is the following result. (Edited by Photoshop.)
Code:
ImGuiStyle& style = ImGui::GetStyle();
style.ButtonTextAlign = ImVec2(0.5, 0.5);
ImGui::Begin("Button with ICON");
{
ImGui::Button(ICON_FA_WRENCH "\nproperty", ImVec2(120.0, 0.0)); ImGui::SameLine();
ImGui::Button("1st line\n2nd", ImVec2(120.0, 0.0)); ImGui::SameLine();
ImGui::Button(ICON_FA_INFO "\ninfo", ImVec2(120.0, 0.0));
}
ImGui::End();
Is there a parameter that would allow me to achieve this?
The text was updated successfully, but these errors were encountered: