Add a ShadowedRectangle item
ClosedPublic

Authored by ahiemstra on Wed, Mar 11, 3:19 PM.

Details

Summary

This adds a ShadowedRectangle item, which is a rectangle with a shadow.
It uses a custom shader that draws the rectangle and the shadow below it
using distance fields, which has significantly better performance compared
to the DropShadow effect. It also supports rounded corners, which the
current Card code does not.

This is a first step to moving more of AbstractCard and related items to
C++ code. Other bits will include a ShadowedImage item and moving actual
card code to C++.

Test Plan

Screenshot of test program showing ShadowedRectangle, Rectangle with DropShadow effect and empty Kirigami Card.

Rounded corners.

Performance comparison:

The video at top is using Rectangle with DropShadow, the one below that ShadowedRectangle.

Diff Detail

Repository
R169 Kirigami
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
ahiemstra created this revision.Wed, Mar 11, 3:19 PM
Restricted Application added a project: Kirigami. · View Herald TranscriptWed, Mar 11, 3:19 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
ahiemstra requested review of this revision.Wed, Mar 11, 3:19 PM
ahiemstra edited the summary of this revision. (Show Details)Wed, Mar 11, 3:50 PM
ahiemstra edited the test plan for this revision. (Show Details)
zzag added a subscriber: zzag.EditedWed, Mar 11, 4:08 PM

Are there any significant differences between shadows that were generated using distance fields and shadows that were generated with a blur filter(e.g. box blur or stack blur, etc)? (asking out of curiosity)

EDIT: Urgh, never mind. You've just updated the test plan.

Yeah I can't upload screenshots etc. through Arc so I always need to upload those afterwards.

ahiemstra updated this revision to Diff 77427.Wed, Mar 11, 4:27 PM
  • Add a manual test
cblack added a subscriber: cblack.Wed, Mar 11, 4:32 PM

I feel like a border property would be desirable for the following usecases:

  • Cards that have no elevation when resting
  • Fallback for when shadows are too heavy

How does the shadow look and perform when animating?

This revision was not accepted when it landed; it landed in state Needs Review.Wed, Mar 11, 4:38 PM
This revision was automatically updated to reflect the committed changes.
ahiemstra reopened this revision.Wed, Mar 11, 4:45 PM

Argh I hate arc

I feel like a border property would be desirable for the following usecases:

  • Cards that have no elevation when resting
  • Fallback for when shadows are too heavy

The fallback case is not going to be relevant, a border is going to be as heavy as the shadow is with this approach. But I'm fine with adding a border, also to make it behave more like Rectangle in general.

How does the shadow look and perform when animating?

Animating what?

How does the shadow look and perform when animating?

Animating what?

Attributes of a shadow (size/radius, offsets)

ahiemstra updated this revision to Diff 77436.Wed, Mar 11, 4:55 PM
  • Convert to SPDX identifiers

Attributes of a shadow (size/radius, offsets)

Performance isn't going to be much different between any of these properties, except that a few will be slightly faster because they won't need to resize geometry.

For appearance:

ahiemstra updated this revision to Diff 77446.Wed, Mar 11, 6:15 PM
  • Remove QRectF parameter from ShadowedRectNode ctor
  • Properly initialize offset and aspect ratio variables of ShadowedRectNode
mart added a subscriber: mart.Wed, Mar 11, 7:25 PM

tested it locally, works beautifully

mart requested changes to this revision.Thu, Mar 12, 11:42 AM

to me is good, would just change that one thing api wise.
do you think there are other blockers from a technical pov or good to go?

src/shadowedrectangle.h
16

shadowSize to correspond with shadowColor

This revision now requires changes to proceed.Thu, Mar 12, 11:42 AM

I've been adding some documentation, in addition to border properties. With that I'm fairly sure this is ready.

ahiemstra added inline comments.Thu, Mar 12, 11:59 AM
src/shadowedrectangle.h
16

I've actually been pondering making it a grouped property, it would make it more similar to border.

So then you'd have:

ShadowedRectangle {
    shadow {
        size: 10
        color: "red"
        xOffset: 10
        yOffset: 10
    }
}
ahiemstra updated this revision to Diff 77504.Thu, Mar 12, 1:26 PM
  • Documentation
  • Add support for rendering a border
ahiemstra updated this revision to Diff 77506.Thu, Mar 12, 1:56 PM
  • Convert shadow properties of ShadowedRectangle to a grouped property
ahiemstra marked an inline comment as done.Thu, Mar 12, 1:58 PM
ahiemstra added inline comments.
src/shadowedrectangle.h
16

Done that now.

ahiemstra retitled this revision from [WIP] Add a ShadowedRectangle item to Add a ShadowedRectangle item.Thu, Mar 12, 2:03 PM

With that, I think this is now completely ready.

mart accepted this revision.Thu, Mar 12, 5:04 PM
This revision is now accepted and ready to land.Thu, Mar 12, 5:04 PM
This revision was automatically updated to reflect the committed changes.