From f8f382221c846081c4fcfb6668f2b361f0547f60 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 15 Aug 2017 11:41:00 +0800 Subject: [PATCH] ImVector: added resize() variant with initialization value --- imgui.h | 5 +++-- imgui_draw.cpp | 12 +++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/imgui.h b/imgui.h index 98e05d9c..8d0336cc 100644 --- a/imgui.h +++ b/imgui.h @@ -908,12 +908,13 @@ public: inline int _grow_capacity(int new_size) { int new_capacity = Capacity ? (Capacity + Capacity/2) : 8; return new_capacity > new_size ? new_capacity : new_size; } inline void resize(int new_size) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); Size = new_size; } + inline void resize(int new_size, const T& v){ if (new_size > Capacity) reserve(_grow_capacity(new_size)); if (new_size > Size) for (int n = Size; n < new_size; n++) Data[n] = v; Size = new_size; } inline void reserve(int new_capacity) { if (new_capacity <= Capacity) return; - T* new_data = (value_type*)ImGui::MemAlloc((size_t)new_capacity * sizeof(value_type)); + T* new_data = (value_type*)ImGui::MemAlloc((size_t)new_capacity * sizeof(T)); if (Data) - memcpy(new_data, Data, (size_t)Size * sizeof(value_type)); + memcpy(new_data, Data, (size_t)Size * sizeof(T)); ImGui::MemFree(Data); Data = new_data; Capacity = new_capacity; diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 3eb8eea6..b2f599d8 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1820,16 +1820,10 @@ void ImFont::SetFallbackChar(ImWchar c) void ImFont::GrowIndex(int new_size) { IM_ASSERT(IndexXAdvance.Size == IndexLookup.Size); - int old_size = IndexLookup.Size; - if (new_size <= old_size) + if (new_size <= IndexLookup.Size) return; - IndexXAdvance.resize(new_size); - IndexLookup.resize(new_size); - for (int i = old_size; i < new_size; i++) - { - IndexXAdvance[i] = -1.0f; - IndexLookup[i] = (unsigned short)-1; - } + IndexXAdvance.resize(new_size, -1.0f); + IndexLookup.resize(new_size, (unsigned short)-1); } void ImFont::AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst)