summaryrefslogtreecommitdiff
path: root/FL
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2025-11-29 21:01:48 +0100
committerMatthias Melcher <github@matthiasm.com>2025-11-29 21:01:53 +0100
commit70527b3bf0289add9cb4c3f8456368f946a5e386 (patch)
tree979a5cc55fc890170d09d8d6d408267ff72a998f /FL
parent6aa95584e092fc5ab554e408b061a30d4b3811e3 (diff)
Improve access to C++ symbols.
For events, fonts, and callback reasons
Diffstat (limited to 'FL')
-rw-r--r--FL/names.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/FL/names.h b/FL/names.h
index 3587b3d8d..1d4c42a4c 100644
--- a/FL/names.h
+++ b/FL/names.h
@@ -92,6 +92,20 @@ std::map<int, const char*> fl_eventnames = {
{ Fl::Pen::BUTTON_RELEASE, "Fl::Pen::BUTTON_RELEASE" }
};
+/**
+ Return the C++ symbol of an Fl_Event as a string.
+ \param[in] event index as an integer
+ \return C++ symbol of event index as a string
+ */
+inline std::string fl_eventname_str(int event) {
+ auto it = fl_eventnames.find(event);
+ if (it == fl_eventnames.end()) {
+ return "FL_EVENT_" + std::to_string(event);
+ } else {
+ return it->second;
+ }
+}
+
/**
This is an array of font names you can use to convert font numbers into names.
@@ -131,6 +145,20 @@ const char * const fl_fontnames[] =
};
/**
+ Return the C++ symbol of an Fl_Font as a string.
+ \param[in] font index as an integer
+ \return C++ symbol of font index as a string
+*/
+inline std::string fl_fontname_str(int font) {
+ if ((font < 0) || (font >= FL_ZAPF_DINGBATS)) {
+ return "FL_FONT_" + std::to_string(font);
+ } else {
+ return fl_fontnames[font];
+ }
+}
+
+
+/**
This is an array of callback reason names you can use to convert callback reasons into names.
The array gets defined inline wherever your '\#include <FL/names.h>' appears.
@@ -156,6 +184,19 @@ const char * const fl_callback_reason_names[] =
"FL_REASON_USER", "FL_REASON_USER+1", "FL_REASON_USER+2", "FL_REASON_USER+3",
};
+/**
+ Return the C++ symbol of an Fl_Callback_Reason as a string.
+ \param[in] reason as an integer
+ \return C++ symbol of reason as a string
+*/
+inline std::string fl_callback_reason_str(int reason) {
+ if ((reason < 0) || (reason >= FL_REASON_USER+3) || (fl_callback_reason_names[reason] == nullptr)) {
+ return "FL_REASON_" + std::to_string(reason);
+ } else {
+ return fl_callback_reason_names[reason];
+ }
+}
+
/** @} */
#endif /* FL_NAMES_H */