From 5a4b521855c4212b3e2422fbd643c824a48b4ee8 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 18 Jul 2015 21:50:23 -0600 Subject: [PATCH] Added ImDrawList::AddText() shorthand helper --- imgui.cpp | 8 ++++++++ imgui.h | 1 + 2 files changed, 9 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index c6d567bd..48d7c235 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9632,6 +9632,14 @@ void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos, _VtxCurrentIdx = (ImDrawIdx)VtxBuffer.Size; } +// This is one of the few function breaking the encapsulation of ImDrawLst, but it is just so useful. +void ImDrawList::AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end) +{ + if ((col >> 24) == 0) + return; + AddText(ImGui::GetWindowFont(), ImGui::GetWindowFontSize(), pos, col, text_begin, text_end); +} + void ImDrawList::AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col) { if ((col >> 24) == 0) diff --git a/imgui.h b/imgui.h index d3105bcf..db5f48de 100644 --- a/imgui.h +++ b/imgui.h @@ -1072,6 +1072,7 @@ struct ImDrawList IMGUI_API void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col); IMGUI_API void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); IMGUI_API void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); + IMGUI_API void AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL); IMGUI_API void AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec4* cpu_fine_clip_rect = NULL); IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col = 0xFFFFFFFF); IMGUI_API void AddPolyline(const ImVec2* points, const int num_points, ImU32 col, bool closed, float thickness, bool anti_aliased);