From 39739c1c5f06971318d0fbfc1de78accd5ef9d4d Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 9 Feb 2017 14:28:55 +0100 Subject: Add columns for visibility and selectability toggles Good example of where the table API is useful: Adding new columns is a small change. --- .../editors/space_collections/collections_draw.c | 20 ++++++++++++++++++++ .../editors/space_collections/collections_edit.c | 16 +++++++++++++--- .../editors/space_collections/collections_intern.h | 2 ++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/space_collections/collections_draw.c b/source/blender/editors/space_collections/collections_draw.c index fdf31562985..2fb87e4f936 100644 --- a/source/blender/editors/space_collections/collections_draw.c +++ b/source/blender/editors/space_collections/collections_draw.c @@ -31,6 +31,8 @@ #include "DNA_screen_types.h" #include "DNA_space_types.h" +#include "RNA_access.h" + #include "UI_interface.h" #include "UI_resources.h" #include "UI_table.h" @@ -62,3 +64,21 @@ void collections_draw_cell(uiLayout *layout, void *rowdata, rcti UNUSED(drawrect LayerCollection *collection = rowdata; uiItemL(layout, collection->scene_collection->name, ICON_NONE); } + +void collections_draw_cell_visibility(uiLayout *layout, void *rowdata, rcti UNUSED(drawrect)) +{ + LayerCollection *collection = rowdata; + PointerRNA ptr; + + RNA_pointer_create(NULL, &RNA_LayerCollection, collection, &ptr); + uiItemR(layout, &ptr, "hide", UI_ITEM_R_NO_BG, "", ICON_RESTRICT_VIEW_OFF); +} + +void collections_draw_cell_selectability(uiLayout *layout, void *rowdata, rcti UNUSED(drawrect)) +{ + LayerCollection *collection = rowdata; + PointerRNA ptr; + + RNA_pointer_create(NULL, &RNA_LayerCollection, collection, &ptr); + uiItemR(layout, &ptr, "hide_select", UI_ITEM_R_NO_BG, "", ICON_RESTRICT_SELECT_OFF); +} diff --git a/source/blender/editors/space_collections/collections_edit.c b/source/blender/editors/space_collections/collections_edit.c index b485ebc1a2f..e7bdd4c2ae6 100644 --- a/source/blender/editors/space_collections/collections_edit.c +++ b/source/blender/editors/space_collections/collections_edit.c @@ -28,7 +28,9 @@ #include "DNA_layer_types.h" #include "DNA_screen_types.h" +#include "DNA_userdef_types.h" +#include "UI_interface.h" #include "UI_table.h" #include "collections_intern.h" @@ -36,12 +38,20 @@ void collections_table_create(SceneLayer *layer, uiTable **r_table) { - *r_table = UI_table_vertical_flow_create(); + uiTable *table = UI_table_vertical_flow_create(); + uiTableColumn *col; + + UI_table_column_add(table, "name", "Collection", collections_draw_cell); + col = UI_table_column_add(table, "visibility", "Visible", collections_draw_cell_visibility); + UI_table_column_width_set(col, UI_UNIT_X, TABLE_UNIT_PX, UI_UNIT_X); + col = UI_table_column_add(table, "selectability", "Selectable", collections_draw_cell_selectability); + UI_table_column_width_set(col, UI_UNIT_X, TABLE_UNIT_PX, UI_UNIT_X); - UI_table_column_add(*r_table, "collection_name", "Collection", collections_draw_cell); for (LayerCollection *collection = layer->layer_collections.first; collection; collection = collection->next) { - UI_table_row_add(*r_table, collection); + UI_table_row_add(table, collection); } + + *r_table = table; } void collections_table_free(uiTable *table) diff --git a/source/blender/editors/space_collections/collections_intern.h b/source/blender/editors/space_collections/collections_intern.h index 6cae7c0037b..9b49aac3534 100644 --- a/source/blender/editors/space_collections/collections_intern.h +++ b/source/blender/editors/space_collections/collections_intern.h @@ -43,6 +43,8 @@ void collections_keymap(struct wmKeyConfig *keyconf); /* collections_draw.c */ void collections_draw_table(const struct bContext *C, struct SpaceCollections *spc, ARegion *ar); void collections_draw_cell(struct uiLayout *layout, void *rowdata, struct rcti drawrect); +void collections_draw_cell_visibility(struct uiLayout *layout, void *rowdata, struct rcti drawrect); +void collections_draw_cell_selectability(struct uiLayout *layout, void *rowdata, struct rcti drawrect); #endif /* __COLLECTIONS_INTERN_H__ */ -- cgit v1.2.3