Clickable area of Current File Assets in 'template_asset_view' is reduced when no 'drag_operator' is used #102856

Closed
opened 2022-11-29 18:00:44 +01:00 by Mysteryem · 5 comments

System Information
Operating system: Windows-10-10.0.19045-SP0 64 Bits
Graphics card: NVIDIA GeForce GTX 1070 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 516.94

Blender Version
Broken: version: 3.3.1, branch: master, commit date: 2022-10-04 18:35, hash: b292cfe5a9 and 3.3.2 Release Candidate, branch: master, commit date: 2022-11-24 14:33, hash: 2124bfb211
Worked: (newest version of Blender that worked as expected)

Short description of error
The clickable area of Current File Assets in template_asset_view is reduced when no drag_operator is used. To be precise, it looks like the clickable area of the text and asset preview isn't expanding with UI. The green regions roughly show the clickable area of the Cube asset in both Panels: image.png

Exact steps for others to reproduce the error

  • Open the attached .blend (authored in 3.3.1, it has the default Camera, Cube and Light marked as Assets and a script to run in the Text Editor)
  • Run the script in the Text Editor to create two Operators and two Panels shown in the Test category of the UI region (right shelf) of the 3D View.

Observe the difference in the clickable area of Current File Assets in both Panels (the ActivateAsset Operator will report whenever an Asset is clicked on and expanding the width of the Panels makes the issue more obvious).

template_asset_view_drag_test.blend
The included script is reproduced below:

import bpy


class ActivateAsset(bpy.types.Operator):
    bl_idname = 'test.activate_asset'
    bl_label = "Test Activate"
    
    @classmethod
    def poll(cls, context):
        return context.asset_file_handle is not None
    
    def execute(self, context):
        asset = context.asset_file_handle
        self.report({'INFO'}, f"Activated asset '{asset.name}'")
        return {'FINISHED'}


class DragAsset(bpy.types.Operator):
    bl_idname = 'test.drag_asset'
    bl_label = "Test Drag"
    
    @classmethod
    def poll(cls, context):
        return context.asset_file_handle is not None
    
    def execute(self, context):
        asset = context.asset_file_handle
        self.report({'INFO'}, f"Dragged asset '{asset.name}'")
        return {'FINISHED'}


def draw_asset_view(self, context, use_drag):
    layout = self.layout
    workspace = context.workspace
    wm = context.window_manager
    if use_drag:
        drag_operator=DragAsset.bl_idname
    else:
        drag_operator=""
    - list_id must be unique otherwise behaviour gets weird when the template_asset_view is shown twice
    - (drag operator stops working in AssetPanelDrag, clickable area of all Assets in AssetPanelNoDrag gets
    - reduced to below the Asset name and clickable area of Current File Assets in AssetPanelDrag gets
    - reduced as if it didn't have a drag operator)
    list_id = "test_assets_drag" if use_drag else "test_assets_no_drag"
    _activate_op_props, _drag_op_props = layout.template_asset_view(
        list_id,
        workspace,
        "asset_library_ref",
        wm,
        "test_assets",
        wm,
        "test_active_index",
        activate_operator=ActivateAsset.bl_idname,
        drag_operator=drag_operator,
    )


class AssetPanelDrag(bpy.types.Panel):
    bl_idname = 'TEST_PT_asset_panel_drag'
    bl_label = "Panel With Drag"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Test"
    
    def draw(self, context):
        draw_asset_view(self, context, True)


class AssetPanelNoDrag(bpy.types.Panel):
    bl_idname = 'TEST_PT_asset_panel_no_drag'
    bl_label = "Without Drag"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Test"
    
    def draw(self, context):
        draw_asset_view(self, context, False)
    
    

bpy.types.WindowManager.test_assets = bpy.props.CollectionProperty(type=bpy.types.AssetHandle)
bpy.types.WindowManager.test_active_index = bpy.props.IntProperty()
bpy.utils.register_class(ActivateAsset)
bpy.utils.register_class(DragAsset)
bpy.utils.register_class(AssetPanelDrag)
bpy.utils.register_class(AssetPanelNoDrag)
**System Information** Operating system: Windows-10-10.0.19045-SP0 64 Bits Graphics card: NVIDIA GeForce GTX 1070 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 516.94 **Blender Version** Broken: version: 3.3.1, branch: master, commit date: 2022-10-04 18:35, hash: `b292cfe5a9` and 3.3.2 Release Candidate, branch: master, commit date: 2022-11-24 14:33, hash: `2124bfb211` Worked: (newest version of Blender that worked as expected) **Short description of error** The clickable area of Current File Assets in `template_asset_view` is reduced when no drag_operator is used. To be precise, it looks like the clickable area of the text and asset preview isn't expanding with UI. The green regions roughly show the clickable area of the Cube asset in both Panels: ![image.png](https://archive.blender.org/developer/F13979348/image.png) **Exact steps for others to reproduce the error** - Open the attached .blend (authored in 3.3.1, it has the default Camera, Cube and Light marked as Assets and a script to run in the Text Editor) - Run the script in the Text Editor to create two Operators and two Panels shown in the `Test` category of the `UI` region (right shelf) of the 3D View. # Observe the difference in the clickable area of Current File Assets in both Panels (the ActivateAsset Operator will report whenever an Asset is clicked on and expanding the width of the Panels makes the issue more obvious). [template_asset_view_drag_test.blend](https://archive.blender.org/developer/F13979369/template_asset_view_drag_test.blend) The included script is reproduced below: ``` import bpy class ActivateAsset(bpy.types.Operator): bl_idname = 'test.activate_asset' bl_label = "Test Activate" @classmethod def poll(cls, context): return context.asset_file_handle is not None def execute(self, context): asset = context.asset_file_handle self.report({'INFO'}, f"Activated asset '{asset.name}'") return {'FINISHED'} class DragAsset(bpy.types.Operator): bl_idname = 'test.drag_asset' bl_label = "Test Drag" @classmethod def poll(cls, context): return context.asset_file_handle is not None def execute(self, context): asset = context.asset_file_handle self.report({'INFO'}, f"Dragged asset '{asset.name}'") return {'FINISHED'} def draw_asset_view(self, context, use_drag): layout = self.layout workspace = context.workspace wm = context.window_manager if use_drag: drag_operator=DragAsset.bl_idname else: drag_operator="" - list_id must be unique otherwise behaviour gets weird when the template_asset_view is shown twice - (drag operator stops working in AssetPanelDrag, clickable area of all Assets in AssetPanelNoDrag gets - reduced to below the Asset name and clickable area of Current File Assets in AssetPanelDrag gets - reduced as if it didn't have a drag operator) list_id = "test_assets_drag" if use_drag else "test_assets_no_drag" _activate_op_props, _drag_op_props = layout.template_asset_view( list_id, workspace, "asset_library_ref", wm, "test_assets", wm, "test_active_index", activate_operator=ActivateAsset.bl_idname, drag_operator=drag_operator, ) class AssetPanelDrag(bpy.types.Panel): bl_idname = 'TEST_PT_asset_panel_drag' bl_label = "Panel With Drag" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = "Test" def draw(self, context): draw_asset_view(self, context, True) class AssetPanelNoDrag(bpy.types.Panel): bl_idname = 'TEST_PT_asset_panel_no_drag' bl_label = "Without Drag" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = "Test" def draw(self, context): draw_asset_view(self, context, False) bpy.types.WindowManager.test_assets = bpy.props.CollectionProperty(type=bpy.types.AssetHandle) bpy.types.WindowManager.test_active_index = bpy.props.IntProperty() bpy.utils.register_class(ActivateAsset) bpy.utils.register_class(DragAsset) bpy.utils.register_class(AssetPanelDrag) bpy.utils.register_class(AssetPanelNoDrag) ```
Author

Added subscriber: @Mysteryem-2

Added subscriber: @Mysteryem-2

Added subscribers: @JulianEisel, @mano-wii

Added subscribers: @JulianEisel, @mano-wii

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

I can confirm the problem.
template_asset_view has been implemented in 8925d3b7bf
So @JulianEisel would be the best person to take a look at?

I can confirm the problem. `template_asset_view` has been implemented in 8925d3b7bf So @JulianEisel would be the best person to take a look at?
Philipp Oeser removed the
Interest
User Interface
label 2023-02-10 09:21:27 +01:00
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2023-10-19 12:10:32 +02:00
Member

Note that 4.0 now includes the asset shelf which will replace the asset view template at some point. There's a Ui asset shelf template available for it in the script editor.


Also, slightly updated script for 4.0 breaking changes:

import bpy


class ActivateAsset(bpy.types.Operator):
    bl_idname = 'test.activate_asset'
    bl_label = "Test Activate"
    
    @classmethod
    def poll(cls, context):
        return context.asset is not None
    
    def execute(self, context):
        asset = context.asset
        self.report({'INFO'}, f"Activated asset '{asset.name}'")
        return {'FINISHED'}


class DragAsset(bpy.types.Operator):
    bl_idname = 'test.drag_asset'
    bl_label = "Test Drag"
    
    @classmethod
    def poll(cls, context):
        return context.asset is not None
    
    def execute(self, context):
        asset = context.asset
        self.report({'INFO'}, f"Dragged asset '{asset.name}'")
        return {'FINISHED'}


def draw_asset_view(self, context, use_drag):
    layout = self.layout
    workspace = context.workspace
    wm = context.window_manager
    if use_drag:
        drag_operator=DragAsset.bl_idname
    else:
        drag_operator=""
    # list_id must be unique otherwise behaviour gets weird when the template_asset_view is shown twice
    # (drag operator stops working in AssetPanelDrag, clickable area of all Assets in AssetPanelNoDrag gets
    # reduced to below the Asset name and clickable area of Current File Assets in AssetPanelDrag gets
    # reduced as if it didn't have a drag operator)
    list_id = "test_assets_drag" if use_drag else "test_assets_no_drag"
    _activate_op_props, _drag_op_props = layout.template_asset_view(
        list_id,
        workspace,
        "asset_library_reference",
        wm,
        "test_assets",
        wm,
        "test_active_index",
        activate_operator=ActivateAsset.bl_idname,
        drag_operator=drag_operator,
    )


class AssetPanelDrag(bpy.types.Panel):
    bl_idname = 'TEST_PT_asset_panel_drag'
    bl_label = "Panel With Drag"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Test"
    
    def draw(self, context):
        draw_asset_view(self, context, True)


class AssetPanelNoDrag(bpy.types.Panel):
    bl_idname = 'TEST_PT_asset_panel_no_drag'
    bl_label = "Without Drag"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Test"
    
    def draw(self, context):
        draw_asset_view(self, context, False)
    
    

bpy.types.WindowManager.test_assets = bpy.props.CollectionProperty(type=bpy.types.AssetHandle)
bpy.types.WindowManager.test_active_index = bpy.props.IntProperty()
bpy.utils.register_class(ActivateAsset)
bpy.utils.register_class(DragAsset)
bpy.utils.register_class(AssetPanelDrag)
bpy.utils.register_class(AssetPanelNoDrag)
Note that 4.0 now includes the asset shelf which will replace the asset view template at some point. There's a _Ui asset shelf_ template available for it in the script editor. ---- Also, slightly updated script for [4.0 breaking changes](https://wiki.blender.org/wiki/Reference/Release_Notes/4.0/Python_API#Breaking_changes): ```python import bpy class ActivateAsset(bpy.types.Operator): bl_idname = 'test.activate_asset' bl_label = "Test Activate" @classmethod def poll(cls, context): return context.asset is not None def execute(self, context): asset = context.asset self.report({'INFO'}, f"Activated asset '{asset.name}'") return {'FINISHED'} class DragAsset(bpy.types.Operator): bl_idname = 'test.drag_asset' bl_label = "Test Drag" @classmethod def poll(cls, context): return context.asset is not None def execute(self, context): asset = context.asset self.report({'INFO'}, f"Dragged asset '{asset.name}'") return {'FINISHED'} def draw_asset_view(self, context, use_drag): layout = self.layout workspace = context.workspace wm = context.window_manager if use_drag: drag_operator=DragAsset.bl_idname else: drag_operator="" # list_id must be unique otherwise behaviour gets weird when the template_asset_view is shown twice # (drag operator stops working in AssetPanelDrag, clickable area of all Assets in AssetPanelNoDrag gets # reduced to below the Asset name and clickable area of Current File Assets in AssetPanelDrag gets # reduced as if it didn't have a drag operator) list_id = "test_assets_drag" if use_drag else "test_assets_no_drag" _activate_op_props, _drag_op_props = layout.template_asset_view( list_id, workspace, "asset_library_reference", wm, "test_assets", wm, "test_active_index", activate_operator=ActivateAsset.bl_idname, drag_operator=drag_operator, ) class AssetPanelDrag(bpy.types.Panel): bl_idname = 'TEST_PT_asset_panel_drag' bl_label = "Panel With Drag" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = "Test" def draw(self, context): draw_asset_view(self, context, True) class AssetPanelNoDrag(bpy.types.Panel): bl_idname = 'TEST_PT_asset_panel_no_drag' bl_label = "Without Drag" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = "Test" def draw(self, context): draw_asset_view(self, context, False) bpy.types.WindowManager.test_assets = bpy.props.CollectionProperty(type=bpy.types.AssetHandle) bpy.types.WindowManager.test_active_index = bpy.props.IntProperty() bpy.utils.register_class(ActivateAsset) bpy.utils.register_class(DragAsset) bpy.utils.register_class(AssetPanelDrag) bpy.utils.register_class(AssetPanelNoDrag) ```
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#102856
No description provided.