Comments (12)
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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)
- Detecting a mouse click HOT 7
- How to get resizable child in window? HOT 8
- CMake Support HOT 1
- I want know where is ImGuiLayout HOT 3
- Question: How to load state of docked windows HOT 11
- Locked on 62 / 63 fps in dx11 without Vsync HOT 1
- Change cursor when hand whenTextLink is hovered - Common Style HOT 1
- Touchpad tap to click not captured when io.ConfigInputTrickleEventQueue is false HOT 5
- Position inside child window when border width changes HOT 7
- Left upper corner coordinates and child window dimensions for different border thicknesses HOT 3
- InputText display latency when trickling events HOT 4
- ImGui::Image tint_col doesn't allow amplifying texture color intensity HOT 1
- ImGuiListClipper for horizontal lists HOT 2
- 10 years of Dear ImGui (long post) HOT 33
- How can I render a large number of waveforms drawn using ImGui's drawList only once and then use it as a cached image for display to reduce drawing resource usage? Should I use a texture with DirectX 11 and Win32, or save it as an image? HOT 2
- Cannot draw inside a very small child window HOT 1
- Can't get ImGui::Shortcut to work HOT 18
- doc: mistake in comment HOT 1
- Support char 'x' for ImGuiInputTextFlags_CharsHexadecimal
- SetCorsorPos - does not work correctly! HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imgui.