Skip to content

Commit 5854da1

Browse files
committed
Declare other structures as constexpr (#4995) + rename ImGuiInputEventType_Char to ImGuiInputEventType_Text for consistency with event structure.
1 parent 71f98dd commit 5854da1

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

imconfig.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@
8181
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
8282
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
8383
/*
84-
#define IM_VEC2_CLASS_EXTRA \
85-
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
84+
#define IM_VEC2_CLASS_EXTRA \
85+
constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \
8686
operator MyVec2() const { return MyVec2(x,y); }
8787
88-
#define IM_VEC4_CLASS_EXTRA \
89-
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
88+
#define IM_VEC4_CLASS_EXTRA \
89+
constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \
9090
operator MyVec4() const { return MyVec4(x,y,z,w); }
9191
*/
9292

imgui.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ void ImGuiIO::AddInputCharacter(unsigned int c)
11801180
return;
11811181

11821182
ImGuiInputEvent e;
1183-
e.Type = ImGuiInputEventType_Char;
1183+
e.Type = ImGuiInputEventType_Text;
11841184
e.Source = ImGuiInputSource_Keyboard;
11851185
e.Text.Char = c;
11861186
g.InputEventsQueue.push_back(e);
@@ -7882,7 +7882,7 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs)
78827882
}
78837883
}
78847884
}
7885-
else if (e->Type == ImGuiInputEventType_Char)
7885+
else if (e->Type == ImGuiInputEventType_Text)
78867886
{
78877887
// Trickling Rule: Stop processing queued events if keys/mouse have been interacted with
78887888
if (trickle_fast_inputs && (key_changed || mouse_button_changed != 0 || mouse_moved || mouse_wheeled))

imgui_internal.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,17 +469,17 @@ IM_MSVC_RUNTIME_CHECKS_OFF
469469
struct ImVec1
470470
{
471471
float x;
472-
ImVec1() { x = 0.0f; }
473-
ImVec1(float _x) { x = _x; }
472+
constexpr ImVec1() : x(0.0f) { }
473+
constexpr ImVec1(float _x) : x(_x) { }
474474
};
475475

476476
// Helper: ImVec2ih (2D vector, half-size integer, for long-term packed storage)
477477
struct ImVec2ih
478478
{
479479
short x, y;
480-
ImVec2ih() { x = y = 0; }
481-
ImVec2ih(short _x, short _y) { x = _x; y = _y; }
482-
explicit ImVec2ih(const ImVec2& rhs) { x = (short)rhs.x; y = (short)rhs.y; }
480+
constexpr ImVec2ih() : x(0), y(0) {}
481+
constexpr ImVec2ih(short _x, short _y) : x(_x), y(_y) {}
482+
constexpr explicit ImVec2ih(const ImVec2& rhs) : x((short)rhs.x), y((short)rhs.y) {}
483483
};
484484

485485
// Helper: ImRect (2D axis aligned bounding-box)
@@ -489,10 +489,10 @@ struct IMGUI_API ImRect
489489
ImVec2 Min; // Upper-left
490490
ImVec2 Max; // Lower-right
491491

492-
ImRect() : Min(0.0f, 0.0f), Max(0.0f, 0.0f) {}
493-
ImRect(const ImVec2& min, const ImVec2& max) : Min(min), Max(max) {}
494-
ImRect(const ImVec4& v) : Min(v.x, v.y), Max(v.z, v.w) {}
495-
ImRect(float x1, float y1, float x2, float y2) : Min(x1, y1), Max(x2, y2) {}
492+
constexpr ImRect() : Min(0.0f, 0.0f), Max(0.0f, 0.0f) {}
493+
constexpr ImRect(const ImVec2& min, const ImVec2& max) : Min(min), Max(max) {}
494+
constexpr ImRect(const ImVec4& v) : Min(v.x, v.y), Max(v.z, v.w) {}
495+
constexpr ImRect(float x1, float y1, float x2, float y2) : Min(x1, y1), Max(x2, y2) {}
496496

497497
ImVec2 GetCenter() const { return ImVec2((Min.x + Max.x) * 0.5f, (Min.y + Max.y) * 0.5f); }
498498
ImVec2 GetSize() const { return ImVec2(Max.x - Min.x, Max.y - Min.y); }
@@ -1171,7 +1171,7 @@ enum ImGuiInputEventType
11711171
ImGuiInputEventType_MouseWheel,
11721172
ImGuiInputEventType_MouseButton,
11731173
ImGuiInputEventType_Key,
1174-
ImGuiInputEventType_Char,
1174+
ImGuiInputEventType_Text,
11751175
ImGuiInputEventType_Focus,
11761176
ImGuiInputEventType_COUNT
11771177
};

0 commit comments

Comments
 (0)