Skip to content

Commit

Permalink
Fixed ImGuiTreeNodeFlags_AllowOverlapMode to behave better on touch-s…
Browse files Browse the repository at this point in the history
…tyle inputs (#600)
  • Loading branch information
ocornut committed May 1, 2016
1 parent df749e3 commit ab6bc05
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
15 changes: 6 additions & 9 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5262,14 +5262,6 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool

bool pressed = false;
bool hovered = IsHovered(bb, id, (flags & ImGuiButtonFlags_FlattenChilds) != 0);

// AllowOverlap mode (rarely used) requires previous frame HoveredId to be null or to match. This allows using patterns where a later submitted widget overlaps a previous one.
if (hovered && (flags & ImGuiButtonFlags_AllowOverlapMode) && (g.HoveredIdPreviousFrame != id && g.HoveredIdPreviousFrame != 0))
{
SetHoveredID(id);
hovered = false;
}

if (hovered)
{
SetHoveredID(id);
Expand Down Expand Up @@ -5319,6 +5311,10 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
}
}

// AllowOverlap mode (rarely used) requires previous frame HoveredId to be null or to match. This allows using patterns where a later submitted widget overlaps a previous one.
if (hovered && (flags & ImGuiButtonFlags_AllowOverlapMode) && (g.HoveredIdPreviousFrame != id && g.HoveredIdPreviousFrame != 0))
hovered = pressed = held = false;

if (out_hovered) *out_hovered = hovered;
if (out_held) *out_held = held;

Expand Down Expand Up @@ -5688,6 +5684,8 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
opened = !opened;
window->DC.StateStorage->SetInt(id, opened);
}
if (flags & ImGuiTreeNodeFlags_AllowOverlapMode)
SetItemAllowOverlap();

// Render
const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
Expand Down Expand Up @@ -5752,7 +5750,6 @@ bool ImGui::CollapsingHeader(const char* label, bool* p_open, ImGuiTreeNodeFlags
{
// Create a small overlapping close button // FIXME: We can evolve this into user accessible helpers to add extra buttons on title bars, headers, etc.
ImGuiState& g = *GImGui;
SetItemAllowOverlap();
float button_sz = g.FontSize * 0.5f;
if (CloseButton(window->GetID((void*)(intptr_t)(id+1)), ImVec2(window->DC.LastItemRect.Max.x - g.Style.FramePadding.x - button_sz, window->DC.LastItemRect.Min.y + g.Style.FramePadding.y + button_sz), button_sz))
*p_open = false;
Expand Down
14 changes: 7 additions & 7 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,13 @@ enum ImGuiInputTextFlags_
// Flags for ImGui::TreeNode*(), ImGui::CollapsingHeader*()
enum ImGuiTreeNodeFlags_
{
ImGuiTreeNodeFlags_Selected = 1 << 0,
ImGuiTreeNodeFlags_Framed = 1 << 1,
ImGuiTreeNodeFlags_AllowOverlapMode = 1 << 2,
ImGuiTreeNodeFlags_NoTreePushOnOpen = 1 << 3,
ImGuiTreeNodeFlags_NoAutoOpenOnLog = 1 << 4,
ImGuiTreeNodeFlags_DefaultOpen = 1 << 5,
ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoAutoOpenOnLog,
ImGuiTreeNodeFlags_Selected = 1 << 0, // FIXME: TODO
ImGuiTreeNodeFlags_Framed = 1 << 1, // Full colored frame (e.g. for CollapsingHeader)
ImGuiTreeNodeFlags_AllowOverlapMode = 1 << 2, // Hit testing to allow subsequent widgets to overlap this one
ImGuiTreeNodeFlags_NoTreePushOnOpen = 1 << 3, // Don't do a TreePush() when opened (e.g. for CollapsingHeader) = no extra indent nor pushing on ID stack
ImGuiTreeNodeFlags_NoAutoOpenOnLog = 1 << 4, // Don't automatically and temporarily open node when Logging is active (by default logging will automatically open tree nodes).
ImGuiTreeNodeFlags_DefaultOpen = 1 << 5, // Default node to be opened
ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoAutoOpenOnLog
};

// Flags for ImGui::Selectable()
Expand Down

0 comments on commit ab6bc05

Please sign in to comment.