Window position is invalidated when setting a label to it
ludg1e opened this issue · 1 comments
ludg1e commented
Version of Dear PyGui
Version: 1.9.1
Operating System: Windows 10
My Issue/Question
When a label is set on a window, DPG invalidates the window position
While this may be or not of importance for the main window, modals created as windows (with dpg.window
and modal=True
) to be shown after aren't centered since the window position is broken due to setting a label to them
A workaround is to tell DPG that the position is valid with: dpg.reset_pos(tag)
To Reproduce
Steps to reproduce the behavior:
- Create a modal with
dpg.window
andmodal=True
and set to it a label - Add additional code to show the modal when clicking a button (for e.g)
- The modal isn't centered
Expected behavior
The modal should be centered
Screenshots/Video
Standalone, minimal, complete and verifiable example
import dearpygui.dearpygui as dpg
dpg.create_context()
dpg.create_viewport(
title="hello bro",
width=700,
height=500,
)
with dpg.window(tag="main_window"):
dpg.add_text("Hello world")
dpg.add_input_text(label="string")
dpg.add_slider_float(label="float")
dpg.add_separator()
with dpg.group(
tag="categories",
width=700,
parent="main_window",
horizontal=False,
):
with dpg.collapsing_header(
label="Input",
tag="categories_input",
parent="categories",
default_open=False,
):
dpg.add_button(
label="Mouse",
tag="categories_input_mouse",
width=700,
parent="categories_input",
callback=lambda: dpg.configure_item("mouse_modal", show=True),
)
dpg.set_primary_window("main_window", True)
with dpg.window(
label="Mouse settings",
tag="mouse_modal",
width=500,
height=300,
show=False,
no_resize=True,
no_title_bar=False,
no_collapse=True,
no_close=True,
modal=True,
no_open_over_existing_popup=True,
):
dpg.add_text(
"All those beautiful files will be deleted.\nThis operation cannot be undone!"
)
dpg.add_separator()
dpg.add_checkbox(label="Don't ask me next time")
with dpg.group(horizontal=True):
dpg.add_button(
label="OK",
width=75,
callback=lambda: dpg.configure_item("mouse_modal", show=False),
)
dpg.add_button(
label="Cancel",
width=75,
callback=lambda: dpg.configure_item("mouse_modal", show=False),
)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
Also Tetane's workaround is applied from issue #1978
cc: @v-ein (thanks for the help on Discord!)
v-ein commented
For future reference:
- It's a side effect of the commit b081e6f, which is a fix for #346.
- At some point, this "dirtyPos = true" line had got a comment saying "this is necessary because imgui considers it a new window" - see it after commit ee26195. For some reason, the comment got lost in future commits.