Skip to content

Adds CSS support for shadows and a simpler way of defining shadows in XAML #27180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 12, 2025

Conversation

sthewissen
Copy link
Contributor

Description of Change

Added support for a new -maui-shadow CSS property which can be used to initialize a Shadow on a VisualElement. This also introduces a new ShadowTypeConverter that allows for 3 different ways to initialize a Shadow. These have been kept in line as much as possible with the existing guidelines on box-shadows in CSS.

-maui-shadow: #000000 4 4; // color, offset X, offset Y
-maui-shadow: 4 4 16 #000000;  // offset X, offset Y, radius, color
-maui-shadow: 4 4 16 #000000 0.5;  // offset X, offset Y, radius, color, opacity

Or in XAML:

<VerticalStackLayout BackgroundColor="#fff" Shadow="4 4 16 #000000" />

Issues Fixed

This currently contains a basic implementation for #27157.

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jan 16, 2025
@@ -0,0 +1,141 @@
#nullable disable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be

Suggested change
#nullable disable
#nullable enable

?

@sthewissen
Copy link
Contributor Author

sthewissen commented Jan 20, 2025

Added support for the various solid color implementations;

#000000 4 4
rgb(6, 201, 198) 4 4
rgba(6, 201, 188, 0.2) 4 8
hsl(6, 20%, 45%) 1 5
hsla(6, 20%, 45%,0.75) 6 3
rgb(100%, 32%, 64%) 8 5
rgba(100%, 32%, 64%,0.27) 16 5

EDIT: I still want to improve this a bit to also allow X11 named colors and HSV/HSVA.

fuchsia 4 4
hsv(6, 20%, 45%) 1 5
hsva(6, 20%, 45%,0.75) 6 3

@sthewissen
Copy link
Contributor Author

Updated color parsing for more color support.

Type Format Remark
HEX #rgb, #argb, #rrggbb, #aarrggbb
RGB rgb(255,0,0), rgb(100%,0%,0%) values in range 0-255 or 0%-100%
RGBA rgba(255, 0, 0, 0.8), rgba(100%, 0%, 0%, 0.8) opacity is 0.0-1.0
HSL hsl(120, 100%, 50%)
HSLA hsla(120, 100%, 50%, .8) opacity is 0.0-1.0
HSV hsv(120, 100%, 50%) h is 0-360, s and v are 0%-100%
HSVA hsva(120, 100%, 50%, .8) opacity is 0.0-1.0
Predefined color fuchsia, AquaMarine, limegreen case insensitive

@sthewissen
Copy link
Contributor Author

sthewissen commented Jan 21, 2025

While I'd love to get individual property support through CSS in there, it might be a bit of a big change to pull off in the short term. Therefore I'm setting this as ready for review to get the basic support rolling. We can then improve upon it in the future after giving the best solution some more thought.

@sthewissen sthewissen marked this pull request as ready for review January 21, 2025 15:20
@sthewissen sthewissen requested a review from a team as a code owner January 21, 2025 15:20
@jfversluis
Copy link
Member

jfversluis commented Jan 22, 2025

/azp run

This comment was marked as outdated.

3 similar comments

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as off-topic.

@jfversluis jfversluis added the area-xaml XAML, CSS, Triggers, Behaviors label Jan 23, 2025
@jfversluis jfversluis added this to the .NET 9 SR4 milestone Jan 23, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen modified the milestones: .NET 9 SR4, .NET 9 SR5 Feb 4, 2025
@mattleibow
Copy link
Member

#27157 (comment)

jsuarezruiz
jsuarezruiz previously approved these changes Feb 5, 2025
@jsuarezruiz
Copy link
Contributor

jsuarezruiz commented Feb 6, 2025

/azp run

This comment was marked as off-topic.

@jsuarezruiz

This comment was marked as outdated.

@jsuarezruiz

This comment was marked as off-topic.

@jfversluis jfversluis force-pushed the sthewissen/shadow-css branch from 8e69851 to 79c5933 Compare February 10, 2025 09:11
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@mattleibow
Copy link
Member

Should this be targeting .NET 10 since it is a new thing? If we are to target .NET 9/main, then the converter will have to be internal. We can always merge the converter as internal, and then open an issue to make it public in net 10 once main is merged up to net10.

@sthewissen
Copy link
Contributor Author

Should this be targeting .NET 10 since it is a new thing? If we are to target .NET 9/main, then the converter will have to be internal. We can always merge the converter as internal, and then open an issue to make it public in net 10 once main is merged up to net10.

If making it internal gets it in faster I'm all for it @mattleibow :)

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jfversluis jfversluis self-assigned this Feb 11, 2025
/// <summary>
/// Type converter for converting a properly formatted string to a Shadow.
/// </summary>
internal class ShadowTypeConverter : TypeConverter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make ShadowTypeConverter public and enabled nullable references #nullable enable

@mattleibow mattleibow merged commit b27ff1d into dotnet:main Feb 12, 2025
125 checks passed
@sthewissen sthewissen deleted the sthewissen/shadow-css branch February 13, 2025 07:57
@github-actions github-actions bot locked and limited conversation to collaborators Mar 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-xaml XAML, CSS, Triggers, Behaviors community ✨ Community Contribution
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants