Есть ли разумный способ обнаружить события мыши над родительским элементом и всеми его дочерними элементами одновременно в PyImGui?
Обычно, если я навожу курсор на окно, содержащее несколько элементов (дочерний элемент, кнопка , input_text_multiline, text, ...), мне нужно отслеживать всех либо с помощью imgui.is_item_hovered(), либо imgui.is_window_hovered(), чтобы убедиться, что событие сработало.
Вот что я в итоге сделал:
import imgui
def draw(self):
hovered = []
def check_hover():
if imgui.is_item_hovered() or imgui.is_window_hovered():
hovered.append(True)
# Start a new ImGui window for the console
with imgui.begin("Console"):
check_hover()
# Get the available size for the text editor region
available_size = imgui.get_content_region_available()
# Begin a child window for scroll synchronization between the line numbers and text
with imgui.begin_child("##scrolling_region", available_size.x, available_size.y,
border=False, flags=imgui.WINDOW_NO_BACKGROUND):
imgui.columns(2)
# Left column: line numbers
imgui.set_column_width(0, 25)
check_hover()
for i in range(len(self.file_line_numbers)):
imgui.text(str(i + 1)) # Display the line numbers
# Right column: The multiline text editor
imgui.next_column()
text_changed, text_lines = imgui.input_text_multiline(
"##editor", self.file_content, len(self.file_line_numbers),
available_size.x, available_size.y)
if text_changed: # If the text was changed, update the original list of lines
self.file_content = text_lines #.splitlines(keepends=True) # Split back into lines
check_hover()
if imgui.button("Load"):
self.load_file()
imgui.same_line()
if imgui.button("Save"):
self.save_file(self.file_content)
check_hover()
if any(hovered): # if at least one of the items is hovered
self.is_hovered = True
print("console hovered")
else:
self.is_hovered = False
Подробнее здесь: https://stackoverflow.com/questions/790 ... in-pyimgui