ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.11k stars 10.3k forks source link

Selectable doesn't align the label properly #2601

Closed przemkovv closed 4 years ago

przemkovv commented 5 years ago

Version/Branch of Dear ImGui:

Version: 1.69

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp Operating System: Windows

My Issue/Question:

ImGui::Selectable suppose to support aligning the label. If ImGuiStyleVar_SelectableTextAlign style is set to ImVec2(0.5f, 0.5f), the text should be centered. Unfortunately, the style value is "indirectly" ignored.

I think, that bb_inner in the ImGui::Selectable function is wrongly computed, as it stores the size of text, not the widget. In the result, RenderTextClipped has no room to operate. If I replace bb_inner in the call with bb, it works as expected.

Screenshots/Video

That it looks now: obraz

Expected result: obraz

Standalone, minimal, complete and verifiable example:

        ImGui::Begin("Test");
        static bool test = false;
        ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, ImVec2(0.5f, 0.5f));
        ImGui::Selectable("Test", &test);
        ImGui::PopStyleVar();
        ImGui::End();
twaritwaikar commented 4 years ago

Found this appearing in my setup too:


Version/Branch of Dear ImGui:

Version: 1.76 WIP Branch: docking

Back-end/Renderer/Compiler/OS

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

twaritwaikar commented 4 years ago
ImGui::Begin("Test");
static bool test = false;
ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, ImVec2(0.5f, 0.5f));
ImGui::Selectable("Test", &test, 0, ImVec2(80,10));
ImGui::PopStyleVar();
ImGui::End();

ImGui::Begin("Test");
static bool test = false;
ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, ImVec2(0.5f, 0.5f));
ImGui::Selectable("Test", &test);
ImGui::PopStyleVar();
ImGui::End();

The two overloads for Selectable() behave differently. The one with the bool* selected parameter is working as expected

ocornut commented 4 years ago

Hello @przemkovv, @IronicallySerious,

Sorry for my late answer. This should be fixed now. (it's not merged in Docking right away but will be soon). It was an issue in the initial commit from #2347.

Thanks!

I'm currently working on Selectable() and cleaning a few confusing things that have been accumulating over time (pushed 3 small commits already). Some other changes incoming to fix issues dealing with multiple columns spanning in Tables/Columns api.