DearPyGui icon indicating copy to clipboard operation
DearPyGui copied to clipboard

tooltip of containers stack together

Open spectereye opened this issue 2 years ago • 3 comments

Hi, tooltip of containers (collapsing_header/tree_node/group/...) stacked/inherited together, which looks abnormal.

import dearpygui.dearpygui as dpg

dpg.create_context()
primary_w = 'w0'


with dpg.window(tag=primary_w):
    with dpg.collapsing_header(label='head1', tag='header1'):
        with dpg.tooltip('header1'):
            dpg.add_text('header1')

        with dpg.tree_node(label='node1', tag='node1'):
            with dpg.tooltip('node1'):
                dpg.add_text('node1')
            dpg.add_button(label='btn1', tag='btn1')
            with dpg.tooltip('btn1'):
                dpg.add_text('btn1')

            with dpg.tree_node(label='node2', tag='node2'):
                with dpg.tooltip('node2', tag='t_node2'):
                    dpg.add_text('node2')
                dpg.add_button(label='btn2', tag='btn2')
                with dpg.tooltip('btn2'):
                    dpg.add_text('btn2')


dpg.create_viewport(title='test tooltip', width=600, height=300)
dpg.set_primary_window(primary_w, True)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

spectereye avatar Oct 12 '23 05:10 spectereye

For future reference:

This happens because the tooltip calls ImGui::IsItemHovered() to detect whether its parent is hovered. Since the tooltip is rendered right after its parent, it works fine on most widgets. For containers, however, the "hovered" state is typically accumulated across contents, because the contents is packed into a group. This causes ImGui::IsItemHovered() to return true not only when the header or tree node is hovered, but also when one of its children is hovered, too.

When multiple tooltips sense the hovered state, they are all rendered, and without ImGuiTooltipFlags_OverridePreviousTooltip, their contents is merged into one window. Even if we set that flag, it won't help much because the tooltip for the outermost container will be rendered last, and will override tooltips for nested widgets.

One way to fix this would be to store a weak_ptr to the parent item in the tooltip, and check its state.hovered instead of relying on ImGui::IsItemHovered(). Maybe even use state.parent (though this would look like a hacky workaround). Not sure what side effects this might have.

v-ein avatar Oct 12 '23 07:10 v-ein

@v-ein thanks for your quick response! seems there is no easy way to fix this ...

spectereye avatar Oct 12 '23 08:10 spectereye

Well, the fix with weak_ptr would be trivial, but it's quite a lot to test. Might break in some scenarios, e.g. within tables. And it would need another build of DPG, that's for sure.

v-ein avatar Oct 13 '23 17:10 v-ein