hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en/latest/
MIT License
13.22k stars 688 forks source link

Resize viewport callback not called when viewport is shrunk #2217

Open Dillon-Fisher-14 opened 12 months ago

Dillon-Fisher-14 commented 12 months ago

Version of Dear PyGui

Version: 1.10.1 Operating System: Windows 10, Ubuntu

My Issue/Question

Resize viewport callback is only called when the viewport size is increased. If the viewport size is shrunk, the resize callback function is not called.

To Reproduce

Steps to reproduce the behavior:

  1. Start with DPG example code in readme, or similarly simple example.
  2. Define a function to be called on viewport resize, "resize_viewport_callback"
  3. Set viewport resize callback with "dpg.set_viewport_resize_callback(resize_viewport_callback)"
  4. Launch program.
  5. Resize the viewport window.

Expected behavior

Resize callback function is called each frame the viewport is resized, (both enlarged and shrunk).

Screenshots/Video

Animation



import dearpygui.dearpygui as dpg
import time

dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()

def resize_viewport_callback():
    dpg.set_value("ViewportWidthText", f"Viewport Width: {dpg.get_viewport_width()}")
    dpg.set_value("ViewportHeightText", f"Viewport Height: {dpg.get_viewport_height()}")
    dpg.set_value("LastViewportSizeUpdateText", f"Time: {time.time_ns()}")

dpg.set_viewport_resize_callback(resize_viewport_callback)

with dpg.window(label="Example Window", tag="Window"):
    dpg.add_text("Viewport Width: ", tag="ViewportWidthText")
    dpg.add_text("Viewport Height: ", tag="ViewportHeightText")
    dpg.add_text("Time: ", tag="LastViewportSizeUpdateText")

dpg.set_primary_window("Window", True)

dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
v-ein commented 12 months ago

Looks like a duplicate of #1896:

Both bind_item_handler_registry and set_viewport_resize_callback have this bug.