Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default horizontal window padding exists in imgui #1814

Closed
my1e5 opened this issue Jun 23, 2022 · 5 comments
Closed

Default horizontal window padding exists in imgui #1814

my1e5 opened this issue Jun 23, 2022 · 5 comments
Labels
state: pending not addressed yet type: bug bug

Comments

@my1e5
Copy link
Contributor

my1e5 commented Jun 23, 2022

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

Screen.Recording.2022-06-23.at.20.56.16.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()
@my1e5 my1e5 added state: pending not addressed yet type: bug bug labels Jun 23, 2022
@hugle
Copy link

hugle commented Aug 9, 2022

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()

@DataExplorerUser
Copy link
Contributor

WORKAROUND_AVAILABLE

@my1e5
Copy link
Contributor Author

my1e5 commented Jan 17, 2023

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.

@bandit-masked
Copy link
Collaborator

I'll keep the issue open.

@my1e5
Copy link
Contributor Author

my1e5 commented Feb 13, 2023

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 ocornut/imgui#3312 (comment)

The 'fix' is to change the code in imgui.cpp as the above post explains.

@my1e5 my1e5 changed the title WindowPadding not working with child windows Default horizontal window padding exists in imgui Feb 13, 2023
@my1e5 my1e5 closed this as completed Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: pending not addressed yet type: bug bug
Projects
None yet
Development

No branches or pull requests

4 participants