DearPyGui
DearPyGui copied to clipboard
`WindowPadding` not working with child windows
Version of Dear PyGui
Version: 1.6.2 Operating System: macOS
My Issue/Question
Changing WindowPadding in the y direction doesn't seem to filter down to child windows.
To Reproduce
See the MWE below
Expected behavior
I expected changing the WindowPadding to affect both x and y directions, as it does with the main window.
Screenshots/Video
https://user-images.githubusercontent.com/10064103/175389789-02912d4b-493d-4678-9086-793f199057da.mov
Standalone, minimal, complete and verifiable example
import dearpygui.dearpygui as dpg
dpg.create_context()
SIZE = 200
texture_data = []
for i in range(0, SIZE**2):
texture_data.append(0)
texture_data.append(0)
texture_data.append(0)
texture_data.append(255 / 255)
with dpg.texture_registry():
dpg.add_static_texture(width=SIZE, height=SIZE, default_value=texture_data, tag="texture_tag")
with dpg.window():
with dpg.child_window(width=SIZE, height=SIZE, no_scrollbar=True, border=True):
dpg.add_image("texture_tag", pos=(0,0))
dpg.show_style_editor()
dpg.create_viewport(width=SIZE*2, height=SIZE*2)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
Yes, you can have the behaviour without fixing the pos
to (0, 0)
. If you really want to have pos=(0, 0)
, you can set pos
after setting dpg.theme_component
:
import dearpygui.dearpygui as dpg
dpg.create_context()
SIZE = 200
texture_data = []
for i in range(0, SIZE**2):
texture_data.append(0)
texture_data.append(0)
texture_data.append(0)
texture_data.append(255 / 255)
with dpg.texture_registry():
dpg.add_static_texture(width=SIZE, height=SIZE, default_value=texture_data, tag="texture_tag")
with dpg.window():
with dpg.child_window(width=SIZE+16, height=SIZE+16, no_scrollbar=True, border=True):
dpg.add_image("texture_tag") # Remove pos constrain
dpg.show_style_editor()
dpg.create_viewport(width=SIZE*2, height=SIZE*2)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
WORKAROUND_AVAILABLE
Looking back at this, I think the bug is actually that when you set pos=(0,0)
the x
coordinate is not applied properly. The y
coordinate is actually faithfully set to 0
, which is why changing the window padding in the y direction does not change the position of the image in the y direction. However, the image is not properly set to x=0
therefore it moves about when you change the window padding.
Regarding the workaround, it isn't perfect - of course you can remove window padding from that child window and the image can be positioned at (0,0). But there isn't a way to keep window padding (which you might want for other UI elements) but force the image to be located at (0,0). FYI, the proposal that you can set pos=(0,0)
after setting the theme component doesn't work. For example this doesn't work:
def set_image_pos():
dpg.configure_item(image, pos=(0,0))
dpg.set_frame_callback(1,set_image_pos)
The x
coordinate of the image position can't be set to 0
- without removing window padding. But the y
coordinate works correctly.
I'll keep the issue open.
I believe I've figured this out. It's to do with Imgui and the "default window clipping rectangle":
The default window clipping rectangle adds that spacing of WindowPadding.x*0.5f horizontally, and no clipping on the vertical axis. I made this choice in 1.0 because we tend to have a bias toward scrolling vertically, having no clipping-padding on the vertical axis tends to make it more noticeable that there's something to scroll to.
See https://github.com/ocornut/imgui/issues/3312#issuecomment-648052521
The 'fix' is to change the code in imgui.cpp
as the above post explains.