Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Enhancement] Brushes #9220

Merged
merged 96 commits into from Jul 17, 2020
Merged

[Enhancement] Brushes #9220

merged 96 commits into from Jul 17, 2020

Conversation

jsuarezruiz
Copy link
Contributor

@jsuarezruiz jsuarezruiz commented Jan 15, 2020

Description of Change

Added Brushes support. A Brush "paints" an area with its output. Different brushes have different types of output. Some brushes paint an area with a solid color and others with a gradient.

gradients2

Examples:

Using the new Background property you can set the background of any Page, Layout or View using a Brush.

<Grid>
    <Grid.Background>
        <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
            <GradientStop Color="Yellow" Offset="0.0" />
            <GradientStop Color="Red" Offset="0.25" />
            <GradientStop Color="Blue" Offset="0.75" />
            <GradientStop Color="LimeGreen" Offset="1.0" />
        </LinearGradientBrush>
    </Grid.Background>
<Grid>

Issues Resolved

API Changes

Added:

public abstract class Brush : BindableObject
{

}

GradientBrush

public class GradientBrush : Brush
{
    public IList<GradientStop> GradientStops { get; set; }
}

GradientStop

public class GradientStop : BindableObject
{
    public Color Color { get; set; }

    public float Offset { get; set; }
}

SolidColorBrush

public class SolidColorBrush : GradientBrush
{

}

LinearGradientBrush

public class LinearGradientBrush : GradientBrush
{
    public Point StartPoint { get; set; }

    public Point EndPoint { get; set; }
}

RadialGradientBrush

public class RadialGradientBrush : GradientBrush
{
    public Point Center { get; set; }

    public double Radius { get; set; }
}

Platforms Affected

  • Core/XAML (all platforms)
  • iOS
  • Android
  • macOS
  • UWP
  • WPF

Behavioral/Visual Changes

None

Testing Procedure

Launch Core Gallery and navigate to the new Gradients Gallery.

Screenshots

solidcolorbrush

lineargradientbrush-h

lineargradientbrush-v

macos-brushes

css-gradient2

Notes

  • BackgroundColor property will be deprecated.

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)

@jcmanke
Copy link
Contributor

jcmanke commented Feb 5, 2020

What should happen with the BackgroundColor property?. In the current state of the PR can use BackgroundColor (Color) and Background (Brush) properties at the same time. If both properties are used, BackgroundColor is ignored, but should we deprecate BackgroundColor?

Basically, I don't want to ever create a SolidColorBrush object in either XAML or code, I just want to specify the color. There should be an implicit converter so that Background = Color.Blue works. (If this is already included, great. I haven't looked through the files yet.)

@jsuarezruiz
Copy link
Contributor Author

@jcmanke This PR is still a Draft and we continue working on it so, thanks for your feedback. A TypeConverter was added to allow Background="Red".

@MichaelStgt
Copy link

I had a closer look at the source and the sample inside the Gallery.
I assume that x = 0 and y = 0 is the upper left corner of the Element.

Your example contains two for a LinearGradientBrush, where one is

**HorizontalLinearGradient**
StartPoint="0, 0"
EndPoint="1, 0"

and the other one is

**VerticalLinearGradient**
StartPoint="0, 0"
EndPoint="0, 1"

But should it not be like this:

**FromTopLeftToBottomRight (diagonal)**
StartPoint="0, 0"
EndPoint="1, 1"
**HorizontalLinearGradient**
StartPoint="0.5, 0"
EndPoint="0.5, 1"
**VerticalLinearGradient**
StartPoint="0, 0.5"
EndPoint="1, 0.5"
**FromTopRightToBottomLeft (diagonal)**
StartPoint="1, 0"
EndPoint="0, 1"

@jsuarezruiz jsuarezruiz marked this pull request as ready for review February 13, 2020 17:27
Copy link
Contributor

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

Looks like this is failing the Automated platform tests

Copy link
Contributor

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

As a general comment I would say the updatebrush/updatecolor code in the renderers should be consistently setup so updatecolor isn't called if the user sets the brush

For example in TabbedPageRenderer both updates get called when the control is initialized.

https://github.com/xamarin/Xamarin.Forms/pull/9220/files#diff-7feeca82b01e77527e9263a06421f443R782

I think in general UpdateColor/UpdateBrush code should always just call into UpdateBrush and then if the Brush is set call that code otherwise call UpdateColor

For example on ImageButtonRenderer here they both call the same method
https://github.com/xamarin/Xamarin.Forms/pull/9220/files#diff-8295d11d94d3eaa6d894cb727a46be12R104

We don't have to make this change as part of this PR but I wonder how much of this should be at the xplat layer. Can we make it so all the Color properties just set the Brush?

@samhouts samhouts requested a review from PureWeen July 16, 2020 16:49
Copy link
Member

@samhouts samhouts left a comment

Choose a reason for hiding this comment

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

Please rebase to fix conflicts, then merge!!!! THANKS! :D

@jsuarezruiz
Copy link
Contributor Author

@PureWeen Reviewed Shell FlyoutBackground:
flyoutbackground

@PureWeen PureWeen merged commit 3a57e2e into 4.8.0 Jul 17, 2020
4.7.0 automation moved this from In Review to Done Jul 17, 2020
Sprint 173 automation moved this from Ready for Review (PRs) to Done Jul 17, 2020
@PureWeen PureWeen deleted the forms-gradients branch July 17, 2020 14:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
4.7.0
  
Done
Sprint 170
  
Continued in next sprint
Sprint 171
  
Continued in next sprint
Sprint 173
  
Done
Development

Successfully merging this pull request may close these issues.

[Spec] Brushes [Enhancement] Add brush support for background
9 participants