diff options
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r-- | source/blender/editors/interface/interface_panel.c | 30 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 30 |
2 files changed, 29 insertions, 31 deletions
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index bc38e177cea..cf0bb8d4e8c 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -223,21 +223,19 @@ static bool panels_need_realign(ScrArea *area, ARegion *region, Panel **r_panel_ static Panel *UI_panel_add_instanced_ex(ARegion *region, ListBase *panels, PanelType *panel_type, - int list_index, PointerRNA *custom_data) { Panel *panel = MEM_callocN(sizeof(Panel), "instanced panel"); panel->type = panel_type; BLI_strncpy(panel->panelname, panel_type->idname, sizeof(panel->panelname)); - panel->runtime.list_index = list_index; panel->runtime.custom_data_ptr = custom_data; /* Add the panel's children too. Although they aren't instanced panels, we can still use this * function to create them, as UI_panel_begin does other things we don't need to do. */ LISTBASE_FOREACH (LinkData *, child, &panel_type->children) { PanelType *child_type = child->data; - UI_panel_add_instanced_ex(region, &panel->children, child_type, list_index, custom_data); + UI_panel_add_instanced_ex(region, &panel->children, child_type, custom_data); } /* Make sure the panel is added to the end of the display-order as well. This is needed for @@ -262,8 +260,10 @@ static Panel *UI_panel_add_instanced_ex(ARegion *region, * Called in situations where panels need to be added dynamically rather than having only one panel * corresponding to each #PanelType. */ -Panel *UI_panel_add_instanced( - ARegion *region, ListBase *panels, char *panel_idname, int list_index, PointerRNA *custom_data) +Panel *UI_panel_add_instanced(ARegion *region, + ListBase *panels, + char *panel_idname, + PointerRNA *custom_data) { ARegionType *region_type = region->type; @@ -275,7 +275,7 @@ Panel *UI_panel_add_instanced( return NULL; } - return UI_panel_add_instanced_ex(region, panels, panel_type, list_index, custom_data); + return UI_panel_add_instanced_ex(region, panels, panel_type, custom_data); } /** @@ -284,7 +284,9 @@ Panel *UI_panel_add_instanced( */ void UI_list_panel_unique_str(Panel *panel, char *r_name) { - snprintf(r_name, LIST_PANEL_UNIQUE_STR_LEN, "%d", panel->runtime.list_index); + /* The panel sortorder will be unique for a specific panel type because the instanced + * panel list is regenerated for every change in the data order / length. */ + snprintf(r_name, INSTANCED_PANEL_UNIQUE_STR_LEN, "%d", panel->sortorder); } /** @@ -453,11 +455,6 @@ static void reorder_instanced_panel_list(bContext *C, ARegion *region, Panel *dr } MEM_freeN(panel_sort); - /* Don't reorder the panel didn't change order after being dropped. */ - if (move_to_index == drag_panel->runtime.list_index) { - return; - } - /* Set the bit to tell the interface to instanced the list. */ drag_panel->flag |= PNL_INSTANCED_LIST_ORDER_CHANGED; @@ -2482,6 +2479,11 @@ void UI_panel_custom_data_set(Panel *panel, PointerRNA *custom_data) ui_panel_custom_data_set_recursive(panel, custom_data); } +PointerRNA *UI_panel_custom_data_get(const Panel *panel) +{ + return panel->runtime.custom_data_ptr; +} + PointerRNA *UI_region_panel_custom_data_under_cursor(const bContext *C, const wmEvent *event) { ARegion *region = CTX_wm_region(C); @@ -2506,9 +2508,7 @@ PointerRNA *UI_region_panel_custom_data_under_cursor(const bContext *C, const wm return NULL; } - PointerRNA *customdata = panel->runtime.custom_data_ptr; - - return customdata; + return UI_panel_custom_data_get(panel); } /** \} */ diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 8962755ea90..c27279ab744 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -1882,7 +1882,7 @@ void uiTemplateModifiers(uiLayout *UNUSED(layout), bContext *C) PointerRNA *md_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata"); RNA_pointer_create(&ob->id, &RNA_Modifier, md, md_ptr); - Panel *new_panel = UI_panel_add_instanced(region, ®ion->panels, panel_idname, i, md_ptr); + Panel *new_panel = UI_panel_add_instanced(region, ®ion->panels, panel_idname, md_ptr); if (new_panel != NULL) { UI_panel_set_expand_from_list_data(C, new_panel); @@ -1967,10 +1967,11 @@ static ListBase *get_constraints(const bContext *C, bool use_bone_constraints) */ static void constraint_reorder(bContext *C, Panel *panel, int new_index) { - const bool constraint_from_bone = constraint_panel_is_bone(panel); - ListBase *lb = get_constraints(C, constraint_from_bone); + bool constraint_from_bone = constraint_panel_is_bone(panel); + + PointerRNA *con_ptr = UI_panel_custom_data_get(panel); + bConstraint *con = (bConstraint *)con_ptr->data; - bConstraint *con = BLI_findlink(lb, panel->runtime.list_index); PointerRNA props_ptr; wmOperatorType *ot = WM_operatortype_find("CONSTRAINT_OT_move_to_index", false); WM_operator_properties_create_ptr(&props_ptr, ot); @@ -1985,24 +1986,21 @@ static void constraint_reorder(bContext *C, Panel *panel, int new_index) /** * Get the expand flag from the active constraint to use for the panel. */ -static short get_constraint_expand_flag(const bContext *C, Panel *panel) +static short get_constraint_expand_flag(const bContext *UNUSED(C), Panel *panel) { - const bool constraint_from_bone = constraint_panel_is_bone(panel); - ListBase *lb = get_constraints(C, constraint_from_bone); + PointerRNA *con_ptr = UI_panel_custom_data_get(panel); + bConstraint *con = (bConstraint *)con_ptr->data; - bConstraint *con = BLI_findlink(lb, panel->runtime.list_index); return con->ui_expand_flag; } /** * Save the expand flag for the panel and sub-panels to the constraint. */ -static void set_constraint_expand_flag(const bContext *C, Panel *panel, short expand_flag) +static void set_constraint_expand_flag(const bContext *UNUSED(C), Panel *panel, short expand_flag) { - const bool constraint_from_bone = constraint_panel_is_bone(panel); - ListBase *lb = get_constraints(C, constraint_from_bone); - - bConstraint *con = BLI_findlink(lb, panel->runtime.list_index); + PointerRNA *con_ptr = UI_panel_custom_data_get(panel); + bConstraint *con = (bConstraint *)con_ptr->data; con->ui_expand_flag = expand_flag; } @@ -2057,7 +2055,7 @@ void uiTemplateConstraints(uiLayout *UNUSED(layout), bContext *C, bool use_bone_ PointerRNA *con_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata"); RNA_pointer_create(&ob->id, &RNA_Constraint, con, con_ptr); - Panel *new_panel = UI_panel_add_instanced(region, ®ion->panels, panel_idname, i, con_ptr); + Panel *new_panel = UI_panel_add_instanced(region, ®ion->panels, panel_idname, con_ptr); if (new_panel) { /* Set the list panel functionality function pointers since we don't do it with python. */ @@ -2138,7 +2136,7 @@ void uiTemplateGpencilModifiers(uiLayout *UNUSED(layout), bContext *C) PointerRNA *md_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata"); RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, md_ptr); - Panel *new_panel = UI_panel_add_instanced(region, ®ion->panels, panel_idname, i, md_ptr); + Panel *new_panel = UI_panel_add_instanced(region, ®ion->panels, panel_idname, md_ptr); if (new_panel != NULL) { UI_panel_set_expand_from_list_data(C, new_panel); @@ -2220,7 +2218,7 @@ void uiTemplateShaderFx(uiLayout *UNUSED(layout), bContext *C) PointerRNA *fx_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata"); RNA_pointer_create(&ob->id, &RNA_ShaderFx, fx, fx_ptr); - Panel *new_panel = UI_panel_add_instanced(region, ®ion->panels, panel_idname, i, fx_ptr); + Panel *new_panel = UI_panel_add_instanced(region, ®ion->panels, panel_idname, fx_ptr); if (new_panel != NULL) { UI_panel_set_expand_from_list_data(C, new_panel); |