DearPyGui
DearPyGui copied to clipboard
Set the calculated width / height when using autosize_x/y.
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)
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.
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:
- at first frame, the widgets within the window extend its "contents region" to accomodate their size;
- at second frame, the window itself uses the updated contents region (from the previous frame) to set its own 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.