diff options
author | Julian Eisel <julian@blender.org> | 2021-07-13 16:01:00 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-07-15 17:12:36 +0300 |
commit | 87c1c8112fa44ccb94a3e996b7499d6577d85d7f (patch) | |
tree | 931599775e351a8a5eb78668d3f41625d59507a0 /source/blender/makesrna/intern/rna_ui.c | |
parent | 8edcb3af963113e37490288876419e8f50d4f1e8 (diff) |
UI: Support UI list tooltips, defined via Python scripts
Makes it possible to create tooltips for UI list rows, which can be
filled in .py scripts, similar to how they can extend other menus. This
is used by the (to be committed) Pose Library add-on to display pose
operations (selecting bones of a pose, blending a pose, etc).
It's important that the Python scripts check if the UI list is the
correct one by checking the list ID.
For this to work, a new `bpy.context.ui_list` can be checked. For
example, the Pose Library add-on does the following check:
```
def is_pose_asset_view() -> bool:
# Important: Must check context first, or the menu is added for every kind of list.
list = getattr(context, "ui_list", None)
if not list or list.bl_idname != "UI_UL_asset_view" or list.list_id != "pose_assets":
return False
if not context.asset_handle:
return False
return True
```
Diffstat (limited to 'source/blender/makesrna/intern/rna_ui.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_ui.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index 849bbca16f4..2a076554d03 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -458,6 +458,27 @@ static IDProperty **rna_UIList_idprops(PointerRNA *ptr) return &ui_list->properties; } +static void rna_UIList_list_id_get(PointerRNA *ptr, char *value) +{ + uiList *ui_list = (uiList *)ptr->data; + if (!ui_list->type) { + value[0] = '\0'; + return; + } + + strcpy(value, WM_uilisttype_list_id_get(ui_list->type, ui_list)); +} + +static int rna_UIList_list_id_length(PointerRNA *ptr) +{ + uiList *ui_list = (uiList *)ptr->data; + if (!ui_list->type) { + return 0; + } + + return strlen(WM_uilisttype_list_id_get(ui_list->type, ui_list)); +} + static void uilist_draw_item(uiList *ui_list, bContext *C, uiLayout *layout, @@ -1535,6 +1556,16 @@ static void rna_def_uilist(BlenderRNA *brna) "script, then bl_idname = \"OBJECT_UL_vgroups\")"); /* Data */ + /* Note that this is the "non-full" list-ID as obtained through #WM_uilisttype_list_id_get(), + * which differs from the (internal) `uiList.list_id`. */ + prop = RNA_def_property(srna, "list_id", PROP_STRING, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_string_funcs(prop, "rna_UIList_list_id_get", "rna_UIList_list_id_length", NULL); + RNA_def_property_ui_text(prop, + "List Name", + "Identifier of the list, if any was passed to the \"list_id\" " + "parameter of \"template_list()\""); + prop = RNA_def_property(srna, "layout_type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, rna_enum_uilist_layout_type_items); RNA_def_property_clear_flag(prop, PROP_EDITABLE); |