Repository: wpilibsuite/allwpilib
Pull request #7899: Set IMGUI_DEFINE_MATH_OPERATORS
Author: login: spacey-sooty
Labels: name: component: cscore
description: CameraServer library
name: component: glass
description: Glass app and backend
name: component: datalogtool
description: DataLog Tool
Created: 2025-04-11T03:22:04Z | Merged: 2025-04-29T14:44:17Z



Diff:
diff --git a/cscore/.styleguide b/cscore/.styleguide
index e82e06430ea..2737ace2a78 100644
--- a/cscore/.styleguide
+++ b/cscore/.styleguide
@@ -38,8 +38,10 @@ includeOtherLibs {
   ^fmt/
   ^gtest/
   ^opencv2/
+  ^imgui
   ^support/
   ^tcpsockets/
   ^wpi/
+  ^wpigui
   ^wpinet/
 }
diff --git a/cscore/examples/usbviewer/usbviewer.cpp b/cscore/examples/usbviewer/usbviewer.cpp
index 4653c516cd4..cfb9aea9286 100644
--- a/cscore/examples/usbviewer/usbviewer.cpp
+++ b/cscore/examples/usbviewer/usbviewer.cpp
@@ -6,7 +6,6 @@
 #include <thread>
 #include <vector>
 
-#define IMGUI_DEFINE_MATH_OPERATORS
 #include <imgui.h>
 #include <imgui_internal.h>
 #include <opencv2/core/core.hpp>
diff --git a/datalogtool/src/main/native/cpp/App.cpp b/datalogtool/src/main/native/cpp/App.cpp
index 31512a0bd12..ee0d893d45b 100644
--- a/datalogtool/src/main/native/cpp/App.cpp
+++ b/datalogtool/src/main/native/cpp/App.cpp
@@ -10,11 +10,9 @@
 #include <glass/Context.h>
 #include <glass/MainMenuBar.h>
 #include <glass/Storage.h>
-#include <libssh/libssh.h>
-
-#define IMGUI_DEFINE_MATH_OPERATORS
 #include <imgui.h>
 #include <imgui_internal.h>
+#include <libssh/libssh.h>
 #include <wpigui.h>
 #include <wpigui_openurl.h>
 
diff --git a/datalogtool/src/main/native/cpp/App.h b/datalogtool/src/main/native/cpp/App.h
index a9978daf30a..9d1520c8a0a 100644
--- a/datalogtool/src/main/native/cpp/App.h
+++ b/datalogtool/src/main/native/cpp/App.h
@@ -4,7 +4,6 @@
 
 #pragma once
 
-#define IMGUI_DEFINE_MATH_OPERATORS
 #include <imgui.h>
 
 void SetNextWindowPos(const ImVec2& pos, ImGuiCond cond = 0,
diff --git a/glass/.styleguide b/glass/.styleguide
index 148c63451e0..e1943a80e7d 100644
--- a/glass/.styleguide
+++ b/glass/.styleguide
@@ -26,8 +26,10 @@ includeOtherLibs {
   ^frc/
   ^google/
   ^imgui
+  portable-file-dialogs.h
   ^networktables/
   ^ntcore
+  ^units
   ^wpi/
   ^wpigui
   ^wpimath/
diff --git a/glass/src/lib/native/cpp/hardware/Gyro.cpp b/glass/src/lib/native/cpp/hardware/Gyro.cpp
index 8ba5d5e1dd0..cfc6e79855e 100644
--- a/glass/src/lib/native/cpp/hardware/Gyro.cpp
+++ b/glass/src/lib/native/cpp/hardware/Gyro.cpp
@@ -7,8 +7,6 @@
 #include <cmath>
 #include <numbers>
 
-#define IMGUI_DEFINE_MATH_OPERATORS
-
 #include <imgui.h>
 #include <imgui_internal.h>
 #include <wpi/StringExtras.h>
diff --git a/glass/src/lib/native/cpp/other/Drive.cpp b/glass/src/lib/native/cpp/other/Drive.cpp
index d54b2da825b..1467408cf87 100644
--- a/glass/src/lib/native/cpp/other/Drive.cpp
+++ b/glass/src/lib/native/cpp/other/Drive.cpp
@@ -6,12 +6,10 @@
 
 #include <array>
 #include <cmath>
-
-#define IMGUI_DEFINE_MATH_OPERATORS
+#include <numbers>
 
 #include <imgui.h>
 #include <imgui_internal.h>
-#include <numbers>
 
 #include "glass/Context.h"
 #include "glass/DataSource.h"
diff --git a/glass/src/lib/native/cpp/other/Field2D.cpp b/glass/src/lib/native/cpp/other/Field2D.cpp
index c4f61b3c404..4c86aa33cbe 100644
--- a/glass/src/lib/native/cpp/other/Field2D.cpp
+++ b/glass/src/lib/native/cpp/other/Field2D.cpp
@@ -17,8 +17,6 @@
 #include <frc/geometry/Pose2d.h>
 #include <frc/geometry/Rotation2d.h>
 #include <frc/geometry/Translation2d.h>
-
-#define IMGUI_DEFINE_MATH_OPERATORS
 #include <imgui.h>
 #include <imgui_internal.h>
 #include <imgui_stdlib.h>
diff --git a/glass/src/lib/native/cpp/other/Mechanism2D.cpp b/glass/src/lib/native/cpp/other/Mechanism2D.cpp
index b09acf81d30..ce4384f79a9 100644
--- a/glass/src/lib/native/cpp/other/Mechanism2D.cpp
+++ b/glass/src/lib/native/cpp/other/Mechanism2D.cpp
@@ -17,8 +17,6 @@
 #include <frc/geometry/Rotation2d.h>
 #include <frc/geometry/Transform2d.h>
 #include <frc/geometry/Translation2d.h>
-
-#define IMGUI_DEFINE_MATH_OPERATORS
 #include <imgui.h>
 #include <imgui_internal.h>
 #include <imgui_stdlib.h>
diff --git a/glass/src/lib/native/cpp/other/Plot.cpp b/glass/src/lib/native/cpp/other/Plot.cpp
index 56fc04d099d..e3f658e37bc 100644
--- a/glass/src/lib/native/cpp/other/Plot.cpp
+++ b/glass/src/lib/native/cpp/other/Plot.cpp
@@ -22,7 +22,6 @@
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
 #endif
 
-#define IMGUI_DEFINE_MATH_OPERATORS
 #include <imgui.h>
 #include <imgui_stdlib.h>
 #include <implot.h>
diff --git a/glass/src/lib/native/cpp/support/ExtraGuiWidgets.cpp b/glass/src/lib/native/cpp/support/ExtraGuiWidgets.cpp
index 0b0aae3eaaf..cf66558e0bc 100644
--- a/glass/src/lib/native/cpp/support/ExtraGuiWidgets.cpp
+++ b/glass/src/lib/native/cpp/support/ExtraGuiWidgets.cpp
@@ -4,14 +4,12 @@
 
 #include "glass/support/ExtraGuiWidgets.h"
 
-#define IMGUI_DEFINE_MATH_OPERATORS
-#include <imgui.h>
-#include <imgui_internal.h>
-
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 
+#include <imgui.h>
+#include <imgui_internal.h>
 #include <wpi/DenseMap.h>
 
 #include "glass/DataSource.h"
diff --git a/glass/src/lib/native/include/glass/MainMenuBar.h b/glass/src/lib/native/include/glass/MainMenuBar.h
index 914153636ef..048ab9b9eff 100644
--- a/glass/src/lib/native/include/glass/MainMenuBar.h
+++ b/glass/src/lib/native/include/glass/MainMenuBar.h
@@ -4,12 +4,12 @@
 
 #pragma once
 
-#include <portable-file-dialogs.h>
-
 #include <functional>
 #include <memory>
 #include <vector>
 
+#include <portable-file-dialogs.h>
+
 namespace glass {
 
 /**
diff --git a/glass/src/lib/native/include/glass/Window.h b/glass/src/lib/native/include/glass/Window.h
index 62b369cdd45..0a37f9ae88e 100644
--- a/glass/src/lib/native/include/glass/Window.h
+++ b/glass/src/lib/native/include/glass/Window.h
@@ -9,7 +9,6 @@
 #include <string_view>
 #include <utility>
 
-#define IMGUI_DEFINE_MATH_OPERATORS
 #include <imgui.h>
 
 #include "glass/View.h"
diff --git a/glass/src/lib/native/include/glass/other/Field2D.h b/glass/src/lib/native/include/glass/other/Field2D.h
index 2b0f9a8ef0b..9c9f72ae6f8 100644
--- a/glass/src/lib/native/include/glass/other/Field2D.h
+++ b/glass/src/lib/native/include/glass/other/Field2D.h
@@ -10,8 +10,6 @@
 #include <frc/geometry/Pose2d.h>
 #include <frc/geometry/Rotation2d.h>
 #include <frc/geometry/Translation2d.h>
-
-#define IMGUI_DEFINE_MATH_OPERATORS
 #include <imgui.h>
 #include <wpi/function_ref.h>
 
diff --git a/glass/src/lib/native/include/glass/other/Mechanism2D.h b/glass/src/lib/native/include/glass/other/Mechanism2D.h
index 440fed38b02..ab5ccdce543 100644
--- a/glass/src/lib/native/include/glass/other/Mechanism2D.h
+++ b/glass/src/lib/native/include/glass/other/Mechanism2D.h
@@ -6,8 +6,6 @@
 
 #include <frc/geometry/Rotation2d.h>
 #include <frc/geometry/Translation2d.h>
-
-#define IMGUI_DEFINE_MATH_OPERATORS
 #include <imgui.h>
 #include <wpi/function_ref.h>
 
diff --git a/glass/src/lib/native/include/glass/support/ExtraGuiWidgets.h b/glass/src/lib/native/include/glass/support/ExtraGuiWidgets.h
index ec4f20ab925..5374b20020b 100644
--- a/glass/src/lib/native/include/glass/support/ExtraGuiWidgets.h
+++ b/glass/src/lib/native/include/glass/support/ExtraGuiWidgets.h
@@ -6,7 +6,6 @@
 
 #include <stdint.h>
 
-#define IMGUI_DEFINE_MATH_OPERATORS
 #include <imgui.h>
 
 namespace glass {
diff --git a/thirdparty/imgui_suite/imgui/include/imconfig.h b/thirdparty/imgui_suite/imgui/include/imconfig.h
index b56ba49467e..291ce199541 100644
--- a/thirdparty/imgui_suite/imgui/include/imconfig.h
+++ b/thirdparty/imgui_suite/imgui/include/imconfig.h
@@ -98,7 +98,7 @@
         operator MyVec4() const { return MyVec4(x,y,z,w); }
 */
 //---- ...Or use Dear ImGui's own very basic math operators.
-//#define IMGUI_DEFINE_MATH_OPERATORS
+#define IMGUI_DEFINE_MATH_OPERATORS
 
 //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
 // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
diff --git a/upstream_utils/imgui_patches/0001-Set-IMGUI_DEFINE_MATH_OPERATORS.patch b/upstream_utils/imgui_patches/0001-Set-IMGUI_DEFINE_MATH_OPERATORS.patch
new file mode 100644
index 00000000000..fc05f16c48f
--- /dev/null
+++ b/upstream_utils/imgui_patches/0001-Set-IMGUI_DEFINE_MATH_OPERATORS.patch
@@ -0,0 +1,23 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Jade Turner <spacey-sooty@proton.me>
+Date: Fri, 11 Apr 2025 11:20:41 +0800
+Subject: [PATCH] Set IMGUI_DEFINE_MATH_OPERATORS
+
+Signed-off-by: Jade Turner <spacey-sooty@proton.me>
+---
+ imconfig.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/imconfig.h b/imconfig.h
+index b56ba49467ebb388e038f0a23aed46044085bdff..291ce1995412f10e784beaf3f4c51e02d90b9813 100644
+--- a/imconfig.h
++++ b/imconfig.h
+@@ -98,7 +98,7 @@
+         operator MyVec4() const { return MyVec4(x,y,z,w); }
+ */
+ //---- ...Or use Dear ImGui's own very basic math operators.
+-//#define IMGUI_DEFINE_MATH_OPERATORS
++#define IMGUI_DEFINE_MATH_OPERATORS
+ 
+ //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
+ // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).


Reviews:
user: login: PeterJohnson
state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-04-21T15:27:25Z
user: login: spacey-sooty
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-24T08:32:42Z
user: login: PeterJohnson
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-24T16:30:59Z
user: login: PeterJohnson
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-28T23:29:35Z
user: login: PeterJohnson
state: APPROVED
author_association: MEMBER
submitted_at: 2025-04-29T14:43:19Z

Review comments:
diff_hunk: @@ -2,18 +2,18 @@
 // Open Source Software; you can modify and/or share it under the terms of
 // the WPILib BSD license file in the root directory of this project.
 
+#include <imgui.h>
+#include <imgui_internal.h>
+#include <wpigui.h>
path: cscore/examples/usbviewer/usbviewer.cpp
user: login: PeterJohnson
body: These are too high, they should be in the group they're currently in; need to adjust the wpiformat settings for cscore to move them back down.
created_at: 2025-04-21T15:26:15Z
author_association: MEMBER
diff_hunk: @@ -4,6 +4,10 @@
 
 #include "glass/other/Field2D.h"
 
+#include <portable-file-dialogs.h>
+#include <units/angle.h>
+#include <units/length.h>
+
path: glass/src/lib/native/cpp/other/Field2D.cpp
user: login: PeterJohnson
body: These are too high, they should be in the group they're currently in; need to adjust the wpiformat settings for glass to move them back down.
created_at: 2025-04-21T15:26:51Z
author_association: MEMBER
diff_hunk: @@ -4,6 +4,10 @@
 
 #include "glass/other/Field2D.h"
 
+#include <portable-file-dialogs.h>
+#include <units/angle.h>
+#include <units/length.h>
+
path: glass/src/lib/native/cpp/other/Field2D.cpp
user: login: spacey-sooty
body: Any idea how I can get the last one down?
created_at: 2025-04-24T08:32:21Z
author_association: CONTRIBUTOR
diff_hunk: @@ -2,18 +2,18 @@
 // Open Source Software; you can modify and/or share it under the terms of
 // the WPILib BSD license file in the root directory of this project.
 
+#include <imgui.h>
+#include <imgui_internal.h>
+#include <wpigui.h>
path: cscore/examples/usbviewer/usbviewer.cpp
user: login: spacey-sooty
body: Any idea how I can get the last one down?
created_at: 2025-04-24T08:32:32Z
author_association: CONTRIBUTOR
diff_hunk: @@ -2,18 +2,18 @@
 // Open Source Software; you can modify and/or share it under the terms of
 // the WPILib BSD license file in the root directory of this project.
 
+#include <imgui.h>
+#include <imgui_internal.h>
+#include <wpigui.h>
path: cscore/examples/usbviewer/usbviewer.cpp
user: login: PeterJohnson
body: The filter is currently looking for `^wpigui/`, you want just `^wpigui`.
created_at: 2025-04-24T16:30:59Z
author_association: MEMBER
diff_hunk: @@ -4,6 +4,10 @@
 
 #include "glass/other/Field2D.h"
 
+#include <portable-file-dialogs.h>
+#include <units/angle.h>
+#include <units/length.h>
+
path: glass/src/lib/native/cpp/other/Field2D.cpp
user: login: PeterJohnson
body: Just need to add portable-file-dialogs.h to the .wpiformat block for external libraries (where imgui et al are listed).
created_at: 2025-04-28T23:29:35Z
author_association: MEMBER

PR comments:
user: login: PeterJohnson
created_at: 2025-04-11T03:24:32Z
body: It should also be removed from everywhere else we define it.
author_association: MEMBER
user: login: spacey-sooty
created_at: 2025-04-11T03:45:02Z
body: > It should also be removed from everywhere else we define it.

I assume its fine to leave in other places its defined within the thirdparty code?
author_association: CONTRIBUTOR