diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-10-27 18:51:26 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-10-27 18:57:56 +0300 |
commit | ae55523013642f2897e840f30ad62c74d31df3e0 (patch) | |
tree | c8f3af1b967ef05b1aee8a6c90a828c1dbc499b1 /source/blender/editors/interface/interface_templates.c | |
parent | c036db9f57ff1bf5762e2b4dda802ee41cdbd115 (diff) |
UI: add utility to show icons for the keymap item
This is useful for drawing keymap items into the header or status bar
While these icons are available directly,
mapping them from the keymap item isn't trivial.
Diffstat (limited to 'source/blender/editors/interface/interface_templates.c')
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index fe484676ddd..021d7733fae 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -6657,6 +6657,42 @@ void uiTemplateKeymapItemProperties(uiLayout *layout, PointerRNA *ptr) /** \} */ /* -------------------------------------------------------------------- */ +/** \name Event Icon Template + * + * \{ */ + +bool uiTemplateEventFromKeymapItem(struct uiLayout *layout, + const char *text, + const struct wmKeyMapItem *kmi, + bool text_fallback) +{ + bool ok = false; + + int icon_mod[4]; +#ifdef WITH_HEADLESS + int icon = 0; +#else + int icon = UI_icon_from_keymap_item(kmi, icon_mod); +#endif + if (icon != 0) { + for (int j = 0; j < ARRAY_SIZE(icon_mod) && icon_mod[j]; j++) { + uiItemL(layout, "", icon_mod[j]); + } + uiItemL(layout, text, icon); + ok = true; + } + else if (text_fallback) { + const char *event_text = WM_key_event_string(kmi->type, true); + uiItemL(layout, event_text, ICON_NONE); + uiItemL(layout, text, ICON_NONE); + ok = true; + } + return ok; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ /** \name Color Management Template * \{ */ |