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
12.89k stars 671 forks source link

Set the calculated width / height when using autosize_x/y. #1815

Open Riddle1001 opened 2 years ago

Riddle1001 commented 2 years ago

Is your feature request related to a problem? Please describe. I would like

with dpg.child_window(autosize_x=True, height=150, tag="cw") as cw:
        print(dpg.get_item_configuration("cw")["width"])

not to return 0. Describe the solution you'd like When autosize_x is True set the item configuration width and height properties to the calculated width and height properties instead of 0

Describe alternatives you've considered

def window_resize( sender, data, user ):
    width = dpg.get_item_configuration("window")["width"]
    dpg.configure_item("cw", width=width - 20)

with dpg.window(label="Main", width=800, height=600, tag="window") as win:
    with dpg.child_window(width=0, height=150, tag="cw") as cw:
        with dpg.item_handler_registry() as handle:
            dpg.add_item_resize_handler(callback=window_resize)
            dpg.bind_item_handler_registry(win, handle)
bandit-masked commented 1 year ago

In these cases, it usually takes a frame for all values to be updated. If you would check in the next frame, it might show the appropriate value.

v-ein commented 9 months ago

Retrieving item size in ImGui is only possible after the item renders at least once. For windows, however, it usually takes two frames to auto-size to content size:

That said, your request, as it is, is impossible to implement. I'd suggest that this ticket be closed.

Whenever you need to retrieve the size of an auto-sized widget, like a window or a table, wait a frame or two and then use dpg.get_item_rect_min(widget). If you're creating the widget on-the-fly (not at program initialization), you can use dpg.split_frame() for that. Alternatively, you can use set_frame_callback or use the item_visible handler; this works for widgets created at init, too.