DearPyGui icon indicating copy to clipboard operation
DearPyGui copied to clipboard

getWidgetWidth() / getWidgetHeight

Open ivallc opened this issue 3 years ago • 1 comments

I would be very helpful if you could get the px width and height for most widgets. This would be helpful in making a GUI scalable, as you could define a position based on the width of the widget you're working with. For example, say I wanted to center a text widget in a viewport you could set position to (dpg.getViewportWidth - dpg.getWidgetWidth, SomeYValue), or with more complex equations you could make adjustable widget locations that would be the same relatively regardless of window scale.

ivallc avatar Sep 17 '22 21:09 ivallc

Try use: dpg.get_item_rect_size()

Test code:

import dearpygui.dearpygui as dpg

dpg.create_context()

with dpg.window():
    dpg.add_button(label='test', callback=lambda item: print(dpg.get_item_rect_size(item)))
    dpg.add_button(label='test22222', callback=lambda item: print(dpg.get_item_rect_size(item)))

dpg.create_viewport()
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

IvanNazaruk avatar Sep 18 '22 10:09 IvanNazaruk

Solution provided, closing issue.

bandit-masked avatar Jan 04 '23 22:01 bandit-masked