Cleanup: use 'context' to make panels show in their section

All panels were calling poll to draw in their section causing a lot of
repeated boiler plate poll functions.

Also rename 'PreferencePanel' to 'CenterAlignMixIn'
since this is it's purpose.
This commit is contained in:
Campbell Barton
2019-12-19 13:21:41 +11:00
parent f98e2c0427
commit 7ba1489bd7
4 changed files with 259 additions and 376 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -35,6 +35,9 @@
#include "ED_screen.h" #include "ED_screen.h"
#include "ED_space_api.h" #include "ED_space_api.h"
#include "RNA_access.h"
#include "RNA_enum_types.h"
#include "WM_api.h" #include "WM_api.h"
#include "WM_types.h" #include "WM_types.h"
@@ -119,9 +122,27 @@ static void userpref_main_region_init(wmWindowManager *wm, ARegion *ar)
ED_region_panels_init(wm, ar); ED_region_panels_init(wm, ar);
} }
static void userpref_main_region_draw(const bContext *C, ARegion *ar) static void userpref_main_region_layout(const bContext *C, ARegion *ar)
{ {
ED_region_panels_ex(C, ar, NULL, U.space_data.section_active, true); char id_lower[64];
const char *contexts[2] = {id_lower, NULL};
/* Avoid duplicating identifiers, use existing RNA enum. */
{
const EnumPropertyItem *items = rna_enum_preference_section_items;
int i = RNA_enum_from_value(items, U.space_data.section_active);
/* File is from the future. */
if (i == -1) {
i = 0;
}
const char *id = items[i].identifier;
BLI_assert(strlen(id) < sizeof(id_lower));
STRNCPY(id_lower, id);
BLI_str_tolower_ascii(id_lower, strlen(id_lower));
}
ED_region_panels_layout_ex(
C, ar, &ar->type->paneltypes, contexts, U.space_data.section_active, true, NULL);
} }
static void userpref_operatortypes(void) static void userpref_operatortypes(void)
@@ -225,7 +246,8 @@ void ED_spacetype_userpref(void)
art = MEM_callocN(sizeof(ARegionType), "spacetype userpref region"); art = MEM_callocN(sizeof(ARegionType), "spacetype userpref region");
art->regionid = RGN_TYPE_WINDOW; art->regionid = RGN_TYPE_WINDOW;
art->init = userpref_main_region_init; art->init = userpref_main_region_init;
art->draw = userpref_main_region_draw; art->layout = userpref_main_region_layout;
art->draw = ED_region_panels_draw;
art->listener = userpref_main_region_listener; art->listener = userpref_main_region_listener;
art->keymapflag = ED_KEYMAP_UI; art->keymapflag = ED_KEYMAP_UI;

View File

@@ -219,6 +219,7 @@ extern const EnumPropertyItem rna_enum_abc_compression_items[];
extern const EnumPropertyItem rna_enum_context_mode_items[]; extern const EnumPropertyItem rna_enum_context_mode_items[];
extern const EnumPropertyItem rna_enum_curveprofile_preset_items[]; extern const EnumPropertyItem rna_enum_curveprofile_preset_items[];
extern const EnumPropertyItem rna_enum_preference_section_items[];
/* API calls */ /* API calls */
int rna_node_tree_type_to_enum(struct bNodeTreeType *typeinfo); int rna_node_tree_type_to_enum(struct bNodeTreeType *typeinfo);

View File

@@ -69,7 +69,7 @@ static const EnumPropertyItem opensubdiv_compute_type_items[] = {
}; };
#endif #endif
static const EnumPropertyItem preference_section_items[] = { const EnumPropertyItem rna_enum_preference_section_items[] = {
{USER_SECTION_INTERFACE, "INTERFACE", 0, "Interface", ""}, {USER_SECTION_INTERFACE, "INTERFACE", 0, "Interface", ""},
{USER_SECTION_THEME, "THEMES", 0, "Themes", ""}, {USER_SECTION_THEME, "THEMES", 0, "Themes", ""},
{USER_SECTION_VIEWPORT, "VIEWPORT", 0, "Viewport", ""}, {USER_SECTION_VIEWPORT, "VIEWPORT", 0, "Viewport", ""},
@@ -92,6 +92,8 @@ static const EnumPropertyItem preference_section_items[] = {
{USER_SECTION_SYSTEM, "SYSTEM", 0, "System", ""}, {USER_SECTION_SYSTEM, "SYSTEM", 0, "System", ""},
{USER_SECTION_SAVE_LOAD, "SAVE_LOAD", 0, "Save & Load", ""}, {USER_SECTION_SAVE_LOAD, "SAVE_LOAD", 0, "Save & Load", ""},
{USER_SECTION_FILE_PATHS, "FILE_PATHS", 0, "File Paths", ""}, {USER_SECTION_FILE_PATHS, "FILE_PATHS", 0, "File Paths", ""},
{0, "", 0, NULL, NULL},
{USER_SECTION_EXPERIMENTAL, "EXPERIMENTAL", 0, "Experimental", ""},
{0, NULL, 0, NULL, NULL}, {0, NULL, 0, NULL, NULL},
}; };
@@ -468,26 +470,22 @@ static const EnumPropertyItem *rna_UseDef_active_section_itemf(bContext *UNUSED(
{ {
UserDef *userdef = ptr->data; UserDef *userdef = ptr->data;
if ((userdef->flag & USER_DEVELOPER_UI) == 0) { if ((userdef->flag & USER_DEVELOPER_UI) != 0) {
*r_free = false; *r_free = false;
return preference_section_items; return rna_enum_preference_section_items;
} }
EnumPropertyItem *items = NULL; EnumPropertyItem *items = NULL;
int totitem = 0; int totitem = 0;
RNA_enum_items_add(&items, &totitem, preference_section_items); for (const EnumPropertyItem *it = rna_enum_preference_section_items; it->identifier != NULL;
RNA_enum_item_add_separator(&items, &totitem); it++) {
if (it->value == USER_SECTION_EXPERIMENTAL) {
continue;
}
RNA_enum_item_add(&items, &totitem, it);
}
EnumPropertyItem item = {
.value = USER_SECTION_EXPERIMENTAL,
.name = "Experimental",
.identifier = "EXPERIMENTAL",
.icon = 0,
.description = "",
};
RNA_enum_item_add(&items, &totitem, &item);
RNA_enum_item_end(&items, &totitem); RNA_enum_item_end(&items, &totitem);
*r_free = true; *r_free = true;
@@ -5942,7 +5940,7 @@ void RNA_def_userdef(BlenderRNA *brna)
prop = RNA_def_property(srna, "active_section", PROP_ENUM, PROP_NONE); prop = RNA_def_property(srna, "active_section", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "space_data.section_active"); RNA_def_property_enum_sdna(prop, NULL, "space_data.section_active");
RNA_def_property_enum_items(prop, preference_section_items); RNA_def_property_enum_items(prop, rna_enum_preference_section_items);
RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_UseDef_active_section_itemf"); RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_UseDef_active_section_itemf");
RNA_def_property_ui_text( RNA_def_property_ui_text(
prop, "Active Section", "Active section of the preferences shown in the user interface"); prop, "Active Section", "Active section of the preferences shown in the user interface");