TreeNode: Fixed nodes with ImGuiTreeNodeFlags_Leaf flag always returning true which was meaningless. Tweak demo.

This commit is contained in:
omar 2018-05-14 23:36:37 +02:00
parent 99ff6fc7e4
commit 640c056602
3 changed files with 6 additions and 9 deletions

View File

@ -44,6 +44,7 @@ Breaking Changes:
Other Changes: Other Changes:
- Nav: To keep the navigated item in view we also attempt to scroll the parent window as well as the current window. (#787) - Nav: To keep the navigated item in view we also attempt to scroll the parent window as well as the current window. (#787)
- TreeNode: Fixed nodes with ImGuiTreeNodeFlags_Leaf flag always returning true which was meaningless.
----------------------------------------------------------------------- -----------------------------------------------------------------------

View File

@ -8109,7 +8109,7 @@ void ImGui::LogButtons()
bool ImGui::TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags) bool ImGui::TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags)
{ {
if (flags & ImGuiTreeNodeFlags_Leaf) if (flags & ImGuiTreeNodeFlags_Leaf)
return true; return false;
// We only write to the tree storage if the user clicks (or explicitly use SetNextTreeNode*** functions) // We only write to the tree storage if the user clicks (or explicitly use SetNextTreeNode*** functions)
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;

View File

@ -457,9 +457,9 @@ void ImGui::ShowDemoWindow(bool* p_open)
else else
{ {
// Leaf: The only reason we have a TreeNode at all is to allow selection of the leaf. Otherwise we can use BulletText() or TreeAdvanceToLabelPos()+Text(). // Leaf: The only reason we have a TreeNode at all is to allow selection of the leaf. Otherwise we can use BulletText() or TreeAdvanceToLabelPos()+Text().
node_flags |= ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; // ImGuiTreeNodeFlags_Bullet node_flags |= ImGuiTreeNodeFlags_Leaf; // | ImGuiTreeNodeFlags_Bullet;
ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, "Selectable Leaf %d", i); ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, "Selectable Leaf %d", i);
if (ImGui::IsItemClicked()) if (ImGui::IsItemClicked())
node_clicked = i; node_clicked = i;
} }
} }
@ -3188,13 +3188,9 @@ static void ShowExampleAppPropertyEditor(bool* p_open)
} }
else else
{ {
// Here we use a TreeNode to highlight on hover (we could use e.g. Selectable as well)
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();
// Here we use a Selectable (instead of Text) to highlight on hover ImGui::TreeNodeEx("Field", ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_Bullet, "Field_%d", i);
//ImGui::Text("Field_%d", i);
char label[32];
sprintf(label, "Field_%d", i);
ImGui::Bullet();
ImGui::Selectable(label);
ImGui::NextColumn(); ImGui::NextColumn();
ImGui::PushItemWidth(-1); ImGui::PushItemWidth(-1);
if (i >= 5) if (i >= 5)