mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-23 04:17:00 +00:00
TreeNode(): arbitrary interaction padding after text label not part of layout (#282)
This commit is contained in:
parent
62a3142036
commit
c381d58fb1
12
imgui.cpp
12
imgui.cpp
@ -5364,8 +5364,8 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display
|
|||||||
bb.Max.y += style.FramePadding.y * 2;
|
bb.Max.y += style.FramePadding.y * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: we don't provide our width so that it doesn't get feed back into AutoFit. Should manage that better so we can still hover without extending ContentsSize
|
const float collapser_width = g.FontSize + style.FramePadding.x*2;
|
||||||
const ImRect text_bb(bb.Min, bb.Min + ImVec2(g.FontSize + style.FramePadding.x*2*2,0) + label_size);
|
const ImRect text_bb(bb.Min, bb.Min + ImVec2(collapser_width + style.FramePadding.x*2*0 + (label_size.x > 0.0f ? label_size.x : 0.0f), label_size.y));
|
||||||
ItemSize(ImVec2(text_bb.GetSize().x, bb.GetSize().y), display_frame ? style.FramePadding.y : 0.0f);
|
ItemSize(ImVec2(text_bb.GetSize().x, bb.GetSize().y), display_frame ? style.FramePadding.y : 0.0f);
|
||||||
|
|
||||||
// When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behavior).
|
// When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behavior).
|
||||||
@ -5373,11 +5373,13 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display
|
|||||||
if (g.LogEnabled && !display_frame && window->DC.TreeDepth < g.LogAutoExpandMaxDepth)
|
if (g.LogEnabled && !display_frame && window->DC.TreeDepth < g.LogAutoExpandMaxDepth)
|
||||||
opened = true;
|
opened = true;
|
||||||
|
|
||||||
|
const ImRect interact_bb = display_frame ? bb : ImRect(text_bb.Min, text_bb.Max + ImVec2(style.FramePadding.x*2,0.0f)); // FIXME
|
||||||
if (!ItemAdd(bb, &id))
|
if (!ItemAdd(bb, &id))
|
||||||
|
//if (!ItemAdd(interact_bb, &id)) // Correct but would prevent user from accessing rendered bb which may be of use
|
||||||
return opened;
|
return opened;
|
||||||
|
|
||||||
bool hovered, held;
|
bool hovered, held;
|
||||||
bool pressed = ButtonBehavior(display_frame ? bb : text_bb, id, &hovered, &held, false);
|
bool pressed = ButtonBehavior(interact_bb, id, &hovered, &held, false);
|
||||||
if (pressed)
|
if (pressed)
|
||||||
{
|
{
|
||||||
opened = !opened;
|
opened = !opened;
|
||||||
@ -5397,7 +5399,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display
|
|||||||
const char log_prefix[] = "\n##";
|
const char log_prefix[] = "\n##";
|
||||||
LogRenderedText(bb.Min + style.FramePadding, log_prefix, log_prefix+3);
|
LogRenderedText(bb.Min + style.FramePadding, log_prefix, log_prefix+3);
|
||||||
}
|
}
|
||||||
RenderTextClipped(bb.Min + style.FramePadding + ImVec2(g.FontSize + style.FramePadding.x*2,0), bb.Max, label, NULL, &label_size);
|
RenderTextClipped(bb.Min + style.FramePadding + ImVec2(collapser_width,0), bb.Max, label, NULL, &label_size);
|
||||||
if (g.LogEnabled)
|
if (g.LogEnabled)
|
||||||
{
|
{
|
||||||
const char log_suffix[] = "##";
|
const char log_suffix[] = "##";
|
||||||
@ -5412,7 +5414,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display
|
|||||||
RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, g.FontSize*0.15f), opened, 0.70f, false);
|
RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, g.FontSize*0.15f), opened, 0.70f, false);
|
||||||
if (g.LogEnabled)
|
if (g.LogEnabled)
|
||||||
LogRenderedText(bb.Min, ">");
|
LogRenderedText(bb.Min, ">");
|
||||||
RenderText(bb.Min + ImVec2(g.FontSize + style.FramePadding.x*2,0), label);
|
RenderText(bb.Min + ImVec2(collapser_width,0), label);
|
||||||
}
|
}
|
||||||
|
|
||||||
return opened;
|
return opened;
|
||||||
|
Loading…
Reference in New Issue
Block a user