From 8b9b836a0e8d3c91f816ec9741909830ebd47e13 Mon Sep 17 00:00:00 2001 From: Geordie Hall Date: Sat, 5 Feb 2022 17:58:28 +1100 Subject: [PATCH] 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) --- Userland/Libraries/LibGUI/Event.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Userland/Libraries/LibGUI/Event.h b/Userland/Libraries/LibGUI/Event.h index a0b013b0c1..6bbf5c37ba 100644 --- a/Userland/Libraries/LibGUI/Event.h +++ b/Userland/Libraries/LibGUI/Event.h @@ -546,4 +546,24 @@ private: NonnullRefPtr 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(); + } +} + }