Skip to content

Dynamically remove window padding after Begin() call #3756

Closed
@Vine1

Description

Hello! I'm developing my custom menu bar. It should look like a rectangle at top of the window, without paddings at the top, left, and right sides. My style has window padding for child windows, but ImGui uses this option for the simple windows too. So, my menu bar draws indented My application architecture draws UI element by element, after Begin call, so I can't give access to an element to call PushStyleVar(ImGuiStyleVar_WindowPadding) before Begin(). Also, the menu bar may be dynamically removed and added back, so, I can't just statically push the window padding variable before Begin() call. Also, change the style.WindowPadding I can't too because I need padding for child windows, and maybe in the future, I will need window padding for simple windows without a custom menu bar.
So, Is it possible to remove the current window padding after Begin() (or maybe just draw one frame bypassing padding)?
What I have tried already:

  • Set DC.CursorPos to window->Pos
  • Set DC.CursorStartPos to window->Pos
  • Set DC.CursorPosPrevLine to window->Pos
  • Set DC.Indent to 0
  • Set window->ContentRegionRect to (0, 0)
  • Set window->InnerRect to (0, 0)
  • Set window->ClipRect to (0, 0)
  • Set window->InnerClipRect to (0, 0)
  • Set window->WorkRect to (0, 0)
  • Set window->WindowPadding to (0, 0)

Nothing worked. If it's not possible, I'll find a way to call PushStyleVar before Begin(), but it'll hurt the architecture.
I hope for your help! Thanks in advance!

EDIT:
Example:

       ImGui::Begin("Window");
       
       const ImVec2 pos = ImGui::GetWindowPos();
       const ImVec2 size = ImGui::GetWindowSize();
       const ImU32 col = ImGui::GetColorU32(ImVec4(0, 1, 0, 1));

       ImGui::GetWindowDrawList()->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + 200), col);
       
       ImGui::End();

Screenshot with padding 20:
image
And with padding 0:
image

Why even drawing through ImDrawList depends on padding? How to bypass it?

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions