ocornut / imgui

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

Hmm strange extra padding on the right of framed widgets #6309

Closed TomieAi closed 1 year ago

TomieAi commented 1 year ago

Version/Branch of Dear ImGui:

Version: 1.89.5 WIP Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_dx12.cpp+ imgui_impl_win32.cpp Compiler: MSVC x64 (2022) Operating System: Win11

My Issue/Question:

What's with the weird padding on the right? ImGuiWindowFlags_AlwaysAutoResize is doing it perfectly perfect padding on left and right.. without it .. its weird xD its not balance even if u make the window small it retain its extra padding on the right. large padding

how can i achieve what ImGuiWindowFlags_AlwaysAutoResize does without using it xD i just like the perfect padding but still resizable

Screenshots

without ImGuiWindowFlags_AlwaysAutoResize image

with ImGuiWindowFlags_AlwaysAutoResize image

            ImGui::Begin("aa", nullptr, ImGuiWindowFlags_AlwaysAutoResize);   

            ImGui::BeginTabBar("MyTabBar", ImGuiTabBarFlags_None);

            if (ImGui::BeginTabItem("TEST")) {
                ImGui::Spacing();
                ImGui::SliderFloat("##aaa", &dist, 0.0f, 1.0f);
                ImGui::Spacing();
                ImGui::Spacing();
                ImGui::EndTabItem();
            }

            if (ImGui::BeginTabItem("Tab 2")) {
                ImGui::EndTabItem();
            }

            ImGui::EndTabBar();

            ImGui::End();
TomieAi commented 1 year ago

nvm i think i found it

ocornut commented 1 year ago

See "Demo>Layout&Scrolling->Widgets Width" to understand this.

A regular window has default ItemWidth (for framed widgets) of about 65% of the window width. You can change it with PushItemWidth() and SetNextItemWidth() A widget with ImGuiWindowFlags_AlwaysAutoResize CANNOT have a default ItemWidth propotional to window width, because window width is derived from item widths... So when ImGuiWindowFlags_AlwaysAutoResize is set the default ItemWidth is based on font size.

Code in Begin();

// Default item width. Make it proportional to window size if window manually resizes
if (window->Size.x > 0.0f && !(flags & ImGuiWindowFlags_Tooltip) && !(flags & ImGuiWindowFlags_AlwaysAutoResize))
    window->ItemWidthDefault = ImFloor(window->Size.x * 0.65f);
else
    window->ItemWidthDefault = ImFloor(g.FontSize * 16.0f);