mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
ImVector: added resize() variant with initialization value
This commit is contained in:
parent
032c222d57
commit
f8f382221c
5
imgui.h
5
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;
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user