ソースを参照

LibGUI: Add a to_string helper for GUI::MouseButton

It's useful to be able to print mouse button names to the user in other
parts of the system.

Went with a hardcoded switch instead of an enumeration macro like
KeyCode since there were only a handful of cases, and it's unlikely that
many more will ever be added (but can always change it then)
Geordie Hall 3 年 前
コミット
8b9b836a0e
1 ファイル変更20 行追加0 行削除
  1. 20 0
      Userland/Libraries/LibGUI/Event.h

+ 20 - 0
Userland/Libraries/LibGUI/Event.h

@@ -546,4 +546,24 @@ private:
     NonnullRefPtr<Action> m_action;
 };
 
+inline StringView mouse_button_to_string(MouseButton key)
+{
+    switch (key) {
+    case MouseButton::None:
+        return "None";
+    case MouseButton::Primary:
+        return "Primary";
+    case MouseButton::Secondary:
+        return "Secondary";
+    case MouseButton::Middle:
+        return "Middle";
+    case MouseButton::Backward:
+        return "Backward";
+    case MouseButton::Forward:
+        return "Forward";
+    default:
+        VERIFY_NOT_REACHED();
+    }
+}
+
 }