hoffstadt / DearPyGui

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

when window collapsed dpg.get_item_pos (dpg.get_item_...) doesnt work #1874

Open DevilDeal opened 2 years ago

DevilDeal commented 2 years ago

when i collapse a window the function get_item_pos or is_item_hovered doesnt update or work like it should in my sight.

seems like a bug to me. need a workaround for my overlay im doing maybe someone knows where i can get the window_pos when the window is collapsed/not visible.

below is an example code, it shows the item state in the console. when u collapse the window (collapsed=True) it doesnt show the updated cordinate for the window when u move it. not collapsed works fine.

sorry for my bad english and thanks for future help

import dearpygui.dearpygui as dpg
import threading
import time

def main():

    dpg.create_context()

    with dpg.window(label="Example Window", width=500, height=150, tag="example window", collapsed=False):
        dpg.add_text("Hello, world")

    dpg.create_viewport(title='Custom Title', width=600, height=200)  
    dpg.setup_dearpygui()
    dpg.show_viewport()
    dpg.start_dearpygui()
    dpg.destroy_context()

def example():

    time.sleep(1)
    while True:
        x,y=dpg.get_item_pos("example window")
        width=dpg.get_item_width("example window")
        height=dpg.get_item_height("example window")
        print(x,y,"|",width,"|",height)
        print(dpg.is_item_hovered("example window"))

if __name__=="__main__":
    a= threading.Thread(target=main)
    a.start()
    b= threading.Thread(target=example)
    b.start()
DevilDeal commented 2 years ago

There is also a second bug when item is not hovered or sometimes just random with no sense behind it. When the window is visible(not collapsed) the returned value of dpg.get_item_state("example window")["visible"] is sometimes True and sometimes False so my programm returns wrong values to use for me. When item is not visible(collapsed) the returned value is always False, as it should be.

When item is visible(not collapsed) returned value should always be True i guess???

image

DevilDeal commented 2 years ago

i could do a workaround to look over the last couple miliseconds and if there is one True value i could always return True but that seems very weird to me because the False value works fine...

DevilDeal commented 2 years ago

example code for workaround but very sloppy and weird in my opinion. not optimised and very inefficient i think but for now i will use this....

(increase range for accuracy, 5 should be fine)


while True:
    b=[]
    for i in range(3):

        visible=dpg.get_item_state("example window")["visible"]
        b.append(visible)

    if any(b):
       print("True")
    if not any(b):
        print("False")
v-ein commented 10 months ago

FYI: This part:

There is also a second bug when item is not hovered or sometimes just random with no sense behind it.

is described in #2077 and will eventually get fixed (I have a local fix but need some work to make it into a PR).