1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-12 02:00:58 +01:00

ImVector: added resize() variant with initialization value

This commit is contained in:
omar 2017-08-15 11:41:00 +08:00
parent b409d399c8
commit f0f86213db
2 changed files with 6 additions and 11 deletions

View File

@ -924,12 +924,13 @@ public:
inline int _grow_capacity(int size) const { int new_capacity = Capacity ? (Capacity + Capacity/2) : 8; return new_capacity > size ? new_capacity : 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;

View File

@ -1912,16 +1912,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)