ocornut / imgui

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

Bug with AddRectFilled/WindowDrawList? #811

Closed edin-purkovic closed 8 years ago

edin-purkovic commented 8 years ago

Hi Omar, thanks for this awesome gui lib.. started using it few days ago for writing my 3D editor so its maybe my lack of knowledge and done by design or possible bug?

im rendering 2 imgui windows, one for titlebar and one for workspace so it draws only one part of the red square using: ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(), ImVec2(100,110), ImGui::ColorConvertFloat4ToU32(ImVec4(1, .15, .15, 1)));

and thats fine but there is an offset in x as you can see in the picture and its always half of ImGuiStyleVar_WindowPadding.. if its by design is there a way to draw the rect from 0,0? I used 24,0 just for debuging for ImGuiStyleVar_WindowPadding and the child is drawn at 24 but the AddRectFilled at 12..

Another question is how to force GetWindowDrawList to draw on top of everything? it draws on top of buttons but behind child windows as in the pic even if the AddRectFilled is called after everything else..

13892348_949422815167907_7483109795979410214_n

ocornut commented 8 years ago

By default the window pushes a clipping rectangle (ImGui::PushClipRect / ImDrawList::PushClipRect) with that amount of padding. The half WindowPadding match the amount that e.g. CollapsingHeader uses to extend itself slightly

If you want to draw fullscreen or go off the current clipping rectangle you can call ImGui::PushClipRect() setting the third parameter as false.

Another question is how to force GetWindowDrawList to draw on top of everything?

Drawing commands are processed in order within a window (there's a channel split api for out of order rendering but it isn't what you want there), and then child window are drawn after their parent. There's no explicit finer control of z-ordering yet, but if you have child windows and you want your rectangle to draw over them, a workaround is to create a final child window, push a fullscreen clip rectangle and draw there. There's an OverlayDrawList in imgui_internal.h (not exposed yet) which is basically just a ImDrawList that drawn last. Or you can either create your own ImDrawList.

You can inspect the draw order in the metrics window (call ShowMetricsWindow()).

edin-purkovic commented 8 years ago

Thank you! That worked! Im gonna close this now, and before that a pic of my current progress :) working on docking, imgui makes it quite easy and looking beautiful...

13892348_949422815167907_7483109795979410214_n ..

ocornut commented 8 years ago

Nice! Please don't hesitate to post shots in #772 There's some docking code in #351 which I never had the time to look at myself, but the intent would be to make docking an official feature/extension at some point.

edin-purkovic commented 8 years ago

Will do today, after i update it a little.. as for docking ImWindow looks nice but too complex and lumix does look nice too but doesnt allow docking out of platform window like imWindow does, does have one frame lag to compute dock sizes i guess which i dont like xD and they both lack more control about initial positioning and sizing.. so i wrote my docking, currently around 500loc and when finished around 600 combined for header+source file and have a lot more of control over layout

nem0 commented 8 years ago

is your docking code available?

ocornut commented 8 years ago

Please move this to the other thread as well, so people can find it :)

edin-purkovic commented 8 years ago

@nem0 not yet, its not ready, after i finish it i will release it on my github and link it in #351 , used simple buttons for prototyping for tabbar so have to rewrite that and have to figure how to dock from one platform window to another, then clean the code a little.. but it wont be too hard i guess/hope, also to mention it does not follow imgui style, docks are not resubmited every frame for example and i use std::function but that could be easily changed to function pointers.. now.. moving to the other thread :)