Log/Capture: Fix various new line/spacing issue by using same render text position when there are both RenderText and LogRenderedText call in widget code.

Also Buttons are now enclosed in bracket
docking
Louis Schnellbach 4 years ago committed by ocornut
parent 9d576a96a5
commit dbaf74d758

@ -30,6 +30,15 @@ HOW TO UPDATE?
and API updates have been a little more frequent lately. They are documented below and in imgui.cpp and should not affect all users. and API updates have been a little more frequent lately. They are documented below and in imgui.cpp and should not affect all users.
- Please report any issue! - Please report any issue!
-----------------------------------------------------------------------
VERSION 1.81 (In Progress)
-----------------------------------------------------------------------
Other Changes:
- Log/Capture: Fix various new line/spacing issue by using same render text position when there are both
RenderText and LogRenderedText call in widget code.
Also Buttons are now enclosed in bracket. [@Xipiryon]
----------------------------------------------------------------------- -----------------------------------------------------------------------
VERSION 1.81 WIP (In Progress) VERSION 1.81 WIP (In Progress)

@ -7572,7 +7572,7 @@ void ImGui::BeginGroup()
window->DC.CursorMaxPos = window->DC.CursorPos; window->DC.CursorMaxPos = window->DC.CursorPos;
window->DC.CurrLineSize = ImVec2(0.0f, 0.0f); window->DC.CurrLineSize = ImVec2(0.0f, 0.0f);
if (g.LogEnabled) if (g.LogEnabled)
g.LogLinePosY = -FLT_MAX; // To enforce Log carriage return LogRenderedTextNewLine();
} }
void ImGui::EndGroup() void ImGui::EndGroup()
@ -7593,7 +7593,7 @@ void ImGui::EndGroup()
window->DC.CurrLineSize = group_data.BackupCurrLineSize; window->DC.CurrLineSize = group_data.BackupCurrLineSize;
window->DC.CurrLineTextBaseOffset = group_data.BackupCurrLineTextBaseOffset; window->DC.CurrLineTextBaseOffset = group_data.BackupCurrLineTextBaseOffset;
if (g.LogEnabled) if (g.LogEnabled)
g.LogLinePosY = -FLT_MAX; // To enforce Log carriage return LogRenderedTextNewLine();
if (!group_data.EmitItem) if (!group_data.EmitItem)
{ {
@ -9867,7 +9867,7 @@ void ImGui::LogRenderedText(const ImVec2* ref_pos, const char* text, const char*
if (!text_end) if (!text_end)
text_end = FindRenderedTextEnd(text, text_end); text_end = FindRenderedTextEnd(text, text_end);
const bool log_new_line = ref_pos && (ref_pos->y > g.LogLinePosY + 1); const bool log_new_line = ref_pos && (ref_pos->y > g.LogLinePosY + g.Style.FramePadding.y + 1);
if (ref_pos) if (ref_pos)
g.LogLinePosY = ref_pos->y; g.LogLinePosY = ref_pos->y;
if (log_new_line) if (log_new_line)
@ -9895,6 +9895,9 @@ void ImGui::LogRenderedText(const ImVec2* ref_pos, const char* text, const char*
else else
LogText(" %.*s", char_count, line_start); LogText(" %.*s", char_count, line_start);
g.LogLineFirstItem = false; g.LogLineFirstItem = false;
if (*line_end == '\n')
LogRenderedTextNewLine();
} }
else if (log_new_line) else if (log_new_line)
{ {
@ -9909,6 +9912,13 @@ void ImGui::LogRenderedText(const ImVec2* ref_pos, const char* text, const char*
} }
} }
void ImGui::LogRenderedTextNewLine()
{
// To enforce Log carriage return
ImGuiContext& g = *GImGui;
g.LogLinePosY = -FLT_MAX;
}
// Start logging/capturing text output // Start logging/capturing text output
void ImGui::LogBegin(ImGuiLogType type, int auto_open_depth) void ImGui::LogBegin(ImGuiLogType type, int auto_open_depth)
{ {

@ -2392,6 +2392,7 @@ namespace ImGui
IMGUI_API void RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFlags flags = ImGuiNavHighlightFlags_TypeDefault); // Navigation highlight IMGUI_API void RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFlags flags = ImGuiNavHighlightFlags_TypeDefault); // Navigation highlight
IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text. IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text.
IMGUI_API void LogRenderedText(const ImVec2* ref_pos, const char* text, const char* text_end = NULL); IMGUI_API void LogRenderedText(const ImVec2* ref_pos, const char* text, const char* text_end = NULL);
IMGUI_API void LogRenderedTextNewLine();
// Render helpers (those functions don't access any ImGui state!) // Render helpers (those functions don't access any ImGui state!)
IMGUI_API void RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImU32 col, ImGuiDir dir, float scale = 1.0f); IMGUI_API void RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImU32 col, ImGuiDir dir, float scale = 1.0f);

@ -692,7 +692,13 @@ bool ImGui::ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags
const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
RenderNavHighlight(bb, id); RenderNavHighlight(bb, id);
RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label, NULL, &label_size, style.ButtonTextAlign, &bb);
ImRect render_text_pos = ImRect(bb.Min + style.FramePadding, bb.Max - style.FramePadding);
if (g.LogEnabled)
LogRenderedText(&render_text_pos.Min, "[");
RenderTextClipped(render_text_pos.Min, render_text_pos.Max ,label, NULL, &label_size, style.ButtonTextAlign, &bb);
if (g.LogEnabled)
LogRenderedText(&render_text_pos.Min, "]");
// Automatically close popups // Automatically close popups
//if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup)) //if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
@ -1097,10 +1103,12 @@ bool ImGui::Checkbox(const char* label, bool* v)
RenderCheckMark(window->DrawList, check_bb.Min + ImVec2(pad, pad), check_col, square_sz - pad * 2.0f); RenderCheckMark(window->DrawList, check_bb.Min + ImVec2(pad, pad), check_col, square_sz - pad * 2.0f);
} }
ImVec2 render_text_pos = ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + style.FramePadding.y);
if (g.LogEnabled) if (g.LogEnabled)
LogRenderedText(&total_bb.Min, mixed_value ? "[~]" : *v ? "[x]" : "[ ]"); LogRenderedText(&render_text_pos, mixed_value ? "[~]" : *v ? "[x]" : "[ ]");
if (label_size.x > 0.0f) if (label_size.x > 0.0f)
RenderText(ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + style.FramePadding.y), label); RenderText(render_text_pos, label);
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0)); IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0));
return pressed; return pressed;
@ -1198,10 +1206,11 @@ bool ImGui::RadioButton(const char* label, bool active)
window->DrawList->AddCircle(center, radius, GetColorU32(ImGuiCol_Border), 16, style.FrameBorderSize); window->DrawList->AddCircle(center, radius, GetColorU32(ImGuiCol_Border), 16, style.FrameBorderSize);
} }
ImVec2 render_text_pos = ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + style.FramePadding.y);
if (g.LogEnabled) if (g.LogEnabled)
LogRenderedText(&total_bb.Min, active ? "(x)" : "( )"); LogRenderedText(&render_text_pos, active ? "(x)" : "( )");
if (label_size.x > 0.0f) if (label_size.x > 0.0f)
RenderText(ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + style.FramePadding.y), label); RenderText(render_text_pos, label);
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags); IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags);
return pressed; return pressed;
@ -1385,7 +1394,11 @@ void ImGui::SeparatorEx(ImGuiSeparatorFlags flags)
// Draw // Draw
window->DrawList->AddLine(bb.Min, ImVec2(bb.Max.x, bb.Min.y), GetColorU32(ImGuiCol_Separator)); window->DrawList->AddLine(bb.Min, ImVec2(bb.Max.x, bb.Min.y), GetColorU32(ImGuiCol_Separator));
if (g.LogEnabled) if (g.LogEnabled)
{
LogRenderedText(&bb.Min, "--------------------------------"); LogRenderedText(&bb.Min, "--------------------------------");
LogRenderedTextNewLine(); // Separator isn't tall enough to trigger a new line automatically in LogRenderText
}
} }
if (columns) if (columns)
{ {
@ -5799,11 +5812,10 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
if (g.LogEnabled) if (g.LogEnabled)
{ {
// 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. // 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_prefix[] = "##";
const char log_suffix[] = "##"; LogRenderedText(&text_pos, log_prefix, log_prefix + 2);
LogRenderedText(&text_pos, log_prefix, log_prefix + 3);
RenderTextClipped(text_pos, frame_bb.Max, label, label_end, &label_size); RenderTextClipped(text_pos, frame_bb.Max, label, label_end, &label_size);
LogRenderedText(&text_pos, log_suffix, log_suffix + 2); LogRenderedText(&text_pos, log_prefix, log_prefix + 2);
} }
else else
{ {

Loading…
Cancel
Save