UI: Move properties tab list creation from RNA to editor

This is a change I pulled from the property-search-ui branch,
where I have to use the list of tabs to search the inactive tabs
and it makes more sense to use the array directly.

It is also an improvement to have this fundamental code to the
properties editor in the editor code rather than an RNA callback.

There are no functional changes.

Differential Revision: https://developer.blender.org/D8368
This commit is contained in:
Hans Goudey 2020-07-23 11:01:59 -04:00
parent c9975d19b5
commit 6f3c37a3ff
3 changed files with 115 additions and 77 deletions

View File

@ -27,6 +27,10 @@
extern "C" {
#endif
struct SpaceProperties;
int ED_buttons_tabs_list(struct SpaceProperties *sbuts, int *context_tabs_array);
#ifdef __cplusplus
}
#endif

View File

@ -35,6 +35,7 @@
#include "BKE_screen.h"
#include "BKE_shader_fx.h"
#include "ED_buttons.h"
#include "ED_screen.h"
#include "ED_space_api.h"
#include "ED_view3d.h" /* To draw toolbar UI. */
@ -139,6 +140,98 @@ static void buttons_main_region_init(wmWindowManager *wm, ARegion *region)
WM_event_add_keymap_handler(&region->handlers, keymap);
}
/**
* Fills an array with the tab context values for the properties editor. -1 signals a separator.
*
* \return The total number of items in the array returned.
*/
int ED_buttons_tabs_list(SpaceProperties *sbuts, int *context_tabs_array)
{
int length = 0;
if (sbuts->pathflag & (1 << BCONTEXT_TOOL)) {
context_tabs_array[length] = BCONTEXT_TOOL;
length++;
}
if (length != 0) {
context_tabs_array[length] = -1;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_RENDER)) {
context_tabs_array[length] = BCONTEXT_RENDER;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_OUTPUT)) {
context_tabs_array[length] = BCONTEXT_OUTPUT;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_VIEW_LAYER)) {
context_tabs_array[length] = BCONTEXT_VIEW_LAYER;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_SCENE)) {
context_tabs_array[length] = BCONTEXT_SCENE;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_WORLD)) {
context_tabs_array[length] = BCONTEXT_WORLD;
length++;
}
if (length != 0) {
context_tabs_array[length] = -1;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_OBJECT)) {
context_tabs_array[length] = BCONTEXT_OBJECT;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_MODIFIER)) {
context_tabs_array[length] = BCONTEXT_MODIFIER;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_SHADERFX)) {
context_tabs_array[length] = BCONTEXT_SHADERFX;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_PARTICLE)) {
context_tabs_array[length] = BCONTEXT_PARTICLE;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_PHYSICS)) {
context_tabs_array[length] = BCONTEXT_PHYSICS;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_CONSTRAINT)) {
context_tabs_array[length] = BCONTEXT_CONSTRAINT;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_DATA)) {
context_tabs_array[length] = BCONTEXT_DATA;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_BONE)) {
context_tabs_array[length] = BCONTEXT_BONE;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_BONE_CONSTRAINT)) {
context_tabs_array[length] = BCONTEXT_BONE_CONSTRAINT;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_MATERIAL)) {
context_tabs_array[length] = BCONTEXT_MATERIAL;
length++;
}
if (length != 0) {
context_tabs_array[length] = -1;
length++;
}
if (sbuts->pathflag & (1 << BCONTEXT_TEXTURE)) {
context_tabs_array[length] = BCONTEXT_TEXTURE;
length++;
}
return length;
}
static void buttons_main_region_layout_properties(const bContext *C,
SpaceProperties *sbuts,
ARegion *region)

View File

@ -1776,87 +1776,28 @@ static const EnumPropertyItem *rna_SpaceProperties_context_itemf(bContext *UNUSE
{
SpaceProperties *sbuts = (SpaceProperties *)(ptr->data);
EnumPropertyItem *item = NULL;
int totitem = 0;
if (sbuts->pathflag & (1 << BCONTEXT_TOOL)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_TOOL);
}
/* We use 32 tabs maximum here so a flag for each can fit into a 32 bit integer flag.
* A theoretical maximum would be BCONTEXT_TOT * 2, with every tab displayed and a spacer
* in every other item. But this size is currently limited by the size of integer
* supported by RNA enums. */
int context_tabs_array[32];
int totitem = ED_buttons_tabs_list(sbuts, context_tabs_array);
BLI_assert(totitem <= ARRAY_SIZE(context_tabs_array));
if (totitem) {
RNA_enum_item_add_separator(&item, &totitem);
}
int totitem_added = 0;
for (int i = 0; i < totitem; i++) {
if (context_tabs_array[i] == -1) {
RNA_enum_item_add_separator(&item, &totitem_added);
continue;
}
if (sbuts->pathflag & (1 << BCONTEXT_RENDER)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_RENDER);
}
RNA_enum_items_add_value(&item, &totitem_added, buttons_context_items, context_tabs_array[i]);
if (sbuts->pathflag & (1 << BCONTEXT_OUTPUT)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_OUTPUT);
}
if (sbuts->pathflag & (1 << BCONTEXT_VIEW_LAYER)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_VIEW_LAYER);
}
if (sbuts->pathflag & (1 << BCONTEXT_SCENE)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_SCENE);
}
if (sbuts->pathflag & (1 << BCONTEXT_WORLD)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_WORLD);
}
if (totitem) {
RNA_enum_item_add_separator(&item, &totitem);
}
if (sbuts->pathflag & (1 << BCONTEXT_OBJECT)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_OBJECT);
}
if (sbuts->pathflag & (1 << BCONTEXT_MODIFIER)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_MODIFIER);
}
if (sbuts->pathflag & (1 << BCONTEXT_SHADERFX)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_SHADERFX);
}
if (sbuts->pathflag & (1 << BCONTEXT_PARTICLE)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_PARTICLE);
}
if (sbuts->pathflag & (1 << BCONTEXT_PHYSICS)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_PHYSICS);
}
if (sbuts->pathflag & (1 << BCONTEXT_CONSTRAINT)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_CONSTRAINT);
}
if (sbuts->pathflag & (1 << BCONTEXT_DATA)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_DATA);
(item + totitem - 1)->icon = sbuts->dataicon;
}
if (sbuts->pathflag & (1 << BCONTEXT_BONE)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_BONE);
}
if (sbuts->pathflag & (1 << BCONTEXT_BONE_CONSTRAINT)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_BONE_CONSTRAINT);
}
if (sbuts->pathflag & (1 << BCONTEXT_MATERIAL)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_MATERIAL);
}
if (totitem) {
RNA_enum_item_add_separator(&item, &totitem);
}
if (sbuts->pathflag & (1 << BCONTEXT_TEXTURE)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_TEXTURE);
/* Add the object data icon dynamically for the data tab. */
if (context_tabs_array[i] == BCONTEXT_DATA) {
(item + totitem_added - 1)->icon = sbuts->dataicon;
}
}
RNA_enum_item_end(&item, &totitem);