Giter Club home page Giter Club logo

Comments (12)

mistahmikey avatar mistahmikey commented on September 7, 2024 1

Because it hard to find authoritative information about this stuff for all use cases, I just guessed that is how it was supposed to be used. So should that code look more like the following?

GUI:Columns(5, "##selected_table_column_data_columns", true)
for row = 1, 5 do
    for column = 1,5 do
        GUI:SetColumnWidth(-1,10)
        if column == 1 then
            GUI:SetNextItemAllowOverlap()
            GUI:Selectable("##selectable_data_cell_"..row.."_"..column,false,GUI.SelectableFlags_SpanAllColumns|GUI.SelectableFlags_AllowOverlap) GUI:SameLine()
        end
        GUI:Text("Data Cell")
        local isItemHovered = GUI:IsItemHovered()
        if isItemHovered and GUI:IsMouseClicked(0) then
            print("Mouse Clicked on "..row..","..column)
        end
        GUI:NextColumn()
    end
end
GUI:Columns(1)

from imgui.

ocornut avatar ocornut commented on September 7, 2024

In the previous version, that last mouse action function worked as expected - when the cursor was positioned over the overlapped item, it would return true as expected. Now it always returns false.

Code as posted calls IsMouseClicked(), which doesn't test cursor overlap.
There's probably a mistake in your statement or repro, because IsMouseClicked(), IsMouseDown() are unrelated to item logic.

from imgui.

mistahmikey avatar mistahmikey commented on September 7, 2024

I've dug a bit more into this, and the problem is occurring with single clicks on the last column in the table (created using the Columns widget.) For some reason, the Selectable doesn't appear to be passing through the click on that column to the overlapped widget. If I drop back to the previous version (which uses the obsolesced SetItemAllowOverlap), it works fine - and the ONLY code difference between that version and the new version that in the new version, SetNextItemAllowOverlap is called before the Selectable call, while in the old version, SetItemAllowOverlap is called after the selectable call. Detecting single click works on all other table columns but the last - and the code that handles drawing each column and detecting the click is the same. So not sure what to make of it.

from imgui.

ocornut avatar ocornut commented on September 7, 2024

I think you need to provide more pseudo code or repro and a more descriptive context (eg screenshots), words are too ambiguous and your first blurb of code is clearly omitting the important stuff.

from imgui.

mistahmikey avatar mistahmikey commented on September 7, 2024

Here is about as simplified a "complete" snippet as I can provide. It is much simpler, but it accurately represents the structure of how the code is called:

GUI:Columns(5, "##selected_table_column_data_columns", true)
for row = 1, 5 do
    for column = 1,5 do
        GUI:SetColumnWidth(-1,10)
        GUI:SetNextItemAllowOverlap()
        GUI:Selectable("##selectable_data_cell_"..row.."_"..column,false,GUI.SelectableFlags_SpanAllColumns|GUI.SelectableFlags_AllowOverlap) GUI:SameLine()
        GUI:Text("Data Cell")
        local isItemHovered = GUI:IsItemHovered()
        if isItemHovered and GUI:IsMouseClicked(0) then
            print("Mouse Clicked on "..row..","..column)
        end
        GUI:NextColumn()
    end
end
GUI:Columns(1)

What I am seeing is the equivalent of never seeing a "Mouse Clicked" message when I click on any cell in the last column of the table. All other cells in the table respond as expected.

from imgui.

ocornut avatar ocornut commented on September 7, 2024

Why are you submitting an all-row-spanning Selectable() in every column? You should only submit one.

I’ll try to recreate that repro soon.

from imgui.

mistahmikey avatar mistahmikey commented on September 7, 2024

FYI, I changed my code to essentially do the above, and now, none of the cells respond to the single mouse click. They do respond to double right clicks, however (as did the previous version.)

from imgui.

mistahmikey avatar mistahmikey commented on September 7, 2024

Another update - we updated to the latest (1.90.8), and the single click detection problem is still present for all columns for snippet version 2 above. Changing back to snippet version 1 (calling Selectable for each cell), and the single click detection works for all columns but the final one again. I also updated the original post to reflect the latest version.

from imgui.

mistahmikey avatar mistahmikey commented on September 7, 2024

Another observation - it looks like when using a selectable, you don't need both GUI:SetNextItemAllowOverlap() and SelectableFlags_AllowOverlap - using one or the other alone results in the same behavior.

from imgui.

mistahmikey avatar mistahmikey commented on September 7, 2024

I also tried changing GUI:IsItemHovered() to GUI:IsItemHovered(GUI.HoveredFlags_AllowWhenOverlappedByItem), but it didn't change the behavior for either snippet version.

from imgui.

ocornut avatar ocornut commented on September 7, 2024

I ported your code to C++ and understood the problem: a ImGui::Text() item doesn't react to mouse events and thus doesn't claim overlap from the Selectable().
So essentially SetNextItemAllowOverlap + Selectable + followed by just a Text won't work.
But if you replace Text by an active element e.g. Button() it will work.

Your code:

ImGui::Begin("#7715");
ImGui::Columns(5, "##selected_table_column_data_columns", true);
for (int row = 0; row < 5; row++)
    for (int col = 0; col < 5; col++)
    {
        //ImGui::SetColumnWidth(-1, 10);
        ImGui::PushID(row * 5 + col);
        if (col == 0)
        {
            char buf[32];
            ImGui::SetNextItemAllowOverlap();
            ImGui::Selectable("##selectable_data_cell", false, ImGuiSelectableFlags_SpanAllColumns);// | GUI.SelectableFlags_AllowOverlap)
            ImGui::SameLine(0, 0);
        }
        ImGui::Button("Data Cell");
        bool isItemHovered = ImGui::IsItemHovered();
        if (isItemHovered && ImGui::IsMouseClicked(0))
            printf("Mouse Clicked on %d %d\n", row, col);
        ImGui::PopID();
        ImGui::NextColumn();
    }
ImGui::Columns(1);
ImGui::End();

However it seems like you may want want to do hit-testing on Text element, but rather on columns here?

Likely you should be querying hovered column instead:

ImGui::Begin("#7715");
if (ImGui::BeginTable("##selected_table_column_data_columns", 5, ImGuiTableFlags_BordersV))
{
    for (int row = 0; row < 5; row++)
    {
        ImGui::TableNextRow();
        bool row_clicked = false;
        for (int col = 0; col < 5; col++)
        {
            ImGui::TableNextColumn();
            ImGui::PushID(row * 5 + col);
            if (col == 0)
            {
                ImGui::SetNextItemAllowOverlap();
                row_clicked = ImGui::Selectable("##selectable_data_cell", false, ImGuiSelectableFlags_SpanAllColumns);
                ImGui::SameLine(0, 0);
            }
            ImGui::Text("Data Cell");

            if (row_clicked && (ImGui::TableGetColumnFlags() & ImGuiTableColumnFlags_IsHovered))
                printf("Mouse Clicked on %d %d\n", row, col);
            ImGui::PopID();
        }
    }
    ImGui::EndTable();
}
ImGui::End();

from imgui.

ocornut avatar ocornut commented on September 7, 2024

Tangential: I decided to move TableGetHoveredColumn() to public API, which is a way to obtain the hovered column in a table without polling individual columns.

So you could change

if (row_clicked && (ImGui::TableGetColumnFlags() & ImGuiTableColumnFlags_IsHovered))
    printf("Mouse Clicked on %d %d\n", row, col);

to

if (row_clicked && (ImGui::TableGetHoveredColumn() == col)
    printf("Mouse Clicked on %d %d\n", row, col);

Or do:

if (ImGui::Selectable("##selectable_data_cell", false, ImGuiSelectableFlags_SpanAllColumns))
     printf("Mouse Clicked on %d %d\n", row, ImGui::TableGetHoveredColumn());

from imgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.