Page MenuHome

UI: option to flip X/Y preview icons for 'template_asset_view'
Needs ReviewPublic

Authored by Campbell Barton (campbellbarton) on Mar 28 2021, 4:10 PM.

Details

Summary

Support for drawing flipped preview icons.

Add icon_flip argument to Layout.template_asset_view.


NOTE: this applies to the asset-browser-poselib branch 9c6eea6034869be035440849fc7d58ff89bd7333

This is a proof of concept patch to support flipping preview images in the UI.

The patch is in response to a request to flip icons for accessing pose libraries which have the option to flip poses.
To avoid storing copies of flipped images, they can be drawn flipped.


To test flipping in the file-selector, this script sets the value:

for area in bpy.context.screen.areas:
    if area.type == 'FILE_BROWSER':
        area.spaces[0].params.preview_flip = {'X'}

Open Topics

  • We could use a struct for storing preview preview transformation to avoid having to add more arguments in the future.
  • If the intention is only to use this for preview icons, the internal variable name could be changed from icon_flip to preview_icon_flip.
  • Currently some icon types (vector icons for example), don't flip but could be supported.
  • We could handle this at a different level (flip the preview data after loading for example).

Diff Detail

Repository
rB Blender
Branch
TEMP-ICON-FLIP (branched from master)
Build Status
Buildable 13773
Build 13773: arc lint + arc unit

Event Timeline

Campbell Barton (campbellbarton) requested review of this revision.Mar 28 2021, 4:10 PM
Campbell Barton (campbellbarton) created this revision.
Sybren A. Stüvel (sybren) requested changes to this revision.Mar 29 2021, 12:44 PM
Sybren A. Stüvel (sybren) added inline comments.
source/blender/editors/include/UI_interface.h
1917

I'm guessing that value should be a combination of UI_ICON_XFORM_FLIP_X and UI_ICON_XFORM_FLIP_Y. This should be documented.

source/blender/editors/include/UI_interface_icons.h
87

I'm guessing that value should be a combination of UI_ICON_XFORM_FLIP_X and UI_ICON_XFORM_FLIP_Y. This should be documented.

source/blender/editors/interface/interface.c
4161–4163

I don't understand this condition. Why shouldn't this function set but->icon_transform=0 when it's called with icon_transform=0?

source/blender/editors/interface/interface_intern.h
643

Same as above, document where the icon_transform values come from.

source/blender/editors/interface/interface_layout.c
176

Same as above, document.

This revision now requires changes to proceed.Mar 29 2021, 12:44 PM

I think the limitations are fine for our current use case, by the way. Maybe they should be documented in the code, though, so that it's clearer what the limitations are, and in which area of the code they could be addressed? Not vital for acceptance of this patch IMO.

Campbell Barton (campbellbarton) retitled this revision from UI: option to flip X/Y preview icons to UI: option to flip X/Y preview icons for 'template_asset_view'.
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)

Updated the patch to use an argument to Layout.template_asset_view.

Julian Eisel (Severin) accepted this revision.EditedApr 7 2021, 3:49 PM

Thanks for working on this!

  • We could use a struct for storing preview preview transformation to avoid having to add more arguments in the future.

Don't think this is needed. I don't see much reason for more advanced transformations.

  • Currently no popup support, no support in the file browser.

What do you mean with popup support?
File Browser support is the most important thing right now.

  • We could handle this at a different level (flip the preview data after loading for example).

Managing the preview data is already problematic: Threaded rendering + undo/redo (they are ID data), shared data-structures but partially separate code paths with .py preview icons, deferred loading from OS thumbnail cache, complex ownership... Generally I'd prefer not to add more complexity.

release/scripts/startup/bl_ui/space_view3d.py
7003–7024 ↗(On Diff #35813)

I removed this panel in the asset-browser-poselib branch. We use the panel from the pose library addon now (also asset-browser-poselib branch)

Thanks for working on this!

  • We could use a struct for storing preview preview transformation to avoid having to add more arguments in the future.

Don't think this is needed. I don't see much reason for more advanced transformations.

  • Currently no popup support, no support in the file browser.

What do you mean with popup support?

Preview icons can show in regions generated by an enum popop - any template_preview for example.

File Browser support is the most important thing right now.

Perhaps best handle this in chat, I need a use-case to test this.

  • We could handle this at a different level (flip the preview data after loading for example).

Managing the preview data is already problematic: Threaded rendering + undo/redo (they are ID data), shared data-structures but partially separate code paths with .py preview icons, deferred loading from OS thumbnail cache, complex ownership... Generally I'd prefer not to add more complexity.

Yep, it seems unnecessarily complicated in that case.

Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)
  • Preview flipping in the file-selector
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)

Updating without arc, for some reason it's including many unrelated changes.

Julian Eisel (Severin) added inline comments.
release/scripts/startup/bl_ui/space_view3d.py
7018–7039 ↗(On Diff #36399)

Better remove this before committing, it's not needed anymore for the asset-browser-poselib branch.

Sybren A. Stüvel (sybren) requested changes to this revision.May 3 2021, 10:57 AM

Updating without arc, for some reason it's including many unrelated changes.

When you do this, please pass -U1000 or some other ridiculousy high number. That way Phabricator can show the context of the patch hunks.

source/blender/editors/space_file/file_draw.c
391–401 ↗(On Diff #36426)

This approach is quite inconsistent with interface_icons.c. In that function cognitive complexity was increased by wrapping everything in a if (icon_flip_flag) block, presumably to save a CPU tick or two. I'm personally not a fan, as I like the cognitive complexity to be low, but if it's really important for performance I think it's okay. However, here that performance apparently doesn't matter at all any more. Either keep interface_icons.c simpler or also change this function so that it's equally performant.

source/blender/makesrna/intern/rna_modifier.c
599–600 ↗(On Diff #36426)

This ought to use the symbols from eIconFlip.

If there is really, really, really a convincing reason that these symbols cannot be used here, it should be heavily documented on both sides that the values are repeated here, why they are repeated here, with a warning that they should be kept in sync.

source/blender/makesrna/intern/rna_ui_api.c
627 ↗(On Diff #36426)

const

This revision now requires changes to proceed.May 3 2021, 10:57 AM
Campbell Barton (campbellbarton) marked an inline comment as done.
  • Minor updates
source/blender/editors/space_file/file_draw.c
391–401 ↗(On Diff #36426)

The reason for the difference between the two functions is variable reuse, here - as other non-flipped icons are drawn below.

The if (icon_flip_flag) was in anticipation that flipping may do other things, it turns out it's not especially useful so it can go.

Often I find it simpler when exceptional cases are added into their own block, then when reading code it's easy to skip past cases you know aren't in the code-path you're investigating.

source/blender/makesrna/intern/rna_modifier.c
599–600 ↗(On Diff #36426)

These are just axis-flags, non-icon code should use them too.

Added a comment to eIconFlip noting that the values represent axes and are used by an RNA enum.

Sybren A. Stüvel (sybren) requested changes to this revision.May 3 2021, 1:55 PM

This ought to use the symbols from eIconFlip.

This note hasn't been handled, or even replied to.

This revision now requires changes to proceed.May 3 2021, 1:55 PM
Campbell Barton (campbellbarton) marked an inline comment as not done.May 3 2021, 3:22 PM

This ought to use the symbols from eIconFlip.

This note hasn't been handled, or even replied to.

Accidentally left the reply unsubmitted, done now.

This revision is now accepted and ready to land.May 3 2021, 3:53 PM
.arcconfig
5 ↗(On Diff #36727)

Curious why you need this? arc diff branchname should work, and arc land --onto branchname for landing. Or do you want to avoid having to do that?

.arcconfig
5 ↗(On Diff #36727)

I needed this to perform arc diff --update D10843

Sybren A. Stüvel (sybren) requested changes to this revision.May 4 2021, 2:31 PM
Sybren A. Stüvel (sybren) added inline comments.
.arcconfig
5 ↗(On Diff #36727)

You can use arc diff --base git:some-commit-or-branch --update Dxxxxx to create a diff against an arbitrary branch or commit. This change certainly shouldn't be part of this patch.

This revision now requires changes to proceed.May 4 2021, 2:31 PM
  • Add description to icon_flip.
  • Improve docstring for eIconFlip.
  • Remove .arcconfig changes.

@Sybren A. Stüvel (sybren) where there any outstanding issues you wanted to check over?

Otherwise I don't think the minor issue with .arcconfig requires an extra review iteration. It can be removed from the final commit easily enough.

To test flipping in the file-selector, this script sets the value

I've tried it with the following code in an Asset Browser panel, and that works as well:

def draw(self, context: Context) -> None:
    layout = self.layout
    wm = context.window_manager
    if wm.poselib_flipped:
        preview_flip = {'X'}
    else:
        preview_flip = set()
    context.space_data.params.preview_flip = preview_flip

Is this the best way to deal with this? Or would you expect to have some update-callback on the window_manager.poselib_flipped property that handles this?

How would you handle this in the UIList asset view template?

To test flipping in the file-selector, this script sets the value

I've tried it with the following code in an Asset Browser panel, and that works as well:

def draw(self, context: Context) -> None:
    layout = self.layout
    wm = context.window_manager
    if wm.poselib_flipped:
        preview_flip = {'X'}
    else:
        preview_flip = set()
    context.space_data.params.preview_flip = preview_flip

Is this the best way to deal with this? Or would you expect to have some update-callback on the window_manager.poselib_flipped property that handles this?

As far as I know yes. And I'm not satisfied with this.

It has the down-side that if we somehow save this setting and the file selector is used in some other context, the user could have inexplicably flipped previews.

A better solution likely involves customizable properties that control settings like this, something the code that uses the file selector can control.

How would you handle this in the UIList asset view template?

Unless there is some other UIList usage for assets: template_asset_view takes a boolean argument for this, there was an example panel & list in earlier versions of this patch - for testing.

I'd expect the flag to be runtime only data (it isn't in this current patch). It is just a drawing-flag really.