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

Add bindings Avalonia v11.0.0 #422

Merged
merged 59 commits into from
Jun 4, 2024

Conversation

SilkyFowl
Copy link
Contributor

This is a continuation of #420.
It adds the bindings that are missing as of Avalonia v11.0.0.

This might become a larger PR than the previous one. Would it be better to create a tracking issue and split the PR?

Copy link
Member

@JaggerJo JaggerJo left a comment

Choose a reason for hiding this comment

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

LGTM, nice work!

- fix strokeDashArray<'t>(value: double list) implementation
- rename binding name: strokeJoinCap -> strokeJoin
- remove create function ... TextElement is AbstractClass.
- add AttachedProperty bindings.
Copy link
Contributor Author

@SilkyFowl SilkyFowl left a comment

Choose a reason for hiding this comment

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

note: GestureRecognizers
AvaloniaUI/Avalonia/issues/12558

@SilkyFowl
Copy link
Contributor Author

SilkyFowl commented May 9, 2024

@JaggerJo @Numpsy In this PR, I've been renaming/removing existing bindings and such when I notice cases, such as:

  • TextElement.create ... Removed. TextElement is abstract class. Throw exception when used. Other bindings that raise exceptions when used, such as bindings for readonly properties, are also removed.
  • Shape.strokeJoinCap ... Renamed to Shape.strokeJoin. Property name is wrong. No exceptions will be made, but confusion will occur.

Should I include significant changes that require adjustments by users of FuncUI in this PR, other than the above?
Specifically, the change is as follows.
This change allows onDisplayModeChanged to receive both the new and old values as arguments, which I personally think is a desirable change. However, there is no immediate necessity as using the existing onDisplayModeChanged does not throw an exception.

diff --git a/src/Avalonia.FuncUI/DSL/Calendar/Calendar.fs b/src/Avalonia.FuncUI/DSL/Calendar/Calendar.fs
index 72008a8..6cc35d1 100644
--- a/src/Avalonia.FuncUI/DSL/Calendar/Calendar.fs
+++ b/src/Avalonia.FuncUI/DSL/Calendar/Calendar.fs
@@ -16,6 +16,19 @@ module Calendar =
      
     type Calendar with
   
+        static member onDisplayModeChanged<'t when 't :> Calendar>(func: CalendarModeChangedEventArgs -> unit, ?subPatchOptions) : IAttr<'t> =
+            let name = nameof Unchecked.defaultof<'t>.DisplayModeChanged
+            let factory: SubscriptionFactory<CalendarModeChangedEventArgs> =
+                fun (control, func, token) ->
+                    let control = control :?> 't
+                    let handler = EventHandler<CalendarModeChangedEventArgs>(fun s e -> func e)
+                    let event = control.DisplayModeChanged
+
+                    event.AddHandler(handler)
+                    token.Register(fun () -> event.RemoveHandler(handler)) |> ignore
+            
+            AttrBuilder<'t>.CreateSubscription(name, factory, func, ?subPatchOptions = subPatchOptions)
+
         static member firstDayOfWeek<'t when 't :> Calendar>(value: DayOfWeek) : IAttr<'t> =
             AttrBuilder<'t>.CreateProperty<DayOfWeek>(Calendar.FirstDayOfWeekProperty, value, ValueNone)
         
@@ -31,9 +44,6 @@ module Calendar =
         static member displayMode<'t when 't :> Calendar>(value: CalendarMode) : IAttr<'t> =
             AttrBuilder<'t>.CreateProperty<CalendarMode>(Calendar.DisplayModeProperty, value, ValueNone)
 
-        static member onDisplayModeChanged<'t when 't :> Calendar>(func: CalendarMode -> unit, ?subPatchOptions) : IAttr<'t> =
-            AttrBuilder<'t>.CreateSubscription<CalendarMode>(Calendar.DisplayModeProperty, func, ?subPatchOptions = subPatchOptions)
-
         static member selectionMode<'t when 't :> Calendar>(value: CalendarSelectionMode) : IAttr<'t> =
             AttrBuilder<'t>.CreateProperty<CalendarSelectionMode>(Calendar.SelectionModeProperty, value, ValueNone)
 

@JaggerJo
Copy link
Member

JaggerJo commented May 9, 2024

Maybe put bigger breaking changes in an extra PR so we can discuss the separately. 👍

@SilkyFowl
Copy link
Contributor Author

Thank you. I will do as you suggested.

@JaggerJo
Copy link
Member

@SilkyFowl I'm quite baffled with just how many bindings were missing 😅

@SilkyFowl
Copy link
Contributor Author

@JaggerJo I'm also surprised.
I'm thinking of making further changes in a separate PR.

Actually, I'm creating a draft to find the classes and their members that should generate the DSL from the specified assembly.
It's incomplete, but I've made a feature to output in markdown format and I'm using it to manage.
Originally, I was planning to submit a PR after the bindings update was completed and the analyzer or test function was expected to be completed.
However, I'm considering whether I should submit a PR as a draft after describing the current situation in #424, as it seems to be late to submit a PR.

@SilkyFowl SilkyFowl marked this pull request as ready for review May 16, 2024 04:01
@JaggerJo
Copy link
Member

@SilkyFowl can I merge this?

@JaggerJo JaggerJo merged commit 28e60d4 into fsprojects:master Jun 4, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants