From 9733f4fa244a11e096440676810156975e6a4483 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 1 May 2016 20:19:28 +0200 Subject: [PATCH] Internal RenderBullet() helper. --- imgui.cpp | 18 ++++++++++-------- imgui_internal.h | 4 +++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b632e398..00990ba5 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2741,6 +2741,12 @@ void ImGui::RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale, bool window->DrawList->AddTriangleFilled(a, b, c, GetColorU32(ImGuiCol_Text)); } +void ImGui::RenderBullet(ImVec2 pos) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DrawList->AddCircleFilled(pos, GImGui->FontSize*0.20f, GetColorU32(ImGuiCol_Text), 8); +} + void ImGui::RenderCheckMark(ImVec2 pos, ImU32 col) { ImGuiState& g = *GImGui; @@ -5929,12 +5935,9 @@ void ImGui::Bullet() return; } - // Render - const float bullet_size = g.FontSize*0.20f; - window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + g.FontSize*0.5f, line_height*0.5f), bullet_size, GetColorU32(ImGuiCol_Text), 8); - - // Stay on same line - ImGui::SameLine(0, style.FramePadding.x*2); + // Render and stay on same line + RenderBullet(bb.Min + ImVec2(style.FramePadding.x + g.FontSize*0.5f, line_height*0.5f)); + SameLine(0, style.FramePadding.x*2); } // Text with a little bullet aligned to the typical tree node. @@ -5958,8 +5961,7 @@ void ImGui::BulletTextV(const char* fmt, va_list args) return; // Render - const float bullet_size = g.FontSize*0.20f; - window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + g.FontSize*0.5f, line_height*0.5f), bullet_size, GetColorU32(ImGuiCol_Text), 8); + RenderBullet(bb.Min + ImVec2(style.FramePadding.x + g.FontSize*0.5f, line_height*0.5f)); RenderText(bb.Min+ImVec2(g.FontSize + style.FramePadding.x*2, text_base_offset_y), text_begin, text_end); } diff --git a/imgui_internal.h b/imgui_internal.h index db4b9ccd..0ef0b847 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -699,12 +699,14 @@ namespace ImGui inline IMGUI_API ImU32 GetColorU32(const ImVec4& col) { ImVec4 c = col; c.w *= GImGui->Style.Alpha; return ImGui::ColorConvertFloat4ToU32(c); } // NB: All position are in absolute pixels coordinates (not window coordinates) - // FIXME: Refactor all RenderText* functions into one. + // FIXME: All those functions are a mess and needs to be refactored into something decent. Avoid use outside of imgui.cpp! + // We need: a sort of symbol library, preferably baked into font atlas when possible + decent text rendering helpers. IMGUI_API void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true); IMGUI_API void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width); IMGUI_API void RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, ImGuiAlign align = ImGuiAlign_Default, const ImVec2* clip_min = NULL, const ImVec2* clip_max = NULL); IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); IMGUI_API void RenderCollapseTriangle(ImVec2 pos, bool opened, float scale = 1.0f, bool shadow = false); + IMGUI_API void RenderBullet(ImVec2 pos); IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col); IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text.