hoffstadt / hoffstadt/DearPyGui
Window position is invalidated when setting a label to it
- Dominant language
- C++
- Stars
- 15.6k
- Forks
- 783
- PR merge metrics
- No merged PRs in 30d
Description
## 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:
1. Create a modal with `dpg.window` and `modal=True` and set to it a label
2. Add additional code to show the modal when clicking a button (for e.g)
3. The modal isn't centered
## Expected behavior
The modal should be centered
## Screenshots/Video
Without the workaround:

With the workaround:

## Standalone, minimal, complete and verifiable example
```python
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!)
Contributor guide
Assessment
This issue has not been assessed yet.