mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-28 17:40:56 +01:00
Separator(): Tweak Logging so that the separator text is aligned according to tree padding.
This commit is contained in:
parent
0106dcbd02
commit
9142002121
35
imgui.cpp
35
imgui.cpp
@ -590,8 +590,6 @@
|
||||
// Forward Declarations
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
static void LogRenderedText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL);
|
||||
|
||||
static float GetDraggedColumnOffset(int column_index);
|
||||
|
||||
static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true);
|
||||
@ -2870,7 +2868,7 @@ void ImGui::LogText(const char* fmt, ...)
|
||||
|
||||
// Internal version that takes a position to decide on newline placement and pad items according to their depth.
|
||||
// We split text into individual lines to add current tree level padding
|
||||
static void LogRenderedText(const ImVec2& ref_pos, const char* text, const char* text_end)
|
||||
static void LogRenderedText(const ImVec2* ref_pos, const char* text, const char* text_end = NULL)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = ImGui::GetCurrentWindowRead();
|
||||
@ -2878,8 +2876,9 @@ static void LogRenderedText(const ImVec2& ref_pos, const char* text, const char*
|
||||
if (!text_end)
|
||||
text_end = ImGui::FindRenderedTextEnd(text, text_end);
|
||||
|
||||
const bool log_new_line = ref_pos.y > window->DC.LogLinePosY+1;
|
||||
window->DC.LogLinePosY = ref_pos.y;
|
||||
const bool log_new_line = ref_pos && (ref_pos->y > window->DC.LogLinePosY + 1);
|
||||
if (ref_pos)
|
||||
window->DC.LogLinePosY = ref_pos->y;
|
||||
|
||||
const char* text_remaining = text;
|
||||
if (g.LogStartDepth > window->DC.TreeDepth) // Re-adjust padding if we have popped out of our starting depth
|
||||
@ -2944,7 +2943,7 @@ void ImGui::RenderText(ImVec2 pos, const char* text, const char* text_end, bool
|
||||
{
|
||||
window->DrawList->AddText(g.Font, g.FontSize, pos, GetColorU32(ImGuiCol_Text), text, text_display_end);
|
||||
if (g.LogEnabled)
|
||||
LogRenderedText(pos, text, text_display_end);
|
||||
LogRenderedText(&pos, text, text_display_end);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2961,7 +2960,7 @@ void ImGui::RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end
|
||||
{
|
||||
window->DrawList->AddText(g.Font, g.FontSize, pos, GetColorU32(ImGuiCol_Text), text, text_end, wrap_width);
|
||||
if (g.LogEnabled)
|
||||
LogRenderedText(pos, text, text_end);
|
||||
LogRenderedText(&pos, text, text_end);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3003,7 +3002,7 @@ void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, cons
|
||||
window->DrawList->AddText(g.Font, g.FontSize, pos, GetColorU32(ImGuiCol_Text), text, text_display_end, 0.0f, NULL);
|
||||
}
|
||||
if (g.LogEnabled)
|
||||
LogRenderedText(pos, text, text_display_end);
|
||||
LogRenderedText(&pos, text, text_display_end);
|
||||
}
|
||||
|
||||
// Render a rectangle shaped with optional rounding and borders
|
||||
@ -4288,7 +4287,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
||||
if (window->Collapsed)
|
||||
{
|
||||
// Title bar only
|
||||
RenderFrame(title_bar_rect.GetTL(), title_bar_rect.GetBR(), GetColorU32(ImGuiCol_TitleBgCollapsed), true, window_rounding);
|
||||
RenderFrame(title_bar_rect.Min, title_bar_rect.Max, GetColorU32(ImGuiCol_TitleBgCollapsed), true, window_rounding);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -6148,9 +6147,9 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
|
||||
// NB: '##' is normally used to hide text (as a library-wide feature), so we need to specify the text range to make sure the ## aren't stripped out here.
|
||||
const char log_prefix[] = "\n##";
|
||||
const char log_suffix[] = "##";
|
||||
LogRenderedText(text_pos, log_prefix, log_prefix+3);
|
||||
LogRenderedText(&text_pos, log_prefix, log_prefix+3);
|
||||
RenderTextClipped(text_pos, bb.Max, label, label_end, &label_size);
|
||||
LogRenderedText(text_pos, log_suffix+1, log_suffix+3);
|
||||
LogRenderedText(&text_pos, log_suffix+1, log_suffix+3);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -6168,7 +6167,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
|
||||
else if (!(flags & ImGuiTreeNodeFlags_Leaf))
|
||||
RenderCollapseTriangle(bb.Min + ImVec2(padding.x, g.FontSize*0.15f + text_base_offset_y), is_open, 0.70f);
|
||||
if (g.LogEnabled)
|
||||
LogRenderedText(text_pos, ">");
|
||||
LogRenderedText(&text_pos, ">");
|
||||
RenderText(text_pos, label, label_end, false);
|
||||
}
|
||||
|
||||
@ -7461,9 +7460,9 @@ bool ImGui::Checkbox(const char* label, bool* v)
|
||||
}
|
||||
|
||||
if (g.LogEnabled)
|
||||
LogRenderedText(text_bb.GetTL(), *v ? "[x]" : "[ ]");
|
||||
LogRenderedText(&text_bb.Min, *v ? "[x]" : "[ ]");
|
||||
if (label_size.x > 0.0f)
|
||||
RenderText(text_bb.GetTL(), label);
|
||||
RenderText(text_bb.Min, label);
|
||||
|
||||
return pressed;
|
||||
}
|
||||
@ -7533,9 +7532,9 @@ bool ImGui::RadioButton(const char* label, bool active)
|
||||
}
|
||||
|
||||
if (g.LogEnabled)
|
||||
LogRenderedText(text_bb.GetTL(), active ? "(x)" : "( )");
|
||||
LogRenderedText(&text_bb.Min, active ? "(x)" : "( )");
|
||||
if (label_size.x > 0.0f)
|
||||
RenderText(text_bb.GetTL(), label);
|
||||
RenderText(text_bb.Min, label);
|
||||
|
||||
return pressed;
|
||||
}
|
||||
@ -8378,7 +8377,7 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
|
||||
// Log as text
|
||||
if (g.LogEnabled && !is_password)
|
||||
LogRenderedText(render_pos, buf_display, NULL);
|
||||
LogRenderedText(&render_pos, buf_display, NULL);
|
||||
|
||||
if (label_size.x > 0)
|
||||
RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
|
||||
@ -9917,7 +9916,7 @@ void ImGui::Separator()
|
||||
window->DrawList->AddLine(bb.Min, ImVec2(bb.Max.x,bb.Min.y), GetColorU32(ImGuiCol_Separator));
|
||||
|
||||
if (g.LogEnabled)
|
||||
LogText(IM_NEWLINE "--------------------------------");
|
||||
LogRenderedText(NULL, IM_NEWLINE "--------------------------------");
|
||||
|
||||
if (window->DC.ColumnsCount > 1)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user