fsprojects / Avalonia.FuncUI

Develop cross-plattform GUI Applications using F# and Avalonia!
https://funcui.avaloniaui.net/
MIT License
955 stars 74 forks source link

Add bindings Avalonia v11.0.0 #422

Closed SilkyFowl closed 4 months ago

SilkyFowl commented 5 months ago

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?

SilkyFowl commented 4 months ago

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

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 commented 4 months ago

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

SilkyFowl commented 4 months ago

Thank you. I will do as you suggested.

JaggerJo commented 4 months ago

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

SilkyFowl commented 4 months ago

@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.

JaggerJo commented 4 months ago

@SilkyFowl can I merge this?