mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 20:07:01 +00:00
Fixed ImGuiTreeNodeFlags_AllowOverlapMode to behave better on touch-style inputs (#600)
This commit is contained in:
parent
df749e3f13
commit
ab6bc05fc3
15
imgui.cpp
15
imgui.cpp
@ -5262,14 +5262,6 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
|
|||||||
|
|
||||||
bool pressed = false;
|
bool pressed = false;
|
||||||
bool hovered = IsHovered(bb, id, (flags & ImGuiButtonFlags_FlattenChilds) != 0);
|
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)
|
if (hovered)
|
||||||
{
|
{
|
||||||
SetHoveredID(id);
|
SetHoveredID(id);
|
||||||
@ -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_hovered) *out_hovered = hovered;
|
||||||
if (out_held) *out_held = held;
|
if (out_held) *out_held = held;
|
||||||
|
|
||||||
@ -5688,6 +5684,8 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
|
|||||||
opened = !opened;
|
opened = !opened;
|
||||||
window->DC.StateStorage->SetInt(id, opened);
|
window->DC.StateStorage->SetInt(id, opened);
|
||||||
}
|
}
|
||||||
|
if (flags & ImGuiTreeNodeFlags_AllowOverlapMode)
|
||||||
|
SetItemAllowOverlap();
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
|
const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
|
||||||
@ -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.
|
// 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;
|
ImGuiState& g = *GImGui;
|
||||||
SetItemAllowOverlap();
|
|
||||||
float button_sz = g.FontSize * 0.5f;
|
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))
|
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;
|
*p_open = false;
|
||||||
|
14
imgui.h
14
imgui.h
@ -518,13 +518,13 @@ enum ImGuiInputTextFlags_
|
|||||||
// Flags for ImGui::TreeNode*(), ImGui::CollapsingHeader*()
|
// Flags for ImGui::TreeNode*(), ImGui::CollapsingHeader*()
|
||||||
enum ImGuiTreeNodeFlags_
|
enum ImGuiTreeNodeFlags_
|
||||||
{
|
{
|
||||||
ImGuiTreeNodeFlags_Selected = 1 << 0,
|
ImGuiTreeNodeFlags_Selected = 1 << 0, // FIXME: TODO
|
||||||
ImGuiTreeNodeFlags_Framed = 1 << 1,
|
ImGuiTreeNodeFlags_Framed = 1 << 1, // Full colored frame (e.g. for CollapsingHeader)
|
||||||
ImGuiTreeNodeFlags_AllowOverlapMode = 1 << 2,
|
ImGuiTreeNodeFlags_AllowOverlapMode = 1 << 2, // Hit testing to allow subsequent widgets to overlap this one
|
||||||
ImGuiTreeNodeFlags_NoTreePushOnOpen = 1 << 3,
|
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,
|
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,
|
ImGuiTreeNodeFlags_DefaultOpen = 1 << 5, // Default node to be opened
|
||||||
ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoAutoOpenOnLog,
|
ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoAutoOpenOnLog
|
||||||
};
|
};
|
||||||
|
|
||||||
// Flags for ImGui::Selectable()
|
// Flags for ImGui::Selectable()
|
||||||
|
Loading…
Reference in New Issue
Block a user