WIP: #104303: WM panel parent API #105193

Draft
Pratyaksh Raj wants to merge 2 commits from Pratyaksh-Raj/blender:WM-Panel-API into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
9 changed files with 61 additions and 18 deletions
Showing only changes of commit 24783dae41 - Show all commits

View File

@ -208,11 +208,13 @@ static PanelType *fmodifier_subpanel_register(ARegionType *region_type,
panel_type->poll = poll;
panel_type->flag = PANEL_TYPE_DEFAULT_CLOSED;
BLI_assert(parent != NULL);
/* BLI_assert(parent != NULL);
Review

WM_paneltype_subpanel_add(parent, pt, false); (you do not want to use order here).

` WM_paneltype_subpanel_add(parent, pt, false);` (you do not want to use order here).
BLI_strncpy(panel_type->parent_id, parent->idname, BKE_ST_MAXNAME);
panel_type->parent = parent;
BLI_addtail(&parent->children, BLI_genericNodeN(panel_type));
BLI_addtail(&region_type->paneltypes, panel_type);
Review

This line should not be removed, it's not handled by the call to WM_paneltype_subpanel_add.

This line should not be removed, it's not handled by the call to `WM_paneltype_subpanel_add`.
BLI_addtail(&region_type->paneltypes, panel_type);*/
Review

Please remove code, do not comment it out. It makes patch less readable, and we do not want to keep dead code around.

Same for other cases below.

Please remove code, do not comment it out. It makes patch less readable, and we do not want to keep dead code around. Same for other cases below.
WM_paneltype_subpanel_add(parent, NULL, pt, true);
Review

There are four parameters here, function only takes three of them...

Same for other cases below.

There are four parameters here, function only takes three of them... Same for other cases below.
return panel_type;
}

View File

@ -665,11 +665,12 @@ void nla_buttons_register(ARegionType *art)
strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
pt->draw = nla_panel_evaluation;
pt->draw_header = nla_panel_animated_influence_header;
pt->parent = pt_properties;
// pt->parent = pt_properties;
pt->flag = PANEL_TYPE_DEFAULT_CLOSED;
pt->poll = nla_strip_eval_panel_poll;
Review

WM_paneltype_subpanel_add(parent, pt, false); (you do not want to use order here).

` WM_paneltype_subpanel_add(parent, pt, false);` (you do not want to use order here).
BLI_addtail(&pt_properties->children, BLI_genericNodeN(pt));
BLI_addtail(&art->paneltypes, pt);
// BLI_addtail(&pt_properties->children, BLI_genericNodeN(pt));
// BLI_addtail(&art->paneltypes, pt);
Review

Remove extra spaces...

Remove extra spaces...
WM_paneltype_subpanel_add(pt_properties, pt, true);
pt = MEM_callocN(sizeof(PanelType), "spacetype nla panel animated strip time");
strcpy(pt->idname, "NLA_PT_animated_strip_time");
@ -679,12 +680,12 @@ void nla_buttons_register(ARegionType *art)
strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
pt->draw = nla_panel_animated_strip_time;
pt->draw_header = nla_panel_animated_strip_time_header;
pt->parent = pt_properties;
// pt->parent = pt_properties;
Review

WM_paneltype_subpanel_add(parent, pt, false); (you do not want to use order here).

` WM_paneltype_subpanel_add(parent, pt, false);` (you do not want to use order here).
pt->flag = PANEL_TYPE_DEFAULT_CLOSED;
pt->poll = nla_strip_eval_panel_poll;
BLI_addtail(&pt_properties->children, BLI_genericNodeN(pt));
BLI_addtail(&art->paneltypes, pt);
Review

No need to remove that line

No need to remove that line
//BLI_addtail(&pt_properties->children, BLI_genericNodeN(pt));
//BLI_addtail(&art->paneltypes, pt);
WM_paneltype_subpanel_add(pt_properties, pt, true);
pt = MEM_callocN(sizeof(PanelType), "spacetype nla panel modifiers");
strcpy(pt->idname, "NLA_PT_modifiers");
strcpy(pt->label, N_("Modifiers"));

View File

@ -391,11 +391,13 @@ PanelType *gpencil_modifier_subpanel_register(ARegionType *region_type,
panel_type->poll = gpencil_modifier_ui_poll;
panel_type->flag = PANEL_TYPE_DEFAULT_CLOSED;
BLI_assert(parent != NULL);
/* BLI_assert(parent != NULL);
Review

WM_paneltype_subpanel_add(parent, pt, false); (you do not want to use order here).

` WM_paneltype_subpanel_add(parent, pt, false);` (you do not want to use order here).
BLI_strncpy(panel_type->parent_id, parent->idname, BKE_ST_MAXNAME);
panel_type->parent = parent;
BLI_addtail(&parent->children, BLI_genericNodeN(panel_type));
BLI_addtail(&region_type->paneltypes, panel_type);
Review

This line should not be removed, it's not handled by the call to WM_paneltype_subpanel_add.

This line should not be removed, it's not handled by the call to `WM_paneltype_subpanel_add`.
BLI_addtail(&region_type->paneltypes, panel_type);*/
WM_paneltype_subpanel_add(parent, NULL, pt, true);
return panel_type;
}

View File

@ -389,7 +389,7 @@ static StructRNA *rna_Panel_register(Main *bmain,
}
/* Insert into list. */
BLI_insertlinkafter(&art->paneltypes, pt_iter, pt);
/* BLI_insertlinkafter(&art->paneltypes, pt_iter, pt);
if (parent) {
pt->parent = parent;
@ -410,7 +410,9 @@ static StructRNA *rna_Panel_register(Main *bmain,
}
}
WM_paneltype_add(pt);
WM_paneltype_add(pt); */
WM_paneltype_subpanel_add(parent, NULL, pt, true);
/* update while blender is running */
WM_main_add_notifier(NC_WINDOW, NULL);

View File

@ -483,11 +483,13 @@ PanelType *modifier_subpanel_register(ARegionType *region_type,
panel_type->poll = modifier_ui_poll;
panel_type->flag = PANEL_TYPE_DEFAULT_CLOSED;
BLI_assert(parent != NULL);
/* BLI_assert(parent != NULL);
Review

WM_paneltype_subpanel_add(parent, pt, false); (you do not want to use order here).

` WM_paneltype_subpanel_add(parent, pt, false);` (you do not want to use order here).
BLI_strncpy(panel_type->parent_id, parent->idname, BKE_ST_MAXNAME);
panel_type->parent = parent;
BLI_addtail(&parent->children, BLI_genericNodeN(panel_type));
BLI_addtail(&region_type->paneltypes, panel_type);
Review

This line should not be removed, it's not handled by the call to WM_paneltype_subpanel_add.

This line should not be removed, it's not handled by the call to `WM_paneltype_subpanel_add`.
BLI_addtail(&region_type->paneltypes, panel_type);*/
WM_paneltype_subpanel_add(parent, NULL, pt, true);
return panel_type;
}

View File

@ -262,11 +262,13 @@ PanelType *shaderfx_subpanel_register(ARegionType *region_type,
panel_type->poll = shaderfx_ui_poll;
panel_type->flag = PANEL_TYPE_DEFAULT_CLOSED;
BLI_assert(parent != NULL);
/* BLI_assert(parent != NULL);
Review

WM_paneltype_subpanel_add(parent, pt, false); (you do not want to use order here).

` WM_paneltype_subpanel_add(parent, pt, false);` (you do not want to use order here).
BLI_strncpy(panel_type->parent_id, parent->idname, BKE_ST_MAXNAME);
panel_type->parent = parent;
BLI_addtail(&parent->children, BLI_genericNodeN(panel_type));
BLI_addtail(&region_type->paneltypes, panel_type);
Review

This line should not be removed, it's not handled by the call to WM_paneltype_subpanel_add.

This line should not be removed, it's not handled by the call to `WM_paneltype_subpanel_add`.
BLI_addtail(&region_type->paneltypes, panel_type); */
WM_paneltype_subpanel_add(parent, NULL, pt, true);
return panel_type;
}

View File

@ -1154,6 +1154,7 @@ void WM_paneltype_init(void);
void WM_paneltype_clear(void);
struct PanelType *WM_paneltype_find(const char *idname, bool quiet);
bool WM_paneltype_add(struct PanelType *pt);
void WM_paneltype_subpanel_add(PanelType *pt, PanelType *parent, bool use_order);
void WM_paneltype_remove(struct PanelType *pt);
void WM_paneltype_idname_visit_for_search(const struct bContext *C,

View File

@ -46,6 +46,37 @@ bool WM_paneltype_add(PanelType *pt)
BLI_ghash_insert(g_paneltypes_hash, pt->idname, pt);
return true;
}
void WM_paneltype_subpanel_add(PanelType *pt, PanelType *parent, bool use_order)
Review

Style: Please leave an empty line between function definitions.

Style: Please leave an empty line between function definitions.
{
pt->parent = parent;
if (parent) {
if (use_order) {
LinkData *pt_child_iter = parent->children.last;
for (; pt_child_iter; pt_child_iter = pt_child_iter->prev) {
PanelType *pt_child = pt_child_iter->data;
if (pt_child->order <= pt->order) {
break;
}
}
BLI_insertlinkafter(&parent->children, pt_child_iter, BLI_genericNodeN(pt));
}
else {
BLI_addtail(&parent->children, BLI_genericNodeN(pt));
}
BLI_addtail(&art->paneltypes, pt);
Review

Wondering where art comes from here...? Missing parameter?

Wondering where `art` comes from here...? Missing parameter?
}
{
const char *owner_id = RNA_struct_state_owner_get();
if (owner_id) {
BLI_strncpy(pt->owner_id, owner_id, sizeof(pt->owner_id));
}
}
Review

That block about the owner_id does not belong to that function, it's specific to the RNA registration code and should be kept there.

That block about the `owner_id` does not belong to that function, it's specific to the RNA registration code and should be kept there.
WM_paneltype_add(pt);
Review

This should also be left out of this function, since it is not relevant to parenting a panel to another one, and not all panels need to be registered globally at the WM level.

This should also be left out of this function, since it is not relevant to parenting a panel to another one, and not all panels need to be registered globally at the WM level.
}
void WM_paneltype_remove(PanelType *pt)
{

@ -1 +1 @@
Subproject commit e133fc08cd3254bb3d3bd1345028c8486700bca4
Subproject commit 27826b4aed138b7e3aed882d0eab96740c3a55c7
Review

This should not be here, in fact this has been removed recently, you need to update your patch against latest main branch.

This should not be here, in fact this has been removed recently, you need to update your patch against latest `main` branch.
Review

Sir In my 2nd commit there is no such submodule. Updated my main branch. Now For removing this should I need to change my branch and then put another PR?

Sir In my 2nd commit there is no such submodule. Updated my main branch. Now For removing this should I need to change my branch and then put another PR?
Review

Yes just rebase on latest main branch, and force-push on your fork.

Yes just rebase on latest `main` branch, and force-push on your fork.