From 468baef5c8ba66eb52741e30dc1a52a03f8c389a Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 31 May 2024 12:11:04 +0500 Subject: [PATCH] materials ui - make expanding/contracting categories more natural Previously if you had some item active before the category you're trying to expand/cotract it would jump back to that item which was confusing. Now it sets contracted/expanded category as active to prevent that jump. Before - https://imgur.com/a/87ZDnVq After - https://imgur.com/a/B9WOn8I In Blender when we reload materials in collection property it's resetting scroll position in the template_list and setting it based template_list index, so the only way to preserve the scroll position is to manipulate template_list index. --- .../blenderbim/bim/module/material/operator.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/material/operator.py b/src/blenderbim/blenderbim/bim/module/material/operator.py index 4578562b7e..000aad780f 100644 --- a/src/blenderbim/blenderbim/bim/module/material/operator.py +++ b/src/blenderbim/blenderbim/bim/module/material/operator.py @@ -705,8 +705,12 @@ class ExpandMaterialCategory(bpy.types.Operator): def execute(self, context): props = context.scene.BIMMaterialProperties - for category in [c for c in props.materials if c.is_category and c.name == self.category]: + for index, category in [ + (i, c) for i, c in enumerate(props.materials) + if c.is_category and c.name == self.category + ]: category.is_expanded = True + props.active_material_index = index core.load_materials(tool.Material, props.material_type) return {"FINISHED"} @@ -719,8 +723,12 @@ class ContractMaterialCategory(bpy.types.Operator): def execute(self, context): props = context.scene.BIMMaterialProperties - for category in [c for c in props.materials if c.is_category and c.name == self.category]: + for index, category in [ + (i, c) for i, c in enumerate(props.materials) + if c.is_category and c.name == self.category + ]: category.is_expanded = False + props.active_material_index = index core.load_materials(tool.Material, props.material_type) return {"FINISHED"}