1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:07:45 +00:00

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)
This commit is contained in:
Geordie Hall 2022-02-05 17:58:28 +11:00 committed by Linus Groh
parent 5b56f3ed5b
commit 8b9b836a0e

View file

@ -546,4 +546,24 @@ private:
NonnullRefPtr<Action> m_action; 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();
}
}
} }