UI: Category support for instanced panels

This adds support for panel categories to the instanced panel system
used for modifiers and others. The change is pulled from D7997 where
it is needed for FCurve modifiers, but it is unused now.

The change is simple and basically amounts to checking the panel
category where it was overlooked before.
This commit is contained in:
Hans Goudey 2020-08-12 12:56:10 -04:00
parent 6238eabcd4
commit 1da053956a
2 changed files with 45 additions and 27 deletions

View File

@ -117,7 +117,9 @@ typedef struct PanelSort {
static int get_panel_real_size_y(const Panel *panel);
static void panel_activate_state(const bContext *C, Panel *panel, uiHandlePanelState state);
static int compare_panel(const void *a1, const void *a2);
static bool panel_type_context_poll(PanelType *panel_type, const char *context);
static bool panel_type_context_poll(ARegion *region,
const PanelType *panel_type,
const char *context);
static void panel_title_color_get(bool show_background, uchar color[4])
{
@ -460,14 +462,17 @@ static void reorder_instanced_panel_list(bContext *C, ARegion *region, Panel *dr
return;
}
char *context = drag_panel->type->context;
char *context = NULL;
if (!UI_panel_category_is_visible(region)) {
context = drag_panel->type->context;
}
/* Find how many instanced panels with this context string. */
int list_panels_len = 0;
LISTBASE_FOREACH (Panel *, panel, &region->panels) {
if (panel->type) {
if (panel_type_context_poll(panel->type, context)) {
if (panel->type->flag & PNL_INSTANCED) {
if (panel->type->flag & PNL_INSTANCED) {
if (panel_type_context_poll(region, panel->type, context)) {
list_panels_len++;
}
}
@ -479,8 +484,8 @@ static void reorder_instanced_panel_list(bContext *C, ARegion *region, Panel *dr
PanelSort *sort_index = panel_sort;
LISTBASE_FOREACH (Panel *, panel, &region->panels) {
if (panel->type) {
if (panel_type_context_poll(panel->type, context)) {
if (panel->type->flag & PNL_INSTANCED) {
if (panel->type->flag & PNL_INSTANCED) {
if (panel_type_context_poll(region, panel->type, context)) {
sort_index->panel = MEM_dupallocN(panel);
sort_index->orig = panel;
sort_index++;
@ -657,11 +662,18 @@ static void panels_collapse_all(const bContext *C,
set_panels_list_data_expand_flag(C, region);
}
static bool panel_type_context_poll(PanelType *panel_type, const char *context)
static bool panel_type_context_poll(ARegion *region,
const PanelType *panel_type,
const char *context)
{
if (UI_panel_category_is_visible(region)) {
return STREQ(panel_type->category, UI_panel_category_active_get(region, false));
}
if (panel_type->context[0] && STREQ(panel_type->context, context)) {
return true;
}
return false;
}

View File

@ -2658,29 +2658,35 @@ void ED_region_panels_layout_ex(const bContext *C,
if (has_instanced_panel) {
LISTBASE_FOREACH (Panel *, panel, &region->panels) {
if (panel->type == NULL) {
continue; /* Some panels don't have a type.. */
continue; /* Some panels don't have a type. */
}
if (!(panel->type->flag & PNL_INSTANCED)) {
continue;
}
if (use_category_tabs && panel->type->category[0] &&
!STREQ(category, panel->type->category)) {
continue;
}
if (panel->type->flag & PNL_INSTANCED) {
if (panel && UI_panel_is_dragging(panel)) {
/* Prevent View2d.tot rectangle size changes while dragging panels. */
update_tot_size = false;
}
/* Use a unique identifier for instanced panels, otherwise an old block for a different
* panel of the same type might be found. */
char unique_panel_str[8];
UI_list_panel_unique_str(panel, unique_panel_str);
ed_panel_draw(C,
area,
region,
&region->panels,
panel->type,
panel,
(panel->type->flag & PNL_DRAW_BOX) ? w_box_panel : w,
em,
vertical,
unique_panel_str);
if (panel && UI_panel_is_dragging(panel)) {
/* Prevent View2d.tot rectangle size changes while dragging panels. */
update_tot_size = false;
}
/* Use a unique identifier for instanced panels, otherwise an old block for a different
* panel of the same type might be found. */
char unique_panel_str[8];
UI_list_panel_unique_str(panel, unique_panel_str);
ed_panel_draw(C,
area,
region,
&region->panels,
panel->type,
panel,
(panel->type->flag & PNL_DRAW_BOX) ? w_box_panel : w,
em,
vertical,
unique_panel_str);
}
}