local bFoundSelect
local function recurDraw(node)
local name,addr = getName(node)
local children = node:getChildren()
if #children > 0 then
local bSelect = (self.cur_select_node == node)
if bSelect then
imgui.PushStyleColor(0,1,0,1)
end
if imgui.treeNodeEx(name,imgui.ImGuiTreeNodeFlags_OpenOnArrow) then
if bSelect then
imgui.PopStyleColor()
end
for i,child in ipairs(children)do
recurDraw(child)
end
imgui.treePop()
else
if bSelect then
imgui.PopStyleColor()
end
end
if imgui.IsItemClicked() then
if not bFoundSelect then
bFoundSelect = true
self.cur_select_node = node
end
print("IsItemClicked",name)
end
else
if self.cur_select_node == node then
imgui.PushStyleColor(0,1,0,1)
imgui.treeNodeEx(name,imgui.ImGuiTreeNodeFlags_Leaf)
imgui.treePop()
imgui.PopStyleColor()
else
imgui.treeNodeEx(name,imgui.ImGuiTreeNodeFlags_Leaf)
imgui.treePop()
end
if imgui.IsItemClicked() then
-- if imgui.button(name) then
if not bFoundSelect then
bFoundSelect = true
self.cur_select_node = node
end
end
end
end
export c++ api to lua for game use.
I'm drawing the scene Hierachy recursivly.When the treeNode is collapsed,IsItemClicked() return true.But after the treeNode expand,IsItemClicked() return false!As i know,IsItemClicked equals IsMouseClicked&&IsItemHoverd锛宨 found that IsMouseClicked returned false!
with ImGuiTreeNodeFlags_OpenOnArrow flag,when i click the triangle on the left,IsItemClicked() also return true.....Is it reasonable?

As above,when left click to select a node,it turns green,but after the collapser expand,select isn't reponsed as Node[0x0a2a80d0]
dear imgui, v1.66 WIP
IsItemClicked() return the value for the _LAST_ item submitted. There's no stack storage of that data on tree push/pop.
if (TreeNode(A))
{
TreeNode(B);
}
IsItemClicked() <- return value for B
You should call IsItemXXX right after TreeNodeXXX:
e.g.
bool open = TreeNodeXXX()
bool clicked = IsItemClicked()
if (open)
{
...
TreePop();
}
It works,thanks for your reply!
@ocornut Shouldn't that information be stacked? I think that would be more intuitive.
To stack it the way you intent we would need to compute every possible IsItemXXX state for every tree node.
I'm still a beginner - didn't realize how many there are. So doing that would mean stacking all the data on which all the IsItem...() queries are based - or precompute all the values. Probably not worth it.
Your workaround works perfectly btw, so thanks for that!
Most helpful comment
IsItemClicked()return the value for the _LAST_ item submitted. There's no stack storage of that data on tree push/pop.You should call
IsItemXXXright afterTreeNodeXXX:e.g.