ImStrv: Step 1 - change string type to ImStrv in API. (REBASED)

(last rebase amend 2024/12/11)
This commit is contained in:
Rokas Kupstys
2020-07-14 14:14:17 +03:00
committed by ocornut
parent 1c87024840
commit fe8f6d89ed
7 changed files with 337 additions and 336 deletions

View File

@@ -1252,7 +1252,7 @@ static const ImVec2 TOOLTIP_DEFAULT_PIVOT_TOUCH = ImVec2(0.5f, 1.0f); // Multi
//-------------------------------------------------------------------------
static void SetCurrentWindow(ImGuiWindow* window);
static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags);
static ImGuiWindow* CreateNewWindow(ImStrv name, ImGuiWindowFlags flags);
static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window);
static void AddWindowToSortBuffer(ImVector<ImGuiWindow*>* out_sorted_windows, ImGuiWindow* window);
@@ -1325,7 +1325,7 @@ static void UpdateSettings();
static int UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_hovered, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect);
static void RenderWindowOuterBorders(ImGuiWindow* window);
static void RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, bool handle_borders_and_resize_grips, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size);
static void RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open);
static void RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, ImStrv name, bool* p_open);
static void RenderDimmedBackgroundBehindWindow(ImGuiWindow* window, ImU32 col);
static void RenderDimmedBackgrounds();
static void SetLastItemDataForWindow(ImGuiWindow* window, const ImRect& rect);
@@ -2405,7 +2405,7 @@ const char* ImHashSkipUncontributingPrefix(const char* label)
// Default file functions
#ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS
ImFileHandle ImFileOpen(const char* filename, const char* mode)
ImFileHandle ImFileOpen(ImStrv filename, ImStrv mode)
{
#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && (defined(__MINGW32__) || (!defined(__CYGWIN__) && !defined(__GNUC__)))
// We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames.
@@ -2439,7 +2439,7 @@ ImU64 ImFileWrite(const void* data, ImU64 sz, ImU64 count, ImFileHandle f)
// Helper: Load file content into memory
// Memory allocated with IM_ALLOC(), must be freed by user using IM_FREE() == ImGui::MemFree()
// This can't really be used with "rt" because fseek size won't match read size.
void* ImFileLoadToMemory(const char* filename, const char* mode, size_t* out_file_size, int padding_bytes)
void* ImFileLoadToMemory(ImStrv filename, ImStrv mode, size_t* out_file_size, int padding_bytes)
{
IM_ASSERT(filename && mode);
if (out_file_size)
@@ -2913,7 +2913,7 @@ IM_MSVC_RUNTIME_CHECKS_RESTORE
//-----------------------------------------------------------------------------
// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
ImGuiTextFilter::ImGuiTextFilter(const char* default_filter) //-V1077
ImGuiTextFilter::ImGuiTextFilter(ImStrv default_filter) //-V1077
{
InputBuf[0] = 0;
CountGrep = 0;
@@ -2924,7 +2924,7 @@ ImGuiTextFilter::ImGuiTextFilter(const char* default_filter) //-V1077
}
}
bool ImGuiTextFilter::Draw(const char* label, float width)
bool ImGuiTextFilter::Draw(ImStrv label, float width)
{
if (width != 0.0f)
ImGui::SetNextItemWidth(width);
@@ -4439,7 +4439,7 @@ void ImGui::CallContextHooks(ImGuiContext* ctx, ImGuiContextHookType hook_type)
//-----------------------------------------------------------------------------
// ImGuiWindow is mostly a dumb struct. It merely has a constructor and a few helper methods
ImGuiWindow::ImGuiWindow(ImGuiContext* ctx, const char* name) : DrawListInst(NULL)
ImGuiWindow::ImGuiWindow(ImGuiContext* ctx, ImStrv name) : DrawListInst(NULL)
{
memset(this, 0, sizeof(*this));
Ctx = ctx;
@@ -4996,7 +4996,7 @@ const char* ImGui::GetClipboardText()
return g.PlatformIO.Platform_GetClipboardTextFn ? g.PlatformIO.Platform_GetClipboardTextFn(&g) : "";
}
void ImGui::SetClipboardText(const char* text)
void ImGui::SetClipboardText(ImStrv text)
{
ImGuiContext& g = *GImGui;
if (g.PlatformIO.Platform_SetClipboardTextFn != NULL)
@@ -6236,9 +6236,9 @@ ImVec2 ImGui::GetItemRectSize()
return g.LastItemData.Rect.GetSize();
}
// Prior to v1.90 2023/10/16, the BeginChild() function took a 'bool border = false' parameter instead of 'ImGuiChildFlags child_flags = 0'.
// Prior to v1.90 2023/10/16, the BeginChild() function took a 'bool borders = false' parameter instead of 'ImGuiChildFlags child_flags = 0'.
// ImGuiChildFlags_Borders is defined as always == 1 in order to allow old code passing 'true'. Read comments in imgui.h for details!
bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, ImGuiChildFlags child_flags, ImGuiWindowFlags window_flags)
bool ImGui::BeginChild(ImStrv str_id, const ImVec2& size_arg, ImGuiChildFlags child_flags, ImGuiWindowFlags window_flags)
{
ImGuiID id = GetCurrentWindow()->GetID(str_id);
return BeginChildEx(str_id, id, size_arg, child_flags, window_flags);
@@ -6249,7 +6249,7 @@ bool ImGui::BeginChild(ImGuiID id, const ImVec2& size_arg, ImGuiChildFlags child
return BeginChildEx(NULL, id, size_arg, child_flags, window_flags);
}
bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, ImGuiChildFlags child_flags, ImGuiWindowFlags window_flags)
bool ImGui::BeginChildEx(ImStrv name, ImGuiID id, const ImVec2& size_arg, ImGuiChildFlags child_flags, ImGuiWindowFlags window_flags)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* parent_window = g.CurrentWindow;
@@ -6442,7 +6442,7 @@ ImGuiWindow* ImGui::FindWindowByID(ImGuiID id)
return (ImGuiWindow*)g.WindowsById.GetVoidPtr(id);
}
ImGuiWindow* ImGui::FindWindowByName(const char* name)
ImGuiWindow* ImGui::FindWindowByName(ImStrv name)
{
ImGuiID id = ImHashStr(name);
return FindWindowByID(id);
@@ -6487,7 +6487,7 @@ static void InitOrLoadWindowSettings(ImGuiWindow* window, ImGuiWindowSettings* s
}
}
static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags)
static ImGuiWindow* CreateNewWindow(ImStrv name, ImGuiWindowFlags flags)
{
// Create window the first time
//IMGUI_DEBUG_LOG("CreateNewWindow '%s', flags = 0x%08X\n", name, flags);
@@ -7083,7 +7083,7 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar
}
// Render title text, collapse button, close button
void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open)
void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, ImStrv name, bool* p_open)
{
ImGuiContext& g = *GImGui;
ImGuiStyle& style = g.Style;
@@ -7237,7 +7237,7 @@ static void SetWindowActiveForSkipRefresh(ImGuiWindow* window)
// You can use the "##" or "###" markers to use the same label with different id, or same id with different label. See documentation at the top of this file.
// - Return false when window is collapsed, so you can early out in your code. You always need to call ImGui::End() even if false is returned.
// - Passing 'bool* p_open' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed.
bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
bool ImGui::Begin(ImStrv name, bool* p_open, ImGuiWindowFlags flags)
{
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
@@ -8348,7 +8348,7 @@ void ImGui::SetWindowPos(const ImVec2& pos, ImGuiCond cond)
SetWindowPos(window, pos, cond);
}
void ImGui::SetWindowPos(const char* name, const ImVec2& pos, ImGuiCond cond)
void ImGui::SetWindowPos(ImStrv name, const ImVec2& pos, ImGuiCond cond)
{
if (ImGuiWindow* window = FindWindowByName(name))
SetWindowPos(window, pos, cond);
@@ -8394,7 +8394,7 @@ void ImGui::SetWindowSize(const ImVec2& size, ImGuiCond cond)
SetWindowSize(GImGui->CurrentWindow, size, cond);
}
void ImGui::SetWindowSize(const char* name, const ImVec2& size, ImGuiCond cond)
void ImGui::SetWindowSize(ImStrv name, const ImVec2& size, ImGuiCond cond)
{
if (ImGuiWindow* window = FindWindowByName(name))
SetWindowSize(window, size, cond);
@@ -8443,7 +8443,7 @@ bool ImGui::IsWindowAppearing()
return window->Appearing;
}
void ImGui::SetWindowCollapsed(const char* name, bool collapsed, ImGuiCond cond)
void ImGui::SetWindowCollapsed(ImStrv name, bool collapsed, ImGuiCond cond)
{
if (ImGuiWindow* window = FindWindowByName(name))
SetWindowCollapsed(window, collapsed, cond);
@@ -9037,7 +9037,7 @@ ImGuiID ImGuiWindow::GetIDFromRectangle(const ImRect& r_abs)
return id;
}
void ImGui::PushID(const char* str_id)
void ImGui::PushID(ImStrv str_id)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
@@ -9117,7 +9117,7 @@ void ImGui::PopID()
window->IDStack.pop_back();
}
ImGuiID ImGui::GetID(const char* str_id)
ImGuiID ImGui::GetID(ImStrv str_id)
{
ImGuiWindow* window = GImGui->CurrentWindow;
return window->GetID(str_id);
@@ -10617,7 +10617,7 @@ bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags, ImGuiID own
// Which is why it is required you put them in your imconfig file (and NOT only before including imgui.h).
// Otherwise it is possible that different compilation units would see different structure layout.
// If you don't want to modify imconfig.h you can use the IMGUI_USER_CONFIG define to change filename.
bool ImGui::DebugCheckVersionAndDataLayout(const char* version, size_t sz_io, size_t sz_style, size_t sz_vec2, size_t sz_vec4, size_t sz_vert, size_t sz_idx)
bool ImGui::DebugCheckVersionAndDataLayout(ImStrv version, size_t sz_io, size_t sz_style, size_t sz_vec2, size_t sz_vec4, size_t sz_vert, size_t sz_idx)
{
bool error = false;
if (strcmp(version, IMGUI_VERSION) != 0) { error = true; IM_ASSERT(strcmp(version, IMGUI_VERSION) == 0 && "Mismatched version string!"); }
@@ -11953,7 +11953,7 @@ bool ImGui::IsPopupOpen(ImGuiID id, ImGuiPopupFlags popup_flags)
}
}
bool ImGui::IsPopupOpen(const char* str_id, ImGuiPopupFlags popup_flags)
bool ImGui::IsPopupOpen(ImStrv str_id, ImGuiPopupFlags popup_flags)
{
ImGuiContext& g = *GImGui;
ImGuiID id = (popup_flags & ImGuiPopupFlags_AnyPopupId) ? 0 : g.CurrentWindow->GetID(str_id);
@@ -11984,7 +11984,6 @@ ImGuiWindow* ImGui::GetTopMostAndVisiblePopupModal()
return NULL;
}
// When a modal popup is open, newly created windows that want focus (i.e. are not popups and do not specify ImGuiWindowFlags_NoFocusOnAppearing)
// should be positioned behind that modal window, unless the window was created inside the modal begin-stack.
// In case of multiple stacked modals newly created window honors begin stack order and does not go below its own modal parent.
@@ -12021,7 +12020,7 @@ ImGuiWindow* ImGui::FindBlockingModal(ImGuiWindow* window)
return NULL;
}
void ImGui::OpenPopup(const char* str_id, ImGuiPopupFlags popup_flags)
void ImGui::OpenPopup(ImStrv str_id, ImGuiPopupFlags popup_flags)
{
ImGuiContext& g = *GImGui;
ImGuiID id = g.CurrentWindow->GetID(str_id);
@@ -12231,7 +12230,7 @@ bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_window_flags)
return is_open;
}
bool ImGui::BeginPopupMenuEx(ImGuiID id, const char* label, ImGuiWindowFlags extra_window_flags)
bool ImGui::BeginPopupMenuEx(ImGuiID id, ImStrv label, ImGuiWindowFlags extra_window_flags)
{
ImGuiContext& g = *GImGui;
if (!IsPopupOpen(id, ImGuiPopupFlags_None))
@@ -12250,7 +12249,7 @@ bool ImGui::BeginPopupMenuEx(ImGuiID id, const char* label, ImGuiWindowFlags ext
return is_open;
}
bool ImGui::BeginPopup(const char* str_id, ImGuiWindowFlags flags)
bool ImGui::BeginPopup(ImStrv str_id, ImGuiWindowFlags flags)
{
ImGuiContext& g = *GImGui;
if (g.OpenPopupStack.Size <= g.BeginPopupStack.Size) // Early out for performance
@@ -12267,7 +12266,7 @@ bool ImGui::BeginPopup(const char* str_id, ImGuiWindowFlags flags)
// Note that popup visibility status is owned by Dear ImGui (and manipulated with e.g. OpenPopup).
// - *p_open set back to false in BeginPopupModal() when popup is not open.
// - if you set *p_open to false before calling BeginPopupModal(), it will close the popup.
bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags flags)
bool ImGui::BeginPopupModal(ImStrv name, bool* p_open, ImGuiWindowFlags flags)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
@@ -12325,7 +12324,7 @@ void ImGui::EndPopup()
// Helper to open a popup if mouse button is released over the item
// - This is essentially the same as BeginPopupContextItem() but without the trailing BeginPopup()
void ImGui::OpenPopupOnItemClick(const char* str_id, ImGuiPopupFlags popup_flags)
void ImGui::OpenPopupOnItemClick(ImStrv str_id, ImGuiPopupFlags popup_flags)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
@@ -12354,7 +12353,7 @@ void ImGui::OpenPopupOnItemClick(const char* str_id, ImGuiPopupFlags popup_flags
// OpenPopup(id);
// return BeginPopup(id);
// The main difference being that this is tweaked to avoid computing the ID twice.
bool ImGui::BeginPopupContextItem(const char* str_id, ImGuiPopupFlags popup_flags)
bool ImGui::BeginPopupContextItem(ImStrv str_id, ImGuiPopupFlags popup_flags)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
@@ -12368,7 +12367,7 @@ bool ImGui::BeginPopupContextItem(const char* str_id, ImGuiPopupFlags popup_flag
return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings);
}
bool ImGui::BeginPopupContextWindow(const char* str_id, ImGuiPopupFlags popup_flags)
bool ImGui::BeginPopupContextWindow(ImStrv str_id, ImGuiPopupFlags popup_flags)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
@@ -12382,7 +12381,7 @@ bool ImGui::BeginPopupContextWindow(const char* str_id, ImGuiPopupFlags popup_fl
return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings);
}
bool ImGui::BeginPopupContextVoid(const char* str_id, ImGuiPopupFlags popup_flags)
bool ImGui::BeginPopupContextVoid(ImStrv str_id, ImGuiPopupFlags popup_flags)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
@@ -12563,7 +12562,7 @@ void ImGui::SetWindowFocus()
FocusWindow(GImGui->CurrentWindow);
}
void ImGui::SetWindowFocus(const char* name)
void ImGui::SetWindowFocus(ImStrv name)
{
if (name)
{
@@ -14653,7 +14652,7 @@ void ImGui::EndDragDropSource()
}
// Use 'cond' to choose to submit payload on drag start or every frame
bool ImGui::SetDragDropPayload(const char* type, const void* data, size_t data_size, ImGuiCond cond)
bool ImGui::SetDragDropPayload(ImStrv type, const void* data, size_t data_size, ImGuiCond cond)
{
ImGuiContext& g = *GImGui;
ImGuiPayload& payload = g.DragDropPayload;
@@ -14762,7 +14761,7 @@ bool ImGui::IsDragDropPayloadBeingAccepted()
return g.DragDropActive && g.DragDropAcceptIdPrev != 0;
}
const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags)
const ImGuiPayload* ImGui::AcceptDragDropPayload(ImStrv type, ImGuiDragDropFlags flags)
{
ImGuiContext& g = *GImGui;
ImGuiPayload& payload = g.DragDropPayload;
@@ -14981,7 +14980,7 @@ void ImGui::LogToTTY(int auto_open_depth)
}
// Start logging/capturing text output to given file
void ImGui::LogToFile(int auto_open_depth, const char* filename)
void ImGui::LogToFile(int auto_open_depth, ImStrv filename)
{
ImGuiContext& g = *GImGui;
if (g.LogEnabled)
@@ -15154,14 +15153,14 @@ void ImGui::AddSettingsHandler(const ImGuiSettingsHandler* handler)
g.SettingsHandlers.push_back(*handler);
}
void ImGui::RemoveSettingsHandler(const char* type_name)
void ImGui::RemoveSettingsHandler(ImStrv type_name)
{
ImGuiContext& g = *GImGui;
if (ImGuiSettingsHandler* handler = FindSettingsHandler(type_name))
g.SettingsHandlers.erase(handler);
}
ImGuiSettingsHandler* ImGui::FindSettingsHandler(const char* type_name)
ImGuiSettingsHandler* ImGui::FindSettingsHandler(ImStrv type_name)
{
ImGuiContext& g = *GImGui;
const ImGuiID type_hash = ImHashStr(type_name);
@@ -15181,7 +15180,7 @@ void ImGui::ClearIniSettings()
handler.ClearAllFn(&g, &handler);
}
void ImGui::LoadIniSettingsFromDisk(const char* ini_filename)
void ImGui::LoadIniSettingsFromDisk(ImStrv ini_filename)
{
size_t file_data_size = 0;
char* file_data = (char*)ImFileLoadToMemory(ini_filename, "rb", &file_data_size);
@@ -15194,7 +15193,7 @@ void ImGui::LoadIniSettingsFromDisk(const char* ini_filename)
// Zero-tolerance, no error reporting, cheap .ini parsing
// Set ini_size==0 to let us use strlen(ini_data). Do not call this function with a 0 if your buffer is actually empty!
void ImGui::LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size)
void ImGui::LoadIniSettingsFromMemory(ImStrv ini_data, size_t ini_size)
{
ImGuiContext& g = *GImGui;
IM_ASSERT(g.Initialized);
@@ -15264,7 +15263,7 @@ void ImGui::LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size)
handler.ApplyAllFn(&g, &handler);
}
void ImGui::SaveIniSettingsToDisk(const char* ini_filename)
void ImGui::SaveIniSettingsToDisk(ImStrv ini_filename)
{
ImGuiContext& g = *GImGui;
g.SettingsDirtyTimer = 0.0f;
@@ -15294,7 +15293,7 @@ const char* ImGui::SaveIniSettingsToMemory(size_t* out_size)
return g.SettingsIniData.c_str();
}
ImGuiWindowSettings* ImGui::CreateNewWindowSettings(const char* name)
ImGuiWindowSettings* ImGui::CreateNewWindowSettings(ImStrv name)
{
ImGuiContext& g = *GImGui;
@@ -15334,7 +15333,7 @@ ImGuiWindowSettings* ImGui::FindWindowSettingsByWindow(ImGuiWindow* window)
}
// This will revert window to its initial state, including enabling the ImGuiCond_FirstUseEver/ImGuiCond_Once conditions once more.
void ImGui::ClearWindowSettings(const char* name)
void ImGui::ClearWindowSettings(ImStrv name)
{
//IMGUI_DEBUG_LOG("ClearWindowSettings('%s')\n", name);
ImGuiWindow* window = FindWindowByName(name);
@@ -15919,7 +15918,7 @@ void ImGui::DebugRenderKeyboardPreview(ImDrawList* draw_list)
}
// Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct.
void ImGui::DebugTextEncoding(const char* str)
void ImGui::DebugTextEncoding(ImStrv str)
{
Text("Text: \"%s\"", str);
if (!BeginTable("##DebugTextEncoding", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable))
@@ -17916,7 +17915,7 @@ void ImGui::DebugHookIdInfo(ImGuiID, ImGuiDataType, const void*, const void*) {}
#if !defined(IMGUI_DISABLE_DEMO_WINDOWS) || !defined(IMGUI_DISABLE_DEBUG_TOOLS)
// Demo helper function to select among loaded fonts.
// Here we use the regular BeginCombo()/EndCombo() api which is the more flexible one.
void ImGui::ShowFontSelector(const char* label)
void ImGui::ShowFontSelector(ImStrv label)
{
ImGuiIO& io = GetIO();
ImFont* font_current = GetFont();