From 3869e105746a9196f286d657535d44df84ba7d4c Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 7 Jul 2015 12:39:08 -0600 Subject: [PATCH] ImVector<> access to Size/Capacity/Data (#262) --- imgui.cpp | 268 +++++++++++++++++++++++++++--------------------------- imgui.h | 3 +- 2 files changed, 135 insertions(+), 136 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 17e6c90d..d1216a7a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1502,8 +1502,8 @@ static inline void SetCurrentWindow(ImGuiWindow* window) static inline ImGuiWindow* GetParentWindow() { ImGuiState& g = *GImGui; - IM_ASSERT(g.CurrentWindowStack.size() >= 2); - return g.CurrentWindowStack[g.CurrentWindowStack.size() - 2]; + IM_ASSERT(g.CurrentWindowStack.Size >= 2); + return g.CurrentWindowStack[g.CurrentWindowStack.Size - 2]; } static void SetActiveId(ImGuiID id, ImGuiWindow* window = NULL) @@ -1638,7 +1638,7 @@ void ImGuiStorage::SetVoidPtr(ImU32 key, void* val) void ImGuiStorage::SetAllInt(int v) { - for (int i = 0; i < Data.size(); i++) + for (int i = 0; i < Data.Size; i++) Data[i].val_i = v; } @@ -1694,7 +1694,7 @@ void ImGuiTextFilter::Build() input_range.split(',', Filters); CountGrep = 0; - for (int i = 0; i != Filters.size(); i++) + for (int i = 0; i != Filters.Size; i++) { Filters[i].trim_blanks(); if (Filters[i].empty()) @@ -1712,7 +1712,7 @@ bool ImGuiTextFilter::PassFilter(const char* val) const if (val == NULL) val = ""; - for (int i = 0; i != Filters.size(); i++) + for (int i = 0; i != Filters.Size; i++) { const TextRange& f = Filters[i]; if (f.empty()) @@ -1754,11 +1754,11 @@ void ImGuiTextBuffer::appendv(const char* fmt, va_list args) if (len <= 0) return; - const int write_off = Buf.size(); + const int write_off = Buf.Size; const int needed_sz = write_off + len; - if (write_off + len >= Buf.capacity()) + if (write_off + len >= Buf.Capacity) { - int double_capacity = Buf.capacity() * 2; + int double_capacity = Buf.Capacity * 2; Buf.reserve(needed_sz > double_capacity ? needed_sz : double_capacity); } @@ -1886,14 +1886,14 @@ static inline void AddDrawListToRenderList(ImVector& out_render_lis if (draw_list->commands.back().vtx_count == 0) draw_list->commands.pop_back(); out_render_list.push_back(draw_list); - GImGui->IO.MetricsRenderVertices += draw_list->vtx_buffer.size(); + GImGui->IO.MetricsRenderVertices += draw_list->vtx_buffer.Size; } } static void AddWindowToRenderList(ImVector& out_render_list, ImGuiWindow* window) { AddDrawListToRenderList(out_render_list, window->DrawList); - for (int i = 0; i < window->DC.ChildWindows.size(); i++) + for (int i = 0; i < window->DC.ChildWindows.Size; i++) { ImGuiWindow* child = window->DC.ChildWindows[i]; if (!child->Active) // clipped children may have been marked not active @@ -1922,7 +1922,7 @@ static ImGuiIniData* FindWindowSettings(const char* name) { ImGuiState& g = *GImGui; ImGuiID id = ImHash(name, 0); - for (int i = 0; i != g.Settings.size(); i++) + for (int i = 0; i != g.Settings.Size; i++) { ImGuiIniData* ini = &g.Settings[i]; if (ini->ID == id) @@ -1933,7 +1933,7 @@ static ImGuiIniData* FindWindowSettings(const char* name) static ImGuiIniData* AddWindowSettings(const char* name) { - GImGui->Settings.resize(GImGui->Settings.size() + 1); + GImGui->Settings.resize(GImGui->Settings.Size + 1); ImGuiIniData* ini = &GImGui->Settings.back(); ini->Name = ImStrdup(name); ini->ID = ImHash(name, 0); @@ -1999,7 +1999,7 @@ static void SaveSettings() return; // Gather data from windows that were active during this session - for (int i = 0; i != g.Windows.size(); i++) + for (int i = 0; i != g.Windows.Size; i++) { ImGuiWindow* window = g.Windows[i]; if (window->Flags & ImGuiWindowFlags_NoSavedSettings) @@ -2015,7 +2015,7 @@ static void SaveSettings() FILE* f = fopen(filename, "wt"); if (!f) return; - for (int i = 0; i != g.Settings.size(); i++) + for (int i = 0; i != g.Settings.Size; i++) { const ImGuiIniData* settings = &g.Settings[i]; if (settings->Pos.x == FLT_MAX) @@ -2083,7 +2083,7 @@ void ImGui::NewFrame() IM_ASSERT(g.IO.DeltaTime > 0.0f); IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f); IM_ASSERT(g.IO.RenderDrawListsFn != NULL); // Must be implemented - IM_ASSERT(g.IO.Fonts->Fonts.size() > 0); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ? + IM_ASSERT(g.IO.Fonts->Fonts.Size > 0); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ? IM_ASSERT(g.IO.Fonts->Fonts[0]->IsLoaded()); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ? if (!g.Initialized) @@ -2246,7 +2246,7 @@ void ImGui::NewFrame() g.FocusedWindow->FocusIdxTabRequestNext = 0; // Mark all windows as not visible - for (int i = 0; i != g.Windows.size(); i++) + for (int i = 0; i != g.Windows.Size; i++) { ImGuiWindow* window = g.Windows[i]; window->WasActive = window->Active; @@ -2274,7 +2274,7 @@ void ImGui::Shutdown() SaveSettings(); - for (int i = 0; i < g.Windows.size(); i++) + for (int i = 0; i < g.Windows.Size; i++) { g.Windows[i]->~ImGuiWindow(); ImGui::MemFree(g.Windows[i]); @@ -2285,7 +2285,7 @@ void ImGui::Shutdown() g.FocusedWindow = NULL; g.HoveredWindow = NULL; g.HoveredRootWindow = NULL; - for (int i = 0; i < g.Settings.size(); i++) + for (int i = 0; i < g.Settings.Size; i++) ImGui::MemFree(g.Settings[i].Name); g.Settings.clear(); g.ColorModifiers.clear(); @@ -2342,7 +2342,7 @@ static void AddWindowToSortedBuffer(ImVector& out_sorted_windows, out_sorted_windows.push_back(window); if (window->Active) { - int count = window->DC.ChildWindows.size(); + int count = window->DC.ChildWindows.Size; if (count > 1) qsort(window->DC.ChildWindows.begin(), (size_t)count, sizeof(ImGuiWindow*), ChildWindowComparer); for (int i = 0; i < count; i++) @@ -2391,7 +2391,7 @@ void ImGui::Render() if (first_render_of_the_frame) { // Hide implicit "Debug" window if it hasn't been used - IM_ASSERT(g.CurrentWindowStack.size() == 1); // Mismatched Begin/End + IM_ASSERT(g.CurrentWindowStack.Size == 1); // Mismatched Begin/End if (g.CurrentWindow && !g.CurrentWindow->Accessed) g.CurrentWindow->Active = false; ImGui::End(); @@ -2418,8 +2418,8 @@ void ImGui::Render() // Sort the window list so that all child windows are after their parent // We cannot do that on FocusWindow() because childs may not exist yet g.WindowsSortBuffer.resize(0); - g.WindowsSortBuffer.reserve(g.Windows.size()); - for (int i = 0; i != g.Windows.size(); i++) + g.WindowsSortBuffer.reserve(g.Windows.Size); + for (int i = 0; i != g.Windows.Size; i++) { ImGuiWindow* window = g.Windows[i]; if (window->Flags & ImGuiWindowFlags_ChildWindow) // if a child is active its parent will add it @@ -2427,7 +2427,7 @@ void ImGui::Render() continue; AddWindowToSortedBuffer(g.WindowsSortBuffer, window); } - IM_ASSERT(g.Windows.size() == g.WindowsSortBuffer.size()); // we done something wrong + IM_ASSERT(g.Windows.Size == g.WindowsSortBuffer.Size); // we done something wrong g.Windows.swap(g.WindowsSortBuffer); // Clear Input data for next frame @@ -2452,7 +2452,7 @@ void ImGui::Render() g.IO.MetricsActiveWindows = 0; for (int i = 0; i < IM_ARRAYSIZE(g.RenderDrawLists); i++) g.RenderDrawLists[i].resize(0); - for (int i = 0; i != g.Windows.size(); i++) + for (int i = 0; i != g.Windows.Size; i++) { ImGuiWindow* window = g.Windows[i]; if (window->Active && window->HiddenFrames <= 0 && (window->Flags & (ImGuiWindowFlags_ChildWindow)) == 0) @@ -2469,18 +2469,18 @@ void ImGui::Render() } // Flatten layers - int n = g.RenderDrawLists[0].size(); + int n = g.RenderDrawLists[0].Size; int flattened_size = n; for (int i = 1; i < IM_ARRAYSIZE(g.RenderDrawLists); i++) - flattened_size += g.RenderDrawLists[i].size(); + flattened_size += g.RenderDrawLists[i].Size; g.RenderDrawLists[0].resize(flattened_size); for (int i = 1; i < IM_ARRAYSIZE(g.RenderDrawLists); i++) { ImVector& layer = g.RenderDrawLists[i]; if (!layer.empty()) { - memcpy(&g.RenderDrawLists[0][n], &layer[0], layer.size() * sizeof(ImDrawList*)); - n += layer.size(); + memcpy(&g.RenderDrawLists[0][n], &layer[0], layer.Size * sizeof(ImDrawList*)); + n += layer.Size; } } @@ -2502,7 +2502,7 @@ void ImGui::Render() // Render if (!g.RenderDrawLists[0].empty()) - g.IO.RenderDrawListsFn(&g.RenderDrawLists[0][0], g.RenderDrawLists[0].size()); + g.IO.RenderDrawListsFn(&g.RenderDrawLists[0][0], g.RenderDrawLists[0].Size); } } @@ -2828,7 +2828,7 @@ void ImGui::CalcListClipping(int items_count, float items_height, int* out_items static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs) { ImGuiState& g = *GImGui; - for (int i = g.Windows.size()-1; i >= 0; i--) + for (int i = g.Windows.Size-1; i >= 0; i--) { ImGuiWindow* window = g.Windows[i]; if (!window->Active) @@ -3141,7 +3141,7 @@ void ImGui::EndTooltip() static bool IsPopupOpen(ImGuiID id) { ImGuiState& g = *GImGui; - const bool opened = g.OpenedPopupStack.size() > g.CurrentPopupStack.size() && g.OpenedPopupStack[g.CurrentPopupStack.size()].PopupID == id; + const bool opened = g.OpenedPopupStack.Size > g.CurrentPopupStack.Size && g.OpenedPopupStack[g.CurrentPopupStack.Size].PopupID == id; return opened; } @@ -3151,9 +3151,9 @@ void ImGui::OpenPopup(const char* str_id) ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); ImGuiID id = window->GetID(str_id); - int current_stack_size = g.CurrentPopupStack.size(); + int current_stack_size = g.CurrentPopupStack.Size; ImGuiPopupRef popup_ref = ImGuiPopupRef(id, window, window->GetID("##menus")); // Tagged as new ref because constructor sets Window to NULL (we are passing the ParentWindow info here) - if (g.OpenedPopupStack.size() < current_stack_size + 1) + if (g.OpenedPopupStack.Size < current_stack_size + 1) g.OpenedPopupStack.push_back(popup_ref); else if (g.OpenedPopupStack[current_stack_size].PopupID != id) { @@ -3173,7 +3173,7 @@ static void CloseInactivePopups() int n = 0; if (g.FocusedWindow) { - for (n = 0; n < g.OpenedPopupStack.size(); n++) + for (n = 0; n < g.OpenedPopupStack.Size; n++) { ImGuiPopupRef& popup = g.OpenedPopupStack[n]; if (!popup.Window) @@ -3187,7 +3187,7 @@ static void CloseInactivePopups() else { bool has_focus = false; - for (int m = n; m < g.OpenedPopupStack.size() && !has_focus; m++) + for (int m = n; m < g.OpenedPopupStack.Size && !has_focus; m++) has_focus = (g.OpenedPopupStack[m].Window && g.OpenedPopupStack[m].Window->RootWindow == g.FocusedWindow->RootWindow); if (!has_focus) break; @@ -3222,15 +3222,15 @@ static void ClosePopup(ImGuiID id) if (!IsPopupOpen(id)) return; ImGuiState& g = *GImGui; - ClosePopupToLevel(g.OpenedPopupStack.size() - 1); + ClosePopupToLevel(g.OpenedPopupStack.Size - 1); } // Close the popup we have begin-ed into. void ImGui::CloseCurrentPopup() { ImGuiState& g = *GImGui; - int popup_idx = g.CurrentPopupStack.size() - 1; - if (popup_idx < 0 || popup_idx > g.OpenedPopupStack.size() || g.CurrentPopupStack[popup_idx].PopupID != g.OpenedPopupStack[popup_idx].PopupID) + int popup_idx = g.CurrentPopupStack.Size - 1; + if (popup_idx < 0 || popup_idx > g.OpenedPopupStack.Size || g.CurrentPopupStack[popup_idx].PopupID != g.OpenedPopupStack[popup_idx].PopupID) return; while (popup_idx > 0 && g.OpenedPopupStack[popup_idx].Window && (g.OpenedPopupStack[popup_idx].Window->Flags & ImGuiWindowFlags_ChildMenu)) popup_idx--; @@ -3259,7 +3259,7 @@ static bool BeginPopupEx(const char* str_id, ImGuiWindowFlags extra_flags) char name[32]; if (flags & ImGuiWindowFlags_ChildMenu) - ImFormatString(name, 20, "##menu_%d", g.CurrentPopupStack.size()); // Recycle windows based on depth + ImFormatString(name, 20, "##menu_%d", g.CurrentPopupStack.Size); // Recycle windows based on depth else ImFormatString(name, 20, "##popup_%08x", id); // Not recycling, so we can close/open during the same frame float alpha = 1.0f; @@ -3306,7 +3306,7 @@ void ImGui::EndPopup() { ImGuiWindow* window = GetCurrentWindow(); IM_ASSERT(window->Flags & ImGuiWindowFlags_Popup); - IM_ASSERT(GImGui->CurrentPopupStack.size() > 0); + IM_ASSERT(GImGui->CurrentPopupStack.Size > 0); ImGui::End(); if (!(window->Flags & ImGuiWindowFlags_Modal)) ImGui::PopStyleVar(); @@ -3431,12 +3431,12 @@ static void CheckStacksSize(ImGuiWindow* window, bool write) // NOT checking: DC.ItemWidth, DC.AllowKeyboardFocus, DC.ButtonRepeat, DC.TextWrapPos (per window) to allow user to conveniently push once and not pop (they are cleared on Begin) ImGuiState& g = *GImGui; int* p_backup = &window->DC.StackSizesBackup[0]; - { int current = window->IDStack.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopID() - { int current = window->DC.GroupStack.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot EndGroup() - { int current = g.CurrentPopupStack.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot EndPopup()/EndMenu() - { int current = g.ColorModifiers.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopStyleColor() - { int current = g.StyleModifiers.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopStyleVar() - { int current = g.FontStack.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopFont() + { int current = window->IDStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopID() + { int current = window->DC.GroupStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot EndGroup() + { int current = g.CurrentPopupStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot EndPopup()/EndMenu() + { int current = g.ColorModifiers.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopStyleColor() + { int current = g.StyleModifiers.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopStyleVar() + { int current = g.FontStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopFont() IM_ASSERT(p_backup == window->DC.StackSizesBackup + IM_ARRAYSIZE(window->DC.StackSizesBackup)); } @@ -3476,7 +3476,7 @@ static ImGuiWindow* FindWindowByName(const char* name) // FIXME-OPT: Store sorted hashes -> pointers. ImGuiState& g = *GImGui; ImGuiID id = ImHash(name, 0); - for (int i = 0; i < g.Windows.size(); i++) + for (int i = 0; i < g.Windows.Size; i++) if (g.Windows[i]->ID == id) return g.Windows[i]; return NULL; @@ -3587,7 +3587,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_ bool window_was_visible = (window->LastFrameDrawn == current_frame - 1); // Not using !WasActive because the implicit "Debug" window would always toggle off->on if (flags & ImGuiWindowFlags_Popup) { - ImGuiPopupRef& popup_ref = g.OpenedPopupStack[g.CurrentPopupStack.size()]; + ImGuiPopupRef& popup_ref = g.OpenedPopupStack[g.CurrentPopupStack.Size]; window_was_visible &= (window->PopupID == popup_ref.PopupID); window_was_visible &= (window == popup_ref.Window); popup_ref.Window = window; @@ -3635,7 +3635,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_ // Update known root window (if we are a child window, otherwise window == window->RootWindow) int root_idx, root_non_popup_idx; - for (root_idx = g.CurrentWindowStack.size() - 1; root_idx > 0; root_idx--) + for (root_idx = g.CurrentWindowStack.Size - 1; root_idx > 0; root_idx--) if (!(g.CurrentWindowStack[root_idx]->Flags & ImGuiWindowFlags_ChildWindow)) break; for (root_non_popup_idx = root_idx; root_non_popup_idx > 0; root_non_popup_idx--) @@ -4216,7 +4216,7 @@ static void FocusWindow(ImGuiWindow* window) if (g.Windows.back() == window) return; - for (int i = 0; i < g.Windows.size(); i++) + for (int i = 0; i < g.Windows.Size; i++) if (g.Windows[i] == window) { g.Windows.erase(g.Windows.begin() + i); @@ -6843,7 +6843,7 @@ static int STB_TEXTEDIT_KEYTOTEXT(int key) static ImWchar STB_TEXTEDIT_NEWLINE = '\n'; static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx) { - const ImWchar* text = obj->Text.begin(); + const ImWchar* text = obj->Text.Data; const ImWchar* text_remaining = NULL; const ImVec2 size = InputTextCalcTextSizeW(text + line_start_idx, text + obj->CurLenW, &text_remaining, NULL, true); r->x0 = 0.0f; @@ -6858,14 +6858,14 @@ static bool is_separator(unsigned int c) #define STB_TEXTEDIT_IS_SPACE(CH) ( ImCharIsSpace((unsigned int)CH) || is_separator((unsigned int)CH) ) static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n) { - ImWchar* dst = obj->Text.begin() + pos; + ImWchar* dst = obj->Text.Data + pos; // We maintain our buffer length in both UTF-8 and wchar formats obj->CurLenA -= ImTextCountUtf8BytesFromStr(dst, dst + n); obj->CurLenW -= n; // Offset remaining text - const ImWchar* src = obj->Text.begin() + pos + n; + const ImWchar* src = obj->Text.Data + pos + n; while (ImWchar c = *src++) *dst++ = c; *dst = '\0'; @@ -6874,14 +6874,14 @@ static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n) static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const ImWchar* new_text, int new_text_len) { const int text_len = obj->CurLenW; - if (new_text_len + text_len + 1 > obj->Text.size()) + if (new_text_len + text_len + 1 > obj->Text.Size) return false; const int new_text_len_utf8 = ImTextCountUtf8BytesFromStr(new_text, new_text + new_text_len); if (new_text_len_utf8 + obj->CurLenA + 1 > obj->BufSizeA) return false; - ImWchar* text = obj->Text.begin(); + ImWchar* text = obj->Text.Data; if (pos != text_len) memmove(text + pos + new_text_len, text + pos, (size_t)(text_len - pos) * sizeof(ImWchar)); memcpy(text + pos, new_text, (size_t)new_text_len * sizeof(ImWchar)); @@ -7095,9 +7095,9 @@ static bool InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 // From the moment we focused we are ignoring the content of 'buf' edit_state.Text.resize(buf_size); // wchar count <= utf-8 count edit_state.InitialText.resize(buf_size); // utf-8 - ImFormatString(edit_state.InitialText.begin(), edit_state.InitialText.size(), "%s", buf); + ImFormatString(edit_state.InitialText.Data, edit_state.InitialText.Size, "%s", buf); const char* buf_end = NULL; - edit_state.CurLenW = ImTextStrFromUtf8(edit_state.Text.begin(), edit_state.Text.size(), buf, NULL, &buf_end); + edit_state.CurLenW = ImTextStrFromUtf8(edit_state.Text.Data, edit_state.Text.Size, buf, NULL, &buf_end); edit_state.CurLenA = (int)(buf_end - buf); // We can't get the result from ImFormatString() above because it is not UTF-8 aware. Here we'll cut off malformed UTF-8. edit_state.InputCursorScreenPos = ImVec2(-1.f, -1.f); edit_state.CursorAnimReset(); @@ -7230,8 +7230,8 @@ static bool InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 const int ib = edit_state.HasSelection() ? ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end) : 0; const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : edit_state.CurLenW; edit_state.TempTextBuffer.resize((ie-ib) * 4 + 1); - ImTextStrToUtf8(edit_state.TempTextBuffer.begin(), edit_state.TempTextBuffer.size(), edit_state.Text.begin()+ib, edit_state.Text.begin()+ie); - g.IO.SetClipboardTextFn(edit_state.TempTextBuffer.begin()); + ImTextStrToUtf8(edit_state.TempTextBuffer.Data, edit_state.TempTextBuffer.Size, edit_state.Text.Data+ib, edit_state.Text.Data+ie); + g.IO.SetClipboardTextFn(edit_state.TempTextBuffer.Data); } if (cut) @@ -7275,7 +7275,7 @@ static bool InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 if (cancel_edit) { // Restore initial value - ImFormatString(buf, buf_size, "%s", edit_state.InitialText.begin()); + ImFormatString(buf, buf_size, "%s", edit_state.InitialText.Data); value_changed = true; } else @@ -7284,8 +7284,8 @@ static bool InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 // Note that as soon as we can focus into the input box, the in-widget value gets priority over any underlying modification of the input buffer // FIXME: We actually always render 'buf' in RenderTextScrolledClipped // FIXME-OPT: CPU waste to do this every time the widget is active, should mark dirty state from the stb_textedit callbacks - edit_state.TempTextBuffer.resize(edit_state.Text.size() * 4); - ImTextStrToUtf8(edit_state.TempTextBuffer.begin(), edit_state.TempTextBuffer.size(), edit_state.Text.begin(), NULL); + edit_state.TempTextBuffer.resize(edit_state.Text.Size * 4); + ImTextStrToUtf8(edit_state.TempTextBuffer.Data, edit_state.TempTextBuffer.Size, edit_state.Text.Data, NULL); // User callback if ((flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackAlways)) != 0) @@ -7316,14 +7316,14 @@ static bool InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 ImGuiTextEditCallbackData callback_data; callback_data.EventFlag = event_flag; callback_data.EventKey = event_key; - callback_data.Buf = edit_state.TempTextBuffer.begin(); + callback_data.Buf = edit_state.TempTextBuffer.Data; callback_data.BufSize = edit_state.BufSizeA; callback_data.BufDirty = false; callback_data.Flags = flags; callback_data.UserData = user_data; // We have to convert from position from wchar to UTF-8 positions - ImWchar* text = edit_state.Text.begin(); + ImWchar* text = edit_state.Text.Data; const int utf8_cursor_pos = callback_data.CursorPos = ImTextCountUtf8BytesFromStr(text, text + edit_state.StbState.cursor); const int utf8_selection_start = callback_data.SelectionStart = ImTextCountUtf8BytesFromStr(text, text + edit_state.StbState.select_start); const int utf8_selection_end = callback_data.SelectionEnd = ImTextCountUtf8BytesFromStr(text, text + edit_state.StbState.select_end); @@ -7332,7 +7332,7 @@ static bool InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 callback(&callback_data); // Read back what user may have modified - IM_ASSERT(callback_data.Buf == edit_state.TempTextBuffer.begin()); // Invalid to modify those fields + IM_ASSERT(callback_data.Buf == edit_state.TempTextBuffer.Data); // Invalid to modify those fields IM_ASSERT(callback_data.BufSize == edit_state.BufSizeA); IM_ASSERT(callback_data.Flags == flags); if (callback_data.CursorPos != utf8_cursor_pos) edit_state.StbState.cursor = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.CursorPos); @@ -7340,16 +7340,16 @@ static bool InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 if (callback_data.SelectionEnd != utf8_selection_end) edit_state.StbState.select_end = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionEnd); if (callback_data.BufDirty) { - edit_state.CurLenW = ImTextStrFromUtf8(text, edit_state.Text.size(), edit_state.TempTextBuffer.begin(), NULL); - edit_state.CurLenA = (int)strlen(edit_state.TempTextBuffer.begin()); + edit_state.CurLenW = ImTextStrFromUtf8(text, edit_state.Text.Size, edit_state.TempTextBuffer.Data, NULL); + edit_state.CurLenA = (int)strlen(edit_state.TempTextBuffer.Data); edit_state.CursorAnimReset(); } } } - if (strcmp(edit_state.TempTextBuffer.begin(), buf) != 0) + if (strcmp(edit_state.TempTextBuffer.Data, buf) != 0) { - ImFormatString(buf, buf_size, "%s", edit_state.TempTextBuffer.begin()); + ImFormatString(buf, buf_size, "%s", edit_state.TempTextBuffer.Data); value_changed = true; } } @@ -7371,7 +7371,7 @@ static bool InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 // - Handle scrolling, highlight selection, display cursor (those all requires some form of 1d->2d cursor position calculation) // - Measure text height (for scrollbar) // We are attempting to do most of that in one main pass to minimize the computation cost (non-negligible for large amount of text) + 2nd pass for selection rendering (we could merge them by an extra refactoring effort) - const ImWchar* text_begin = edit_state.Text.begin(); + const ImWchar* text_begin = edit_state.Text.Data; const ImWchar* text_end = text_begin + edit_state.CurLenW; ImVec2 cursor_offset, select_start_offset; @@ -8130,7 +8130,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled) bool pressed; bool opened = IsPopupOpen(id); - bool menuset_opened = !(window->Flags & ImGuiWindowFlags_Popup) && (g.OpenedPopupStack.size() > g.CurrentPopupStack.size() && g.OpenedPopupStack[g.CurrentPopupStack.size()].ParentMenuSet == window->GetID("##menus")); + bool menuset_opened = !(window->Flags & ImGuiWindowFlags_Popup) && (g.OpenedPopupStack.Size > g.CurrentPopupStack.Size && g.OpenedPopupStack[g.CurrentPopupStack.Size].ParentMenuSet == window->GetID("##menus")); if (menuset_opened) g.FocusedWindow = window; @@ -8166,9 +8166,9 @@ bool ImGui::BeginMenu(const char* label, bool enabled) { // Implement http://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown to avoid using timers so menus feel more reactive. bool moving_within_opened_triangle = false; - if (g.HoveredWindow == window && g.OpenedPopupStack.size() > g.CurrentPopupStack.size() && g.OpenedPopupStack[g.CurrentPopupStack.size()].ParentWindow == window) + if (g.HoveredWindow == window && g.OpenedPopupStack.Size > g.CurrentPopupStack.Size && g.OpenedPopupStack[g.CurrentPopupStack.Size].ParentWindow == window) { - if (ImGuiWindow* next_window = g.OpenedPopupStack[g.CurrentPopupStack.size()].Window) + if (ImGuiWindow* next_window = g.OpenedPopupStack[g.CurrentPopupStack.Size].Window) { ImRect next_window_rect = next_window->Rect(); ImVec2 ta = g.IO.MousePos - g.IO.MouseDelta; @@ -8195,9 +8195,9 @@ bool ImGui::BeginMenu(const char* label, bool enabled) want_open = true; if (want_close && IsPopupOpen(id)) - ClosePopupToLevel(GImGui->CurrentPopupStack.size()); + ClosePopupToLevel(GImGui->CurrentPopupStack.Size); - if (!opened && want_open && g.OpenedPopupStack.size() > g.CurrentPopupStack.size()) + if (!opened && want_open && g.OpenedPopupStack.Size > g.CurrentPopupStack.Size) { // Don't recycle same menu level in the same frame, first close the other menu and yield for a frame. ImGui::OpenPopup(label); @@ -8549,7 +8549,7 @@ void ImGui::BeginGroup() { ImGuiWindow* window = GetCurrentWindow(); - window->DC.GroupStack.resize(window->DC.GroupStack.size() + 1); + window->DC.GroupStack.resize(window->DC.GroupStack.Size + 1); ImGuiGroupData& group_data = window->DC.GroupStack.back(); group_data.BackupCursorPos = window->DC.CursorPos; group_data.BackupCursorMaxPos = window->DC.CursorMaxPos; @@ -8703,7 +8703,7 @@ float ImGui::GetColumnOffset(int column_index) } // Read from cache - IM_ASSERT(column_index < window->DC.ColumnsOffsetsT.size()); + IM_ASSERT(column_index < window->DC.ColumnsOffsetsT.Size); const float t = window->DC.ColumnsOffsetsT[column_index]; const float min_x = window->DC.ColumnsStartX; @@ -8719,7 +8719,7 @@ void ImGui::SetColumnOffset(int column_index, float offset) if (column_index < 0) column_index = window->DC.ColumnsCurrent; - IM_ASSERT(column_index < window->DC.ColumnsOffsetsT.size()); + IM_ASSERT(column_index < window->DC.ColumnsOffsetsT.Size); const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index); const float min_x = window->DC.ColumnsStartX; @@ -8990,7 +8990,7 @@ void ImDrawList::UpdateClipRect() else { ImVec4 current_clip_rect = clip_rect_stack.empty() ? GNullClipRect : clip_rect_stack.back(); - if (commands.size() > 2 && ImLengthSqr(commands[commands.size()-2].clip_rect - current_clip_rect) < 0.00001f) + if (commands.Size > 2 && ImLengthSqr(commands[commands.Size-2].clip_rect - current_clip_rect) < 0.00001f) commands.pop_back(); else current_cmd->clip_rect = current_clip_rect; @@ -9015,7 +9015,7 @@ void ImDrawList::PushClipRectFullScreen() void ImDrawList::PopClipRect() { - IM_ASSERT(clip_rect_stack.size() > 0); + IM_ASSERT(clip_rect_stack.Size > 0); clip_rect_stack.pop_back(); UpdateClipRect(); } @@ -9042,7 +9042,7 @@ void ImDrawList::PushTextureID(const ImTextureID& texture_id) void ImDrawList::PopTextureID() { - IM_ASSERT(texture_id_stack.size() > 0); + IM_ASSERT(texture_id_stack.Size > 0); texture_id_stack.pop_back(); UpdateTextureID(); } @@ -9052,9 +9052,9 @@ void ImDrawList::PrimReserve(unsigned int vtx_count) ImDrawCmd& draw_cmd = commands.back(); draw_cmd.vtx_count += vtx_count; - int vtx_buffer_size = vtx_buffer.size(); + int vtx_buffer_size = vtx_buffer.Size; vtx_buffer.resize(vtx_buffer_size + vtx_count); - vtx_write = vtx_buffer.begin() + vtx_buffer_size; + vtx_write = vtx_buffer.Data + vtx_buffer_size; } void ImDrawList::PrimTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col) @@ -9298,7 +9298,7 @@ void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos, // reserve vertices for worse case const unsigned int char_count = (unsigned int)(text_end - text_begin); const unsigned int vtx_count_max = char_count * 6; - const int vtx_begin = vtx_buffer.size(); + const int vtx_begin = vtx_buffer.Size; PrimReserve(vtx_count_max); ImVec4 clip_rect = clip_rect_stack.back(); @@ -9313,7 +9313,7 @@ void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos, // give back unused vertices vtx_buffer.resize((int)(vtx_write - &vtx_buffer.front())); - const int vtx_count = vtx_buffer.size() - vtx_begin; + const int vtx_count = vtx_buffer.Size - vtx_begin; commands.back().vtx_count -= (unsigned int)(vtx_count_max - vtx_count); vtx_write -= (vtx_count_max - vtx_count); } @@ -9372,7 +9372,7 @@ ImFontAtlas::~ImFontAtlas() void ImFontAtlas::ClearInputData() { - for (int i = 0; i < InputData.size(); i++) + for (int i = 0; i < InputData.Size; i++) { if (InputData[i]->TTFData) ImGui::MemFree(InputData[i]->TTFData); @@ -9393,7 +9393,7 @@ void ImFontAtlas::ClearTexData() void ImFontAtlas::ClearFonts() { - for (int i = 0; i < Fonts.size(); i++) + for (int i = 0; i < Fonts.Size; i++) { Fonts[i]->~ImFont(); ImGui::MemFree(Fonts[i]); @@ -9513,7 +9513,7 @@ ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* compressed_ttf_d bool ImFontAtlas::Build() { - IM_ASSERT(InputData.size() > 0); + IM_ASSERT(InputData.Size > 0); TexID = NULL; TexWidth = TexHeight = 0; @@ -9523,7 +9523,7 @@ bool ImFontAtlas::Build() // Initialize font information early (so we can error without any cleanup) + count glyphs int total_glyph_count = 0; int total_glyph_range_count = 0; - for (int input_i = 0; input_i < InputData.size(); input_i++) + for (int input_i = 0; input_i < InputData.Size; input_i++) { ImFontAtlasData& data = *InputData[input_i]; IM_ASSERT(data.OutFont && (!data.OutFont->IsLoaded() || data.OutFont->ContainerAtlas == this)); @@ -9553,8 +9553,8 @@ bool ImFontAtlas::Build() // Pack our extra data rectangles first, so it will be on the upper-left corner of our texture (UV will have small values). ImVector extra_rects; RenderCustomTexData(0, &extra_rects); - stbrp_pack_rects((stbrp_context*)spc.pack_info, &extra_rects[0], extra_rects.size()); - for (int i = 0; i < extra_rects.size(); i++) + stbrp_pack_rects((stbrp_context*)spc.pack_info, &extra_rects[0], extra_rects.Size); + for (int i = 0; i < extra_rects.Size; i++) if (extra_rects[i].was_packed) TexHeight = ImMax(TexHeight, extra_rects[i].y + extra_rects[i].h); @@ -9568,7 +9568,7 @@ bool ImFontAtlas::Build() memset(buf_ranges, 0, total_glyph_range_count * sizeof(stbtt_pack_range)); // First font pass: pack all glyphs (no rendering at this point, we are working with glyph sizes only) - for (int input_i = 0; input_i < InputData.size(); input_i++) + for (int input_i = 0; input_i < InputData.Size; input_i++) { ImFontAtlasData& data = *InputData[input_i]; @@ -9617,7 +9617,7 @@ bool ImFontAtlas::Build() spc.height = TexHeight; // Second pass: render characters - for (int input_i = 0; input_i < InputData.size(); input_i++) + for (int input_i = 0; input_i < InputData.Size; input_i++) { ImFontAtlasData& data = *InputData[input_i]; ret = stbtt_PackFontRangesRenderIntoRects(&spc, &data.FontInfo, data.Ranges, data.RangesCount, data.Rects); @@ -9630,7 +9630,7 @@ bool ImFontAtlas::Build() buf_rects = NULL; // Third pass: setup ImFont and glyphs for runtime - for (int input_i = 0; input_i < InputData.size(); input_i++) + for (int input_i = 0; input_i < InputData.Size; input_i++) { ImFontAtlasData& data = *InputData[input_i]; data.OutFont->ContainerAtlas = this; @@ -9655,7 +9655,7 @@ bool ImFontAtlas::Build() if (!pc.x0 && !pc.x1 && !pc.y0 && !pc.y1) continue; - data.OutFont->Glyphs.resize(data.OutFont->Glyphs.size() + 1); + data.OutFont->Glyphs.resize(data.OutFont->Glyphs.Size + 1); ImFont::Glyph& glyph = data.OutFont->Glyphs.back(); glyph.Codepoint = (ImWchar)(range.first_unicode_char_in_range + char_idx); glyph.Width = (signed short)pc.x1 - pc.x0 + 1; @@ -9909,7 +9909,7 @@ void ImFont::Clear() void ImFont::BuildLookupTable() { int max_codepoint = 0; - for (int i = 0; i != Glyphs.size(); i++) + for (int i = 0; i != Glyphs.Size; i++) max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint); IndexXAdvance.clear(); @@ -9921,7 +9921,7 @@ void ImFont::BuildLookupTable() IndexXAdvance[i] = -1.0f; IndexLookup[i] = -1; } - for (int i = 0; i < Glyphs.size(); i++) + for (int i = 0; i < Glyphs.Size; i++) { int codepoint = (int)Glyphs[i].Codepoint; IndexXAdvance[codepoint] = Glyphs[i].XAdvance; @@ -9933,13 +9933,13 @@ void ImFont::BuildLookupTable() if (FindGlyph((unsigned short)' ')) { if (Glyphs.back().Codepoint != '\t') // So we can call this function multiple times - Glyphs.resize(Glyphs.size() + 1); + Glyphs.resize(Glyphs.Size + 1); ImFont::Glyph& tab_glyph = Glyphs.back(); tab_glyph = *FindGlyph((unsigned short)' '); tab_glyph.Codepoint = '\t'; tab_glyph.XAdvance *= 4; IndexXAdvance[(int)tab_glyph.Codepoint] = (float)tab_glyph.XAdvance; - IndexLookup[(int)tab_glyph.Codepoint] = (int)(Glyphs.size()-1); + IndexLookup[(int)tab_glyph.Codepoint] = (int)(Glyphs.Size-1); } FallbackGlyph = NULL; @@ -9958,7 +9958,7 @@ void ImFont::SetFallbackChar(ImWchar c) const ImFont::Glyph* ImFont::FindGlyph(unsigned short c) const { - if (c < IndexLookup.size()) + if (c < IndexLookup.Size) { const int i = IndexLookup[c]; if (i != -1) @@ -10192,7 +10192,7 @@ const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const c } } - const float char_width = ((int)c < IndexXAdvance.size()) ? IndexXAdvance[(int)c] * scale : FallbackXAdvance; + const float char_width = ((int)c < IndexXAdvance.Size) ? IndexXAdvance[(int)c] * scale : FallbackXAdvance; if (ImCharIsSpace(c)) { if (inside_word) @@ -10308,7 +10308,7 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons continue; } - const float char_width = ((int)c < IndexXAdvance.size() ? IndexXAdvance[(int)c] : FallbackXAdvance) * scale; + const float char_width = ((int)c < IndexXAdvance.Size ? IndexXAdvance[(int)c] : FallbackXAdvance) * scale; if (line_width + char_width >= max_width) { s = prev_s; @@ -10852,13 +10852,13 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::TreePop(); } - if (ImGui::TreeNode("Fonts", "Fonts (%d)", ImGui::GetIO().Fonts->Fonts.size())) + if (ImGui::TreeNode("Fonts", "Fonts (%d)", ImGui::GetIO().Fonts->Fonts.Size)) { ImGui::TextWrapped("Tip: Load fonts with GetIO().Fonts->AddFontFromFileTTF()."); - for (int i = 0; i < ImGui::GetIO().Fonts->Fonts.size(); i++) + for (int i = 0; i < ImGui::GetIO().Fonts->Fonts.Size; i++) { ImFont* font = ImGui::GetIO().Fonts->Fonts[i]; - ImGui::BulletText("Font %d: %.2f pixels, %d glyphs", i, font->FontSize, font->Glyphs.size()); + ImGui::BulletText("Font %d: %.2f pixels, %d glyphs", i, font->FontSize, font->Glyphs.Size); ImGui::TreePush((void*)i); ImGui::PushFont(font); ImGui::Text("The quick brown fox jumps over the lazy dog"); @@ -11337,7 +11337,7 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr)); static bool pause; - static ImVector values; if (values.empty()) { values.resize(90); memset(&values.front(), 0, values.size()*sizeof(float)); } + static ImVector values; if (values.empty()) { values.resize(90); memset(&values.front(), 0, values.Size*sizeof(float)); } static int values_offset = 0; if (!pause) { @@ -11346,11 +11346,11 @@ void ImGui::ShowTestWindow(bool* opened) { static float phase = 0.0f; values[values_offset] = cosf(phase); - values_offset = (values_offset+1)%values.size(); + values_offset = (values_offset+1)%values.Size; phase += 0.10f*values_offset; } } - ImGui::PlotLines("##Graph", &values.front(), (int)values.size(), values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80)); + ImGui::PlotLines("##Graph", &values.front(), (int)values.Size, values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80)); ImGui::SameLine(0, (int)ImGui::GetStyle().ItemInnerSpacing.x); ImGui::BeginGroup(); ImGui::Text("Graph"); @@ -12013,7 +12013,7 @@ void ImGui::ShowMetricsWindow(bool* opened) { static void NodeDrawList(ImDrawList* draw_list, const char* label) { - bool node_opened = ImGui::TreeNode(draw_list, "%s: '%s' %d vtx, %d cmds", label, draw_list->owner_name ? draw_list->owner_name : "", draw_list->vtx_buffer.size(), draw_list->commands.size()); + bool node_opened = ImGui::TreeNode(draw_list, "%s: '%s' %d vtx, %d cmds", label, draw_list->owner_name ? draw_list->owner_name : "", draw_list->vtx_buffer.Size, draw_list->commands.Size); if (draw_list == ImGui::GetWindowDrawList()) { ImGui::SameLine(); @@ -12039,9 +12039,9 @@ void ImGui::ShowMetricsWindow(bool* opened) static void NodeWindows(ImVector& windows, const char* label) { - if (!ImGui::TreeNode(label, "%s (%d)", label, windows.size())) + if (!ImGui::TreeNode(label, "%s (%d)", label, windows.Size)) return; - for (int i = 0; i < windows.size(); i++) + for (int i = 0; i < windows.Size; i++) Funcs::NodeWindow(windows[i], "Window"); ImGui::TreePop(); } @@ -12052,8 +12052,8 @@ void ImGui::ShowMetricsWindow(bool* opened) return; NodeDrawList(window->DrawList, "DrawList"); if (window->RootWindow != window) NodeWindow(window->RootWindow, "RootWindow"); - if (window->DC.ChildWindows.size() > 0) NodeWindows(window->DC.ChildWindows, "ChildWindows"); - ImGui::BulletText("Storage: %d bytes", window->StateStorage.Data.size() * sizeof(ImGuiStorage::Pair)); + if (window->DC.ChildWindows.Size > 0) NodeWindows(window->DC.ChildWindows, "ChildWindows"); + ImGui::BulletText("Storage: %d bytes", window->StateStorage.Data.Size * sizeof(ImGuiStorage::Pair)); ImGui::TreePop(); } }; @@ -12061,15 +12061,15 @@ void ImGui::ShowMetricsWindow(bool* opened) ImGuiState& g = *GImGui; // Access private state g.DisableHideTextAfterDoubleHash++; // Not exposed (yet). Disable processing that hides text after '##' markers. Funcs::NodeWindows(g.Windows, "Windows"); - if (ImGui::TreeNode("DrawList", "Active DrawLists (%d)", g.RenderDrawLists[0].size())) + if (ImGui::TreeNode("DrawList", "Active DrawLists (%d)", g.RenderDrawLists[0].Size)) { - for (int i = 0; i < g.RenderDrawLists[0].size(); i++) + for (int i = 0; i < g.RenderDrawLists[0].Size; i++) Funcs::NodeDrawList(g.RenderDrawLists[0][i], "DrawList"); ImGui::TreePop(); } - if (ImGui::TreeNode("Popups", "Opened Popups (%d)", g.OpenedPopupStack.size())) + if (ImGui::TreeNode("Popups", "Opened Popups (%d)", g.OpenedPopupStack.Size)) { - for (int i = 0; i < g.OpenedPopupStack.size(); i++) + for (int i = 0; i < g.OpenedPopupStack.Size; i++) ImGui::BulletText("PopupID: %08x, Window: '%s'", g.OpenedPopupStack[i].PopupID, g.OpenedPopupStack[i].Window ? g.OpenedPopupStack[i].Window->Name : "NULL"); ImGui::TreePop(); } @@ -12228,7 +12228,7 @@ static void ShowExampleAppCustomRendering(bool* opened) static ImVector points; static bool adding_line = false; if (ImGui::Button("Clear")) points.clear(); - if (points.size() >= 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) { points.pop_back(); points.pop_back(); } } + if (points.Size >= 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) { points.pop_back(); points.pop_back(); } } ImGui::Text("Left-click and drag to add lines"); ImGui::Text("Right-click to undo"); @@ -12265,7 +12265,7 @@ static void ShowExampleAppCustomRendering(bool* opened) } } draw_list->PushClipRect(ImVec4(canvas_pos.x, canvas_pos.y, canvas_pos.x+canvas_size.x, canvas_pos.y+canvas_size.y)); // clip lines within the canvas (if we resize it, etc.) - for (int i = 0; i < points.size() - 1; i += 2) + for (int i = 0; i < points.Size - 1; i += 2) draw_list->AddLine(ImVec2(canvas_pos.x + points[i].x, canvas_pos.y + points[i].y), ImVec2(canvas_pos.x + points[i+1].x, canvas_pos.y + points[i+1].y), 0xFF00FFFF); draw_list->PopClipRect(); if (adding_preview) @@ -12280,7 +12280,7 @@ struct ExampleAppConsole ImVector Items; bool ScrollToBottom; ImVector History; - int HistoryPos; // -1: new line, 0..History.size()-1 browsing history. + int HistoryPos; // -1: new line, 0..History.Size-1 browsing history. ImVector Commands; ExampleAppConsole() @@ -12295,13 +12295,13 @@ struct ExampleAppConsole ~ExampleAppConsole() { ClearLog(); - for (int i = 0; i < Items.size(); i++) + for (int i = 0; i < Items.Size; i++) free(History[i]); } void ClearLog() { - for (int i = 0; i < Items.size(); i++) + for (int i = 0; i < Items.Size; i++) free(Items[i]); Items.clear(); ScrollToBottom = true; @@ -12332,7 +12332,7 @@ struct ExampleAppConsole // TODO: display items starting from the bottom - if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.size()); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine(); + if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.Size); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine(); if (ImGui::SmallButton("Add Dummy Error")) AddLog("[error] something went wrong"); ImGui::SameLine(); if (ImGui::SmallButton("Clear")) ClearLog(); //static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); } @@ -12355,7 +12355,7 @@ struct ExampleAppConsole ImGui::EndPopup(); } ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // Tighten spacing - for (int i = 0; i < Items.size(); i++) + for (int i = 0; i < Items.Size; i++) { const char* item = Items[i]; if (!filter.PassFilter(item)) @@ -12397,7 +12397,7 @@ struct ExampleAppConsole // Insert into history. First find match and delete it so it can be pushed to the back. This isn't trying to be smart or optimal. HistoryPos = -1; - for (int i = History.size()-1; i >= 0; i--) + for (int i = History.Size-1; i >= 0; i--) if (ImStricmp(History[i], command_line) == 0) { free(History[i]); @@ -12414,12 +12414,12 @@ struct ExampleAppConsole else if (ImStricmp(command_line, "HELP") == 0) { AddLog("Commands:"); - for (int i = 0; i < Commands.size(); i++) + for (int i = 0; i < Commands.Size; i++) AddLog("- %s", Commands[i]); } else if (ImStricmp(command_line, "HISTORY") == 0) { - for (int i = History.size() >= 10 ? History.size() - 10 : 0; i < History.size(); i++) + for (int i = History.Size >= 10 ? History.Size - 10 : 0; i < History.Size; i++) AddLog("%3d: %s\n", i, History[i]); } else @@ -12456,16 +12456,16 @@ struct ExampleAppConsole // Build a list of candidates ImVector candidates; - for (int i = 0; i < Commands.size(); i++) + for (int i = 0; i < Commands.Size; i++) if (ImStrnicmp(Commands[i], word_start, (int)(word_end-word_start)) == 0) candidates.push_back(Commands[i]); - if (candidates.size() == 0) + if (candidates.Size == 0) { // No match AddLog("No match for \"%.*s\"!\n", word_end-word_start, word_start); } - else if (candidates.size() == 1) + else if (candidates.Size == 1) { // Single match. Delete the beginning of the word and replace it entirely so we've got nice casing data->DeleteChars((int)(word_start-data->Buf), (int)(word_end-word_start)); @@ -12480,7 +12480,7 @@ struct ExampleAppConsole { int c = 0; bool all_candidates_matches = true; - for (int i = 0; i < candidates.size() && all_candidates_matches; i++) + for (int i = 0; i < candidates.Size && all_candidates_matches; i++) if (i == 0) c = toupper(candidates[i][match_len]); else if (c != toupper(candidates[i][match_len])) @@ -12498,7 +12498,7 @@ struct ExampleAppConsole // List matches AddLog("Possible matches:\n"); - for (int i = 0; i < candidates.size(); i++) + for (int i = 0; i < candidates.Size; i++) AddLog("- %s\n", candidates[i]); } @@ -12511,14 +12511,14 @@ struct ExampleAppConsole if (data->EventKey == ImGuiKey_UpArrow) { if (HistoryPos == -1) - HistoryPos = History.size() - 1; + HistoryPos = History.Size - 1; else if (HistoryPos > 0) HistoryPos--; } else if (data->EventKey == ImGuiKey_DownArrow) { if (HistoryPos != -1) - if (++HistoryPos >= History.size()) + if (++HistoryPos >= History.Size) HistoryPos = -1; } diff --git a/imgui.h b/imgui.h index c0c7d6ef..5a516c0d 100644 --- a/imgui.h +++ b/imgui.h @@ -741,12 +741,11 @@ struct ImGuiIO template class ImVector { -protected: +public: int Size; int Capacity; T* Data; -public: typedef T value_type; typedef value_type* iterator; typedef const value_type* const_iterator;