Open michaelis79 opened 2 years ago
Hi, shouldn't you have to subtract the title bar height?
Sorry, How can i get the title bar height?
Sorry for reviving a dead thread after a year, but I am running into the same issue. Did you find any solution in the end @darwinharianto ?
I've just looked at the source code and DPG doesn't seem to report the height of the title bar. However, ImGui does have an internal-looking function for that (i.e. not API), and the title bar height is always computed as (font_size + 2 * frame_padding.y)
.
You can get the font size via dpg.get_text_size("")
- without text, should probably work even on the 1st frame, but maybe won't - try it out. Worst case you'll need a 1-frame delay of your initialization.
As for the frame padding, I'm not sure if there's a way to retrieve it, but certainly you can set it to your own value and use that value; or you can rely on ImGui's default value of 3 pixels (don't forget to multiply by 2 per the formula above).
FramePadding = ImVec2(4,3); // Padding within a framed rectangle (used by most widgets)
Note that on high DPI screens, like Retina found on MacBook, those 3 pixels might get scaled to 6 - I don't have a Mac and can't check it right away. ImGui's code contains a function to do that scaling, but I couldn't find any real calls to it, so maybe it's not scaled after all.
Thanks a lot for the reply. It is very informative. I tried and it seems to work quite well. Indeed, for high DPI monitors, pixels need to be multiplied by 2.
On 2 Feb 2023, at 16:39, Vladimir Ein @.***> wrote:
I've just looked at the source code and DPG doesn't seem to report the height of the title bar. However, ImGui does have an internal-looking function for that (i.e. not API), and the title bar height is always computed as (font_size + 2 * frame_padding.y).
You can get the font size via dpg.get_text_size("") - without text, should probably work even on the 1st frame, but maybe won't - try it out. Worst case you'll need a 1-frame delay of your initialization.
As for the frame padding, I'm not sure if there's way to retrieve it, but certainly you can set it to your own value and use that value; or you can rely on ImGui's default value of 3 pixels (don't forget to multiply by 2 per the formula above).
FramePadding = ImVec2(4,3); // Padding within a framed rectangle (used by most widgets)
Note that on high DPI screens, like Retina found on MacBook, those 3 pixels might get scaled to 6 - I don't have a Mac and can't check it right away; ImGui's code contais a function to do that but I couldn't find any real calls to it.
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.
Glad that it worked!
Bad news about scaling: it's not a hard-coded "2", but a value computed somewhere inside of ImGui, and it seems DPG can't tell you that value.
In ImGui, it's stored in the variable io.DisplayFramebufferScale
, and its value is computed differently for different backends (e.g. GLFW vs. Marmalade). Here's a comment that says it's either 1 or 2, but I'm not sure how much one can rely on it:
ImVec2 FramebufferScale; // Amount of pixels for each unit of DisplaySize. Based on io.DisplayFramebufferScale. Generally (1,1) on normal display, (2,2) on OSX with Retina display.
There's a function in DPG named get_global_font_scale()
but it seems to be unrelated to this scaling.
Ideally, in your case you'd need a new function in DPG that would return the display scale (probably a part of get_app_configuration()
), or a function that would return the title bar size, or both.
I'll probably dive deeper into this scaling mess later on because I'm getting weird results on Retina, but unfortunately it's not on my near-term plans.
Version of Dear PyGui
Version: 1.2.3 Operating System: Windows 10
My Issue/Question
The draw list is placed underneath the windows titlebar. But the rectangle with pmin [0, 0] is correctly draw in top left corner just below the title bar. So there is a mismatch between draw list and rectangle coordinates. Problem disappears when there is no title bar. The coordinates in the bottom left corner is of the drawlist when mouse is on title bar.
Screenshots/Video
Standalone, minimal, complete and verifiable example