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

Window position is invalidated when setting a label to it #2323

Open
ludg1e opened this issue Apr 20, 2024 · 1 comment
Open

Window position is invalidated when setting a label to it #2323

ludg1e opened this issue Apr 20, 2024 · 1 comment
Labels
state: pending not addressed yet type: bug bug

Comments

@ludg1e
Copy link

ludg1e commented Apr 20, 2024

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:
image

With the workaround:
image

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

@ludg1e ludg1e added state: pending not addressed yet type: bug bug labels Apr 20, 2024
@v-ein
Copy link
Contributor

v-ein commented Apr 22, 2024

For future reference:

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

2 participants