Skip to content
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

CanvasEffect property source generator #797

Open
4 tasks done
Sergio0694 opened this issue May 23, 2024 · 0 comments · May be fixed by #813
Open
4 tasks done

CanvasEffect property source generator #797

Sergio0694 opened this issue May 23, 2024 · 0 comments · May be fixed by #813
Labels
proposal 💡 A proposal for a new feature

Comments

@Sergio0694
Copy link
Owner

Sergio0694 commented May 23, 2024

Description

This issue tracks adding a new source generator for CanvasEffect properties.
It will be conceptually similar to the MVVM Toolkit observable property generator.

Proposed API

In ComputeSharp.D2D1.WinUI:

namespace ComputeSharp.D2D1.WinUI;

[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public sealed class GeneratedCanvasEffectPropertyAttribute(CanvasEffectInvalidationType invalidationType = CanvasEffectInvalidationType.Update) : Attribute
{
    public CanvasEffectInvalidationType InvalidationType { get; }
}

Example use

User code:

public sealed partial class MyEffect : CanvasEffect
{
    [GeneratedCanvasEffectProperty]
    public partial int BlurAmount { get; set; }
}

Generated code:

partial class MyEffect : CanvasEffect
{
    public partial int BlurAmount
    {
        get => field;
        set
        {
            if (EqualityComparer<int>.Default.Equals(field, value))
            {
                return;
            }

            int oldValue = field;
    
            OnBlurAmountChanging(value);
            OnBlurAmountChanging(oldValue, value);

            field = value;

            OnBlurAmountChanged(value);
            OnBlurAmountChanged(oldValue, value);
    
            InvalidateEffectGraph(invalidationType);
        }
    }

    partial void OnBlurAmountChanging(int newValue);
    partial void OnBlurAmountChanging(int oldValue, int newValue);
    partial void OnBlurAmountChanged(int newValue);
    partial void OnBlurAmountChanged(int oldValue, int newValue);
}

This should contain any drawbacks for the proposal
that came up during the discussions.

Alternatives

Just do nothing.

Work items

  • Refactor existing APIs to be top-level and accessible
  • Add attribute type
  • Implement generator
  • Implement analyzers
@Sergio0694 Sergio0694 added the proposal 💡 A proposal for a new feature label May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal 💡 A proposal for a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant