Misc: tweaks + fix warnings on backends withtout -wno-memaccess (#4995, #5104)

This commit is contained in:
ocornut 2022-03-13 13:15:32 +07:00
parent 0cff5ac5a1
commit fd06ed833b
20 changed files with 23 additions and 25 deletions

View File

@ -71,7 +71,7 @@ struct ImGui_ImplAllegro5_Data
ALLEGRO_VERTEX_DECL* VertexDecl; ALLEGRO_VERTEX_DECL* VertexDecl;
char* ClipboardTextData; char* ClipboardTextData;
ImGui_ImplAllegro5_Data() { memset(this, 0, sizeof(*this)); } ImGui_ImplAllegro5_Data() { memset((void*)this, 0, sizeof(*this)); }
}; };
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts // Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts

View File

@ -59,7 +59,7 @@ struct ImGui_ImplDX10_Data
int VertexBufferSize; int VertexBufferSize;
int IndexBufferSize; int IndexBufferSize;
ImGui_ImplDX10_Data() { memset(this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; } ImGui_ImplDX10_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; }
}; };
struct VERTEX_CONSTANT_BUFFER struct VERTEX_CONSTANT_BUFFER

View File

@ -60,7 +60,7 @@ struct ImGui_ImplDX11_Data
int VertexBufferSize; int VertexBufferSize;
int IndexBufferSize; int IndexBufferSize;
ImGui_ImplDX11_Data() { memset(this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; } ImGui_ImplDX11_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; }
}; };
struct VERTEX_CONSTANT_BUFFER struct VERTEX_CONSTANT_BUFFER

View File

@ -71,7 +71,7 @@ struct ImGui_ImplDX12_Data
UINT numFramesInFlight; UINT numFramesInFlight;
UINT frameIndex; UINT frameIndex;
ImGui_ImplDX12_Data() { memset(this, 0, sizeof(*this)); frameIndex = UINT_MAX; } ImGui_ImplDX12_Data() { memset((void*)this, 0, sizeof(*this)); frameIndex = UINT_MAX; }
}; };
struct VERTEX_CONSTANT_BUFFER struct VERTEX_CONSTANT_BUFFER

View File

@ -46,7 +46,7 @@ struct ImGui_ImplDX9_Data
int VertexBufferSize; int VertexBufferSize;
int IndexBufferSize; int IndexBufferSize;
ImGui_ImplDX9_Data() { memset(this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; } ImGui_ImplDX9_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; }
}; };
struct CUSTOMVERTEX struct CUSTOMVERTEX

View File

@ -105,7 +105,7 @@ struct ImGui_ImplGlfw_Data
GLFWcharfun PrevUserCallbackChar; GLFWcharfun PrevUserCallbackChar;
GLFWmonitorfun PrevUserCallbackMonitor; GLFWmonitorfun PrevUserCallbackMonitor;
ImGui_ImplGlfw_Data() { memset(this, 0, sizeof(*this)); } ImGui_ImplGlfw_Data() { memset((void*)this, 0, sizeof(*this)); }
}; };
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts // Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts

View File

@ -61,7 +61,7 @@ struct ImGui_ImplOpenGL2_Data
{ {
GLuint FontTexture; GLuint FontTexture;
ImGui_ImplOpenGL2_Data() { memset(this, 0, sizeof(*this)); } ImGui_ImplOpenGL2_Data() { memset((void*)this, 0, sizeof(*this)); }
}; };
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts // Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts

View File

@ -193,7 +193,7 @@ struct ImGui_ImplOpenGL3_Data
GLsizeiptr IndexBufferSize; GLsizeiptr IndexBufferSize;
bool HasClipOrigin; bool HasClipOrigin;
ImGui_ImplOpenGL3_Data() { memset(this, 0, sizeof(*this)); } ImGui_ImplOpenGL3_Data() { memset((void*)this, 0, sizeof(*this)); }
}; };
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts // Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts

View File

@ -87,7 +87,7 @@ struct ImGui_ImplSDL2_Data
char* ClipboardTextData; char* ClipboardTextData;
bool MouseCanUseGlobalState; bool MouseCanUseGlobalState;
ImGui_ImplSDL2_Data() { memset(this, 0, sizeof(*this)); } ImGui_ImplSDL2_Data() { memset((void*)this, 0, sizeof(*this)); }
}; };
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts // Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts

View File

@ -42,7 +42,7 @@ struct ImGui_ImplSDLRenderer_Data
{ {
SDL_Renderer* SDLRenderer; SDL_Renderer* SDLRenderer;
SDL_Texture* FontTexture; SDL_Texture* FontTexture;
ImGui_ImplSDLRenderer_Data() { memset(this, 0, sizeof(*this)); } ImGui_ImplSDLRenderer_Data() { memset((void*)this, 0, sizeof(*this)); }
}; };
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts // Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts

View File

@ -118,7 +118,7 @@ struct ImGui_ImplVulkan_Data
ImGui_ImplVulkan_Data() ImGui_ImplVulkan_Data()
{ {
memset(this, 0, sizeof(*this)); memset((void*)this, 0, sizeof(*this));
BufferMemoryAlignment = 256; BufferMemoryAlignment = 256;
} }
}; };

View File

@ -147,7 +147,7 @@ struct ImGui_ImplVulkanH_Window
ImGui_ImplVulkanH_Window() ImGui_ImplVulkanH_Window()
{ {
memset(this, 0, sizeof(*this)); memset((void*)this, 0, sizeof(*this));
PresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR; PresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR;
ClearEnable = true; ClearEnable = true;
} }

View File

@ -94,7 +94,7 @@ struct ImGui_ImplWin32_Data
PFN_XInputGetState XInputGetState; PFN_XInputGetState XInputGetState;
#endif #endif
ImGui_ImplWin32_Data() { memset(this, 0, sizeof(*this)); } ImGui_ImplWin32_Data() { memset((void*)this, 0, sizeof(*this)); }
}; };
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts // Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts

View File

@ -8069,7 +8069,6 @@ void ImGui::ErrorCheckEndFrameRecover(ImGuiErrorLogCallback log_callback, voi
IM_ASSERT(window->IsFallbackWindow); IM_ASSERT(window->IsFallbackWindow);
break; break;
} }
IM_ASSERT(window == g.CurrentWindow);
if (window->Flags & ImGuiWindowFlags_ChildWindow) if (window->Flags & ImGuiWindowFlags_ChildWindow)
{ {
if (log_callback) log_callback(user_data, "Recovered from missing EndChild() for '%s'", window->Name); if (log_callback) log_callback(user_data, "Recovered from missing EndChild() for '%s'", window->Name);

View File

@ -2342,13 +2342,13 @@ struct ImGuiListClipper
// **None of the ImGui API are using ImColor directly but you can use it as a convenience to pass colors in either ImU32 or ImVec4 formats. Explicitly cast to ImU32 or ImVec4 if needed. // **None of the ImGui API are using ImColor directly but you can use it as a convenience to pass colors in either ImU32 or ImVec4 formats. Explicitly cast to ImU32 or ImVec4 if needed.
struct ImColor struct ImColor
{ {
ImVec4 Value; ImVec4 Value;
ImColor() { Value.x = Value.y = Value.z = Value.w = 0.0f; } constexpr ImColor() { }
constexpr ImColor(float r, float g, float b, float a = 1.0f) : Value(r, g, b, a) { }
constexpr ImColor(const ImVec4& col) : Value(col) {}
ImColor(int r, int g, int b, int a = 255) { float sc = 1.0f / 255.0f; Value.x = (float)r * sc; Value.y = (float)g * sc; Value.z = (float)b * sc; Value.w = (float)a * sc; } ImColor(int r, int g, int b, int a = 255) { float sc = 1.0f / 255.0f; Value.x = (float)r * sc; Value.y = (float)g * sc; Value.z = (float)b * sc; Value.w = (float)a * sc; }
ImColor(ImU32 rgba) { float sc = 1.0f / 255.0f; Value.x = (float)((rgba >> IM_COL32_R_SHIFT) & 0xFF) * sc; Value.y = (float)((rgba >> IM_COL32_G_SHIFT) & 0xFF) * sc; Value.z = (float)((rgba >> IM_COL32_B_SHIFT) & 0xFF) * sc; Value.w = (float)((rgba >> IM_COL32_A_SHIFT) & 0xFF) * sc; } ImColor(ImU32 rgba) { float sc = 1.0f / 255.0f; Value.x = (float)((rgba >> IM_COL32_R_SHIFT) & 0xFF) * sc; Value.y = (float)((rgba >> IM_COL32_G_SHIFT) & 0xFF) * sc; Value.z = (float)((rgba >> IM_COL32_B_SHIFT) & 0xFF) * sc; Value.w = (float)((rgba >> IM_COL32_A_SHIFT) & 0xFF) * sc; }
ImColor(float r, float g, float b, float a = 1.0f) { Value.x = r; Value.y = g; Value.z = b; Value.w = a; }
ImColor(const ImVec4& col) { Value = col; }
inline operator ImU32() const { return ImGui::ColorConvertFloat4ToU32(Value); } inline operator ImU32() const { return ImGui::ColorConvertFloat4ToU32(Value); }
inline operator ImVec4() const { return Value; } inline operator ImVec4() const { return Value; }

View File

@ -3873,7 +3873,7 @@ static void ShowDemoWindowTables()
sprintf(buf, "Hello %d,%d", column, row); sprintf(buf, "Hello %d,%d", column, row);
if (contents_type == CT_Text) if (contents_type == CT_Text)
ImGui::TextUnformatted(buf); ImGui::TextUnformatted(buf);
else if (contents_type) else if (contents_type == CT_FillButton)
ImGui::Button(buf, ImVec2(-FLT_MIN, 0.0f)); ImGui::Button(buf, ImVec2(-FLT_MIN, 0.0f));
} }
} }

View File

@ -3878,7 +3878,7 @@ void ImGui::RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, Im
draw_list->PathFillConvex(col); draw_list->PathFillConvex(col);
} }
void ImGui::RenderRectFilledWithHole(ImDrawList* draw_list, ImRect outer, ImRect inner, ImU32 col, float rounding) void ImGui::RenderRectFilledWithHole(ImDrawList* draw_list, const ImRect& outer, const ImRect& inner, ImU32 col, float rounding)
{ {
const bool fill_L = (inner.Min.x > outer.Min.x); const bool fill_L = (inner.Min.x > outer.Min.x);
const bool fill_R = (inner.Max.x < outer.Max.x); const bool fill_R = (inner.Max.x < outer.Max.x);

View File

@ -232,7 +232,7 @@ namespace ImStb
#define IM_NEWLINE "\n" #define IM_NEWLINE "\n"
#endif #endif
#define IM_TABSIZE (4) #define IM_TABSIZE (4)
#define IM_MEMALIGN(_OFF,_ALIGN) (((_OFF) + (_ALIGN - 1)) & ~(_ALIGN - 1)) // Memory align e.g. IM_ALIGN(0,4)=0, IM_ALIGN(1,4)=4, IM_ALIGN(4,4)=4, IM_ALIGN(5,4)=8 #define IM_MEMALIGN(_OFF,_ALIGN) (((_OFF) + ((_ALIGN) - 1)) & ~((_ALIGN) - 1)) // Memory align e.g. IM_ALIGN(0,4)=0, IM_ALIGN(1,4)=4, IM_ALIGN(4,4)=4, IM_ALIGN(5,4)=8
#define IM_F32_TO_INT8_UNBOUND(_VAL) ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f))) // Unsaturated, for display purpose #define IM_F32_TO_INT8_UNBOUND(_VAL) ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f))) // Unsaturated, for display purpose
#define IM_F32_TO_INT8_SAT(_VAL) ((int)(ImSaturate(_VAL) * 255.0f + 0.5f)) // Saturated, always output 0..255 #define IM_F32_TO_INT8_SAT(_VAL) ((int)(ImSaturate(_VAL) * 255.0f + 0.5f)) // Saturated, always output 0..255
#define IM_FLOOR(_VAL) ((float)(int)(_VAL)) // ImFloor() is not inlined in MSVC debug builds #define IM_FLOOR(_VAL) ((float)(int)(_VAL)) // ImFloor() is not inlined in MSVC debug builds
@ -2782,7 +2782,7 @@ namespace ImGui
IMGUI_API void RenderCheckMark(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float sz); IMGUI_API void RenderCheckMark(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float sz);
IMGUI_API void RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col); IMGUI_API void RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col);
IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding); IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding);
IMGUI_API void RenderRectFilledWithHole(ImDrawList* draw_list, ImRect outer, ImRect inner, ImU32 col, float rounding); IMGUI_API void RenderRectFilledWithHole(ImDrawList* draw_list, const ImRect& outer, const ImRect& inner, ImU32 col, float rounding);
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
// [1.71: 2019/06/07: Updating prototypes of some of the internal functions. Leaving those for reference for a short while] // [1.71: 2019/06/07: Updating prototypes of some of the internal functions. Leaving those for reference for a short while]

View File

@ -843,9 +843,8 @@ bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos)
// Render // Render
ImU32 bg_col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); ImU32 bg_col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
ImU32 text_col = GetColorU32(ImGuiCol_Text); ImU32 text_col = GetColorU32(ImGuiCol_Text);
ImVec2 center = bb.GetCenter();
if (hovered || held) if (hovered || held)
window->DrawList->AddCircleFilled(center/*+ ImVec2(0.0f, -0.5f)*/, g.FontSize * 0.5f + 1.0f, bg_col, 12); window->DrawList->AddCircleFilled(bb.GetCenter()/*+ ImVec2(0.0f, -0.5f)*/, g.FontSize * 0.5f + 1.0f, bg_col, 12);
RenderArrow(window->DrawList, bb.Min + g.Style.FramePadding, text_col, window->Collapsed ? ImGuiDir_Right : ImGuiDir_Down, 1.0f); RenderArrow(window->DrawList, bb.Min + g.Style.FramePadding, text_col, window->Collapsed ? ImGuiDir_Right : ImGuiDir_Down, 1.0f);
// Switch to moving the window after mouse is moved beyond the initial drag threshold // Switch to moving the window after mouse is moved beyond the initial drag threshold

View File

@ -368,7 +368,7 @@ struct ImFontBuildSrcGlyphFT
uint32_t Codepoint; uint32_t Codepoint;
unsigned int* BitmapData; // Point within one of the dst_tmp_bitmap_buffers[] array unsigned int* BitmapData; // Point within one of the dst_tmp_bitmap_buffers[] array
ImFontBuildSrcGlyphFT() { memset(this, 0, sizeof(*this)); } ImFontBuildSrcGlyphFT() { memset((void*)this, 0, sizeof(*this)); }
}; };
struct ImFontBuildSrcDataFT struct ImFontBuildSrcDataFT