imgui icon indicating copy to clipboard operation
imgui copied to clipboard

Left upper corner coordinates and child window dimensions for different border thicknesses

Open ElectroidDes opened this issue 1 year ago • 3 comments

Version/Branch of Dear ImGui:

1.90.8

Back-ends:

Raylib

Compiler, OS:

Windows10

Full config/build information:

No response

Details:

For different values ​​of the child window frame width - the return value of the child window size GetWindowSize - differs from the actual visible size.

The same applies to the position of the Upper Left corner of the Child Window. For different values ​​of the child window frame width - the return value of the child window position GetWindowPos - differs from the actual visible position.

Because of this, it is just impossible to accurately position and calculate the necessary coordinates of objects.

ImGui::Begin("Main Window");

    //---------------------------------------------------------------------------
    float border_thickness1 = 1;
    ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, border_thickness1);
    ImGui::BeginChild("Child Window 1", ImVec2(180, 180), true);
    ImGui::Text(&(std::to_string((int)ImGui::GetWindowWidth()) + ":" + std::to_string((int)ImGui::GetWindowHeight()))[0]);
    ImGui::Text(&(std::to_string((int)ImGui::GetCursorPos().x) + ":" + std::to_string((int)ImGui::GetCursorPos().y))[0]);

    ImGui::EndChild();
    ImGui::PopStyleVar();
    //---------------------------------------------------------------------------

    ImGui::SameLine();

    //---------------------------------------------------------------------------
    float border_thickness2 = 2;
    ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, border_thickness2);
    ImGui::BeginChild("Child Window 2", ImVec2(180, 180), true);
    ImGui::Text(&(std::to_string((int)ImGui::GetWindowWidth()) + ":" + std::to_string((int)ImGui::GetWindowHeight()))[0]);
    ImGui::Text(&(std::to_string((int)ImGui::GetCursorPos().x) + ":" + std::to_string((int)ImGui::GetCursorPos().y))[0]);

    ImGui::EndChild();
    ImGui::PopStyleVar();
    //---------------------------------------------------------------------------

    ImGui::SameLine();

    //---------------------------------------------------------------------------
    float border_thickness4 = 3;
    ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, border_thickness4);
    ImGui::BeginChild("Child Window 4", ImVec2(180, 180), true);
    ImGui::Text(&(std::to_string((int)ImGui::GetWindowWidth()) + ":" + std::to_string((int)ImGui::GetWindowHeight()))[0]);
    ImGui::Text(&(std::to_string((int)ImGui::GetCursorPos().x) + ":" + std::to_string((int)ImGui::GetCursorPos().y))[0]);

    ImGui::EndChild();
    ImGui::PopStyleVar();
    //---------------------------------------------------------------------------

    ImGui::SameLine();

    //---------------------------------------------------------------------------
    float border_thickness7 = 4;
    ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, border_thickness7);
    ImGui::BeginChild("Child Window 7", ImVec2(180, 180), true);
    ImGui::Text(&(std::to_string((int)ImGui::GetWindowWidth()) + ":" + std::to_string((int)ImGui::GetWindowHeight()))[0]);
    ImGui::Text(&(std::to_string((int)ImGui::GetCursorPos().x) + ":" + std::to_string((int)ImGui::GetCursorPos().y))[0]);

    ImGui::EndChild();
    ImGui::PopStyleVar();
    //---------------------------------------------------------------------------

    ImGui::SameLine();

    //---------------------------------------------------------------------------
    float border_thickness8 = 15;
    ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, border_thickness8);
    ImGui::BeginChild("Child Window 8", ImVec2(180, 180), true);
    ImGui::Text(&(std::to_string((int)ImGui::GetWindowWidth()) + ":" + std::to_string((int)ImGui::GetWindowHeight()))[0]);
    ImGui::Text(&(std::to_string((int)ImGui::GetCursorPos().x) + ":" + std::to_string((int)ImGui::GetCursorPos().y))[0]);

    ImGui::EndChild();
    ImGui::PopStyleVar();
    //---------------------------------------------------------------------------


    ImGui::End();

Screenshots/Video:

image

ElectroidDes avatar Aug 14 '24 17:08 ElectroidDes

All windows are positioned via SameLine.

As you can see, changing the width of the window frame (and other widgets too) - Breaks Everything.

image

ElectroidDes avatar Aug 14 '24 18:08 ElectroidDes

This is pretty similar to #7887, i don't need we need two issues.

  • Right now thick borders are not supported.
  • I think part of the problem is that you have the assumption that GetWindowSize() has some meaningful value for your layout. It doesn't and never had. GetWindowSize() was never advertised as "visible size" they are paddings involved.

I believe the two actions I want to do eventually do (but hold your breath) are.

  • As per #7887, i generally agree we should aim to move thick border to become "inner" border.
  • When we do that we can consider border size to apply on top of window padding, which will reduce available space (again, available space is NOT GetWindowSize()).

ocornut avatar Aug 20 '24 15:08 ocornut

For now I have pushed e471206 which makes the default clip rect match the border centered around windows edges. This should make both #7887 and #7888 a little less confusing.

But ultimately the solution would be the two points above.

ocornut avatar Aug 20 '24 15:08 ocornut