Skip to content

Conversation

@zxbmmmmmmmmm
Copy link
Contributor

@zxbmmmmmmmmm zxbmmmmmmmmm commented Nov 29, 2025

This pull request implements composition brush types that conform to Avalonia's brush interfaces. It also introduces new interpolators for RelativePoint and RelativeScalar to support smooth brush animations, and adds a new interactive "Composition brush" demo to the CompositionPage in the ControlCatalog sample.

These changes collectively provide a robust demonstration and infrastructure for animated composition brushes in Avalonia, both in the UI sample and the underlying rendering system.

What does the pull request do?

Composition brush implementation:

  • Added new composition brush classes (ServerCompositionBrush, ServerCompositionGradientBrush, etc.) that implement Avalonia's brush interfaces, including property change tracking and deserialization for gradient stops and spread methods.

Animation infrastructure improvements:

  • Introduced RelativePointInterpolator and RelativeScalarInterpolator to enable smooth animation of RelativePoint and RelativeScalar properties, which are essential for animating gradient brush parameters.

Composition brush demo and animation support:

  • Added a new "Composition brush" tab to CompositionPage.axaml, featuring interactive UI elements for creating and animating solid, linear, radial, and conic composition brushes with animated properties and gradient stops.

How was the solution implemented (if it's not obvious)?

#20150 (comment)

Checklist

Breaking changes

None

Obsoletions / Deprecations

None

Fixed issues

fixed #20150

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0060477-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Quaternion,
Color
Color,
RelativePoint,
Copy link
Member

@kekekeks kekekeks Dec 1, 2025

Choose a reason for hiding this comment

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

Should probably add ctors to FFI too, e. g.

"ColorRGB", (float a, float r, float g, float b) => Avalonia.Media.Color.FromArgb(
(byte) MathUtilities.Clamp(a, 0, 255),
(byte) MathUtilities.Clamp(r, 0, 255),
(byte) MathUtilities.Clamp(g, 0, 255),
(byte) MathUtilities.Clamp(b, 0, 255)
)

Not sure how to handle RelativeUnit there, might need a separate VariantType and separate ffi functions as enum value "ctors".

<Property Name="TileMode" Type="Avalonia.Media.TileMode" />
</Object>
</NComposition>
<Object Name="CompositionBrush" ServerBase="ServerRenderResource">
Copy link
Member

Choose a reason for hiding this comment

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

@maxkatz6 I think we might want to mirror UWP API here rather than Avalonia one, at least for the sake of compatibility. This needs an API review

Copy link
Member

@kekekeks kekekeks Dec 1, 2025

Choose a reason for hiding this comment

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

In general our RelativePoint system felt a bit cumbersome to use compared to MS MappingMode one. We could use XPF approach to map brushes (see MuceRadialGradientBrush).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general our RelativePoint system felt a bit cumbersome to use compared to MS MappingMode one.

If we handle RelativeUnit directly like I'm currently doing, we may have to override their operators such as + - * /, which may not be a good way

@kekekeks kekekeks added the needs-api-review The PR adds new public APIs that should be reviewed. label Dec 1, 2025
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0060559-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0060650-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-api-review The PR adds new public APIs that should be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Composition Brush

3 participants