1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-11 00:04:24 +00:00

ImStrv: Fixed various compile errors/warnings.

This commit is contained in:
ocornut 2022-08-22 11:06:33 +02:00 committed by ocornut
parent 932c281377
commit bd152fd872
3 changed files with 18 additions and 17 deletions

View file

@ -12207,7 +12207,7 @@ void ImGui::OpenPopup(ImStrv str_id, ImGuiPopupFlags popup_flags)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
ImGuiID id = g.CurrentWindow->GetID(str_id); ImGuiID id = g.CurrentWindow->GetID(str_id);
IMGUI_DEBUG_LOG_POPUP("[popup] OpenPopup(\"%.*s\" -> 0x%08X\n", (int)(str_id.End - str_id.Begin), str_id, id); IMGUI_DEBUG_LOG_POPUP("[popup] OpenPopup(\"%.*s\" -> 0x%08X\n", (int)(str_id.End - str_id.Begin), str_id.Begin, id);
OpenPopupEx(id, popup_flags); OpenPopupEx(id, popup_flags);
} }
@ -16172,7 +16172,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. // 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(ImStrv str) void ImGui::DebugTextEncoding(ImStrv str)
{ {
Text("Text: \"%s\"", str); Text("Text: \"%.*s\"", (int)str.length(), str.Begin);
if (!BeginTable("##DebugTextEncoding", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable)) if (!BeginTable("##DebugTextEncoding", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable))
return; return;
TableSetupColumn("Offset"); TableSetupColumn("Offset");
@ -16185,7 +16185,7 @@ void ImGui::DebugTextEncoding(ImStrv str)
unsigned int c; unsigned int c;
const int c_utf8_len = ImTextCharFromUtf8(&c, p, str.End); // As we may receive malformed UTF-8, pass an explicit end instead of relying on ImTextCharFromUtf8() assuming enough space. const int c_utf8_len = ImTextCharFromUtf8(&c, p, str.End); // As we may receive malformed UTF-8, pass an explicit end instead of relying on ImTextCharFromUtf8() assuming enough space.
TableNextColumn(); TableNextColumn();
Text("%d", (int)(size_t)(p - str)); Text("%d", (int)(p - str.Begin));
TableNextColumn(); TableNextColumn();
for (int byte_index = 0; byte_index < c_utf8_len; byte_index++) for (int byte_index = 0; byte_index < c_utf8_len; byte_index++)
{ {
@ -16194,7 +16194,7 @@ void ImGui::DebugTextEncoding(ImStrv str)
Text("0x%02X", (int)(unsigned char)p[byte_index]); Text("0x%02X", (int)(unsigned char)p[byte_index]);
} }
TableNextColumn(); TableNextColumn();
TextUnformatted(p, p + c_utf8_len); TextUnformatted(ImStrv(p, p + c_utf8_len));
if (!GetFont()->IsGlyphInFont((ImWchar)c)) if (!GetFont()->IsGlyphInFont((ImWchar)c))
{ {
SameLine(); SameLine();
@ -16384,7 +16384,7 @@ void ImGui::ShowFontAtlas(ImFontAtlas* atlas)
ImFontAtlasRect r = {}; ImFontAtlasRect r = {};
atlas->GetCustomRect(id, &r); atlas->GetCustomRect(id, &r);
ImStrv buf; ImStrv buf;
ImFormatStringToTempBuffer(&buf, NULL, "ID:%08X, used:%d, { w:%3d, h:%3d } { x:%4d, y:%4d }", id, entry.IsUsed, r.w, r.h, r.x, r.y); ImFormatStringToTempBuffer(&buf, "ID:%08X, used:%d, { w:%3d, h:%3d } { x:%4d, y:%4d }", id, entry.IsUsed, r.w, r.h, r.x, r.y);
TableNextColumn(); TableNextColumn();
Selectable(buf.Begin); Selectable(buf.Begin);
if (IsItemHovered()) if (IsItemHovered())
@ -18022,28 +18022,28 @@ void ImGui::DebugHookIdInfo(ImGuiID id, ImGuiDataType data_type, const void* dat
if (info->DescOffset == -1) if (info->DescOffset == -1)
{ {
const char* result = NULL; ImStrv result;
const char* result_end = NULL;
switch (data_type) switch (data_type)
{ {
case ImGuiDataType_S32: case ImGuiDataType_S32:
ImFormatStringToTempBuffer(&result, &result_end, "%d", (int)(intptr_t)data_id); ImFormatStringToTempBuffer(&result, "%d", (int)(intptr_t)data_id);
break; break;
case ImGuiDataType_String: case ImGuiDataType_String:
ImFormatStringToTempBuffer(&result, &result_end, "%.*s", data_id_end ? (int)((const char*)data_id_end - (const char*)data_id) : (int)ImStrlen((const char*)data_id), (const char*)data_id); ImFormatStringToTempBuffer(&result, "%.*s", data_id_end ? (int)((const char*)data_id_end - (const char*)data_id) : (int)ImStrlen((const char*)data_id), (const char*)data_id);
break; break;
case ImGuiDataType_Pointer: case ImGuiDataType_Pointer:
ImFormatStringToTempBuffer(&result, &result_end, "(void*)0x%p", data_id); ImFormatStringToTempBuffer(&result, "(void*)0x%p", data_id);
break; break;
case ImGuiDataType_ID: case ImGuiDataType_ID:
// PushOverrideID() is often used to avoid hashing twice, which would lead to 2 calls to DebugHookIdInfo(). We prioritize the first one. // PushOverrideID() is often used to avoid hashing twice, which would lead to 2 calls to DebugHookIdInfo(). We prioritize the first one.
ImFormatStringToTempBuffer(&result, &result_end, "0x%08X [override]", id); ImFormatStringToTempBuffer(&result, "0x%08X [override]", id);
break; break;
default: default:
IM_ASSERT(0); IM_ASSERT(0);
} }
info->DescOffset = query->ResultsDescBuf.size(); info->DescOffset = query->ResultsDescBuf.size();
query->ResultsDescBuf.append(result, result_end + 1); // Include zero terminator result.End++; // Include zero terminator
query->ResultsDescBuf.append(result);
} }
info->QuerySuccess = true; info->QuerySuccess = true;
if (info->DataType == -1) if (info->DataType == -1)
@ -18083,7 +18083,7 @@ static const char* DebugItemPathQuery_GetResultAsPath(ImGuiDebugItemPathQuery* q
if (c == '/') if (c == '/')
buf->append("\\"); buf->append("\\");
if (c < 256 || !hex_encode_non_ascii_chars) if (c < 256 || !hex_encode_non_ascii_chars)
buf->append(p, p_next); buf->append(ImStrv(p, p_next));
else for (; p < p_next; p++) else for (; p < p_next; p++)
buf->appendf("\\x%02x", (unsigned char)*p); buf->appendf("\\x%02x", (unsigned char)*p);
p = p_next; p = p_next;
@ -18109,6 +18109,7 @@ void ImGui::ShowIDStackToolWindow(bool* p_open)
tool->LastActiveFrame = g.FrameCount; tool->LastActiveFrame = g.FrameCount;
const char* result_path = DebugItemPathQuery_GetResultAsPath(query, tool->OptHexEncodeNonAsciiChars); const char* result_path = DebugItemPathQuery_GetResultAsPath(query, tool->OptHexEncodeNonAsciiChars);
Text("0x%08X", query->MainID); Text("0x%08X", query->MainID);
SameLine(); SameLine();
MetricsHelpMarker("Hover an item with the mouse to display elements of the ID Stack leading to the item's final ID.\nEach level of the stack correspond to a PushID() call.\nAll levels of the stack are hashed together to make the final ID of a widget (ID displayed at the bottom level of the stack).\nRead FAQ entry about the ID stack for details."); MetricsHelpMarker("Hover an item with the mouse to display elements of the ID Stack leading to the item's final ID.\nEach level of the stack correspond to a PushID() call.\nAll levels of the stack are hashed together to make the final ID of a widget (ID displayed at the bottom level of the stack).\nRead FAQ entry about the ID stack for details.");

View file

@ -3191,7 +3191,7 @@ ImFont* ImFontAtlas::AddFontFromFileTTF(ImStrv filename, float size_pixels, cons
{ {
if (font_cfg_template == NULL || (font_cfg_template->Flags & ImFontFlags_NoLoadError) == 0) if (font_cfg_template == NULL || (font_cfg_template->Flags & ImFontFlags_NoLoadError) == 0)
{ {
IMGUI_DEBUG_LOG("While loading '%s'\n", filename); IMGUI_DEBUG_LOG("While loading '%.*s'\n", filename.length(), filename.Begin);
IM_ASSERT_USER_ERROR(0, "Could not load font file!"); IM_ASSERT_USER_ERROR(0, "Could not load font file!");
} }
return NULL; return NULL;
@ -5765,7 +5765,7 @@ begin:
} }
else else
{ {
s = line_end ? line_end + 1 : text.End; s = line_end ? line_end + 1 : text_end;
} }
y += line_height; y += line_height;
} }

View file

@ -1923,7 +1923,7 @@ bool ImGui::BeginCombo(ImStrv label, ImStrv preview_value, ImGuiComboFlags flags
const float arrow_size = (flags & ImGuiComboFlags_NoArrowButton) ? 0.0f : GetFrameHeight(); const float arrow_size = (flags & ImGuiComboFlags_NoArrowButton) ? 0.0f : GetFrameHeight();
const ImVec2 label_size = CalcTextSize(label, true); const ImVec2 label_size = CalcTextSize(label, true);
const float preview_width = ((flags & ImGuiComboFlags_WidthFitPreview) && (preview_value != NULL)) ? CalcTextSize(preview_value, true).x : 0.0f; const float preview_width = ((flags & ImGuiComboFlags_WidthFitPreview) && preview_value) ? CalcTextSize(preview_value, true).x : 0.0f;
const float w = (flags & ImGuiComboFlags_NoPreview) ? arrow_size : ((flags & ImGuiComboFlags_WidthFitPreview) ? (arrow_size + preview_width + style.FramePadding.x * 2.0f) : CalcItemWidth()); const float w = (flags & ImGuiComboFlags_NoPreview) ? arrow_size : ((flags & ImGuiComboFlags_WidthFitPreview) ? (arrow_size + preview_width + style.FramePadding.x * 2.0f) : CalcItemWidth());
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y * 2.0f)); const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y * 2.0f));
const ImRect total_bb(bb.Min, bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); const ImRect total_bb(bb.Min, bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
@ -1962,7 +1962,7 @@ bool ImGui::BeginCombo(ImStrv label, ImStrv preview_value, ImGuiComboFlags flags
if (flags & ImGuiComboFlags_CustomPreview) if (flags & ImGuiComboFlags_CustomPreview)
{ {
g.ComboPreviewData.PreviewRect = ImRect(bb.Min.x, bb.Min.y, value_x2, bb.Max.y); g.ComboPreviewData.PreviewRect = ImRect(bb.Min.x, bb.Min.y, value_x2, bb.Max.y);
IM_ASSERT(!preview_value); IM_ASSERT(preview_value.empty());
} }
// Render preview and label // Render preview and label