diff --git a/src/Avalonia.FuncUI.ControlCatalog/Avalonia.FuncUI.ControlCatalog/Views/Tabs/CanvasDemo.fs b/src/Avalonia.FuncUI.ControlCatalog/Avalonia.FuncUI.ControlCatalog/Views/Tabs/CanvasDemo.fs index a8b4ae79..7e42404b 100644 --- a/src/Avalonia.FuncUI.ControlCatalog/Avalonia.FuncUI.ControlCatalog/Views/Tabs/CanvasDemo.fs +++ b/src/Avalonia.FuncUI.ControlCatalog/Avalonia.FuncUI.ControlCatalog/Views/Tabs/CanvasDemo.fs @@ -54,7 +54,7 @@ module CanvasDemo = Line.startPoint (120.0, 185.0) Line.endPoint (30.0, 115.0) Line.strokeLineCap PenLineCap.Round - Line.strokeJoinCap PenLineJoin.Bevel + Line.strokeJoin PenLineJoin.Bevel Line.stroke "red" Line.strokeThickness 2.0 ] diff --git a/src/Avalonia.FuncUI/Avalonia.FuncUI.fsproj b/src/Avalonia.FuncUI/Avalonia.FuncUI.fsproj index 3adecfa9..c32f8cd4 100644 --- a/src/Avalonia.FuncUI/Avalonia.FuncUI.fsproj +++ b/src/Avalonia.FuncUI/Avalonia.FuncUI.fsproj @@ -68,8 +68,16 @@ + + + + + + + + @@ -83,19 +91,28 @@ + + + + + + + + + @@ -108,12 +125,15 @@ + + + @@ -121,14 +141,20 @@ + - + + + + + + @@ -138,6 +164,8 @@ + + diff --git a/src/Avalonia.FuncUI/DSL/AutoCompleteBox.fs b/src/Avalonia.FuncUI/DSL/AutoCompleteBox.fs index c1fa982d..69456f4f 100644 --- a/src/Avalonia.FuncUI/DSL/AutoCompleteBox.fs +++ b/src/Avalonia.FuncUI/DSL/AutoCompleteBox.fs @@ -12,6 +12,8 @@ module AutoCompleteBox = open Avalonia.Controls.Templates open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder + open System.ComponentModel + open Avalonia.Data let create (attrs: IAttr list): IView = ViewBuilder.Create(attrs) @@ -44,6 +46,13 @@ module AutoCompleteBox = static member isDropDownOpen<'t when 't :> AutoCompleteBox>(value: bool) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(AutoCompleteBox.IsDropDownOpenProperty, value, ValueNone) + static member valueMemberBinding<'t when 't :> AutoCompleteBox>(binding: IBinding) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.ValueMemberBinding + let getter: 't -> IBinding = (fun control -> control.ValueMemberBinding) + let setter: 't * IBinding -> unit = (fun (control, value) -> control.ValueMemberBinding <- value) + + AttrBuilder<'t>.CreateProperty(name, binding, ValueSome getter, ValueSome setter, ValueNone) + static member selectedItem<'t when 't :> AutoCompleteBox>(value: obj) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(AutoCompleteBox.SelectedItemProperty, value, ValueNone) @@ -56,9 +65,87 @@ module AutoCompleteBox = static member onTextChanged<'t when 't :> AutoCompleteBox>(func: string -> unit, ?subPatchOptions) = AttrBuilder<'t>.CreateSubscription(AutoCompleteBox.TextProperty, func, ?subPatchOptions = subPatchOptions) + static member onPopulating<'t when 't :> AutoCompleteBox>(func: PopulatingEventArgs -> unit, ?subPatchOptions) = + let name = nameof Unchecked.defaultof<'t>.Populating + let factory: SubscriptionFactory = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun sender args -> func args) + let event = control.Populating + + event.AddHandler(handler) + token.Register(fun () -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription(name, factory, func, ?subPatchOptions = subPatchOptions) + + static member onPopulated<'t when 't :> AutoCompleteBox>(func: PopulatedEventArgs -> unit, ?subPatchOptions) = + let name = nameof Unchecked.defaultof<'t>.Populated + let factory: SubscriptionFactory = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun sender args -> func args) + let event = control.Populated + + event.AddHandler(handler) + token.Register(fun () -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription(name, factory, func, ?subPatchOptions = subPatchOptions) + static member onSearchTextChanged<'t when 't :> AutoCompleteBox>(func: string -> unit, ?subPatchOptions) = AttrBuilder<'t>.CreateSubscription(AutoCompleteBox.SearchTextProperty, func, ?subPatchOptions = subPatchOptions) + static member onDropDownOpening<'t when 't :> AutoCompleteBox>(func: 't * CancelEventArgs -> unit, ?subPatchOptions) = + let name = nameof Unchecked.defaultof<'t>.DropDownOpening + let factory: SubscriptionFactory<'t * CancelEventArgs> = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun sender args -> func (sender :?> 't, args)) + let event = control.DropDownOpening + + event.AddHandler(handler) + token.Register(fun () -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription<'t * CancelEventArgs>(name, factory, func, ?subPatchOptions = subPatchOptions) + + static member onDropDownOpened<'t when 't :> AutoCompleteBox>(func: 't -> unit, ?subPatchOptions) = + let name = nameof Unchecked.defaultof<'t>.DropDownOpened + let factory: SubscriptionFactory<'t> = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun sender args -> func (sender :?> 't)) + let event = control.DropDownOpened + + event.AddHandler(handler) + token.Register(fun () -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription<'t>(name, factory, func, ?subPatchOptions = subPatchOptions) + + static member onDropDownClosing<'t when 't :> AutoCompleteBox>(func: 't * CancelEventArgs -> unit, ?subPatchOptions) = + let name = nameof Unchecked.defaultof<'t>.DropDownClosing + let factory: SubscriptionFactory<'t * CancelEventArgs> = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun sender args -> func (sender :?> 't, args)) + let event = control.DropDownClosing + + event.AddHandler(handler) + token.Register(fun () -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription<'t * CancelEventArgs>(name, factory, func, ?subPatchOptions = subPatchOptions) + + static member onDropDownClosed<'t when 't :> AutoCompleteBox>(func: 't -> unit, ?subPatchOptions) = + let name = nameof Unchecked.defaultof<'t>.DropDownClosed + let factory: SubscriptionFactory<'t> = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun sender args -> func (sender :?> 't)) + let event = control.DropDownClosed + + event.AddHandler(handler) + token.Register(fun () -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription<'t>(name, factory, func, ?subPatchOptions = subPatchOptions) + static member filterMode<'t when 't :> AutoCompleteBox>(mode: AutoCompleteFilterMode) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(AutoCompleteBox.FilterModeProperty, mode, ValueNone) @@ -72,6 +159,9 @@ module AutoCompleteBox = static member textFilter<'t when 't :> AutoCompleteBox>(filterFunc: string -> obj -> bool) : IAttr<'t> = AttrBuilder<'t>.CreateProperty<_>(AutoCompleteBox.TextFilterProperty, filterFunc, ValueNone) + static member textSelector<'t when 't :> AutoCompleteBox>(selector: AutoCompleteSelector) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty<_>(AutoCompleteBox.TextSelectorProperty, selector, ValueNone) + static member dataItems<'t when 't :> AutoCompleteBox>(items: IEnumerable) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(AutoCompleteBox.ItemsSourceProperty, items, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Base/ContentPresenter.fs b/src/Avalonia.FuncUI/DSL/Base/ContentPresenter.fs index 9605d0b2..440d13f8 100644 --- a/src/Avalonia.FuncUI/DSL/Base/ContentPresenter.fs +++ b/src/Avalonia.FuncUI/DSL/Base/ContentPresenter.fs @@ -10,14 +10,14 @@ module ContentPresenter = open Avalonia.FuncUI.Builder open Avalonia.Media open Avalonia.Media.Immutable - + let create (attrs: IAttr list): IView = ViewBuilder.Create(attrs) - + type ContentPresenter with static member background<'t when 't :> ContentPresenter>(brush: IBrush) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ContentPresenter.BackgroundProperty, brush, ValueNone) - + static member background<'t when 't :> ContentPresenter>(color: string) : IAttr<'t> = Color.Parse(color) |> ImmutableSolidColorBrush |> ContentPresenter.background @@ -26,72 +26,114 @@ module ContentPresenter = static member borderBrush<'t when 't :> ContentPresenter>(brush: IBrush) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ContentPresenter.BorderBrushProperty, brush, ValueNone) - + static member borderBrush<'t when 't :> ContentPresenter>(color: string) : IAttr<'t> = Color.Parse(color) |> ImmutableSolidColorBrush |> ContentPresenter.borderBrush static member borderBrush<'t when 't :> ContentPresenter>(color: Color) : IAttr<'t> = color |> ImmutableSolidColorBrush |> ContentPresenter.borderBrush - + static member borderThickness<'t when 't :> ContentPresenter>(value: Thickness) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ContentPresenter.BorderThicknessProperty, value, ValueNone) - + static member borderThickness<'t when 't :> ContentPresenter>(value: float) : IAttr<'t> = Thickness(value) |> ContentPresenter.borderThickness - + static member borderThickness<'t when 't :> ContentPresenter>(horizontal: float, vertical: float) : IAttr<'t> = Thickness(horizontal, vertical) |> ContentPresenter.borderThickness - + static member borderThickness<'t when 't :> ContentPresenter>(left: float, top: float, right: float, bottom: float) : IAttr<'t> = Thickness(left, top, right, bottom) |> ContentPresenter.borderThickness - + static member boxShadows<'t when 't :> ContentPresenter>(value: BoxShadows) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ContentPresenter.BoxShadowProperty, value, ValueNone) - + static member boxShadow<'t when 't :> ContentPresenter>(value: BoxShadow) : IAttr<'t> = value |> BoxShadows |> ContentPresenter.boxShadows - + + static member foreground<'t when 't :> ContentPresenter>(brush: IBrush) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ContentPresenter.ForegroundProperty, brush, ValueNone) + + static member foreground<'t when 't :> ContentPresenter>(color: string) : IAttr<'t> = + Color.Parse(color) |> ImmutableSolidColorBrush |> ContentPresenter.foreground + + static member foreground<'t when 't :> ContentPresenter>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> ContentPresenter.foreground + + static member fontFamily<'t when 't :> ContentPresenter>(value: FontFamily) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ContentPresenter.FontFamilyProperty, value, ValueNone) + + static member fontSize<'t when 't :> ContentPresenter>(value: float) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ContentPresenter.FontSizeProperty, value, ValueNone) + + static member fontStyle<'t when 't :> ContentPresenter>(value: FontStyle) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ContentPresenter.FontStyleProperty, value, ValueNone) + + static member fontWeight<'t when 't :> ContentPresenter>(value: FontWeight) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ContentPresenter.FontWeightProperty, value, ValueNone) + + static member fontStretch<'t when 't :> ContentPresenter>(value: FontStretch) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ContentPresenter.FontStretchProperty, value, ValueNone) + + static member textAlignment<'t when 't :> ContentPresenter>(value: TextAlignment) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ContentPresenter.TextAlignmentProperty, value, ValueNone) + + static member textWrapping<'t when 't :> ContentPresenter>(value: TextWrapping) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ContentPresenter.TextWrappingProperty, value, ValueNone) + + static member textTrimming<'t when 't :> ContentPresenter>(value: TextTrimming) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ContentPresenter.TextTrimmingProperty, value, ValueNone) + + static member lineHeight<'t when 't :> ContentPresenter>(value: float) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ContentPresenter.LineHeightProperty, value, ValueNone) + + static member maxLines<'t when 't :> ContentPresenter>(value: int) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ContentPresenter.MaxLinesProperty, value, ValueNone) + static member cornerRadius<'t when 't :> ContentPresenter>(value: CornerRadius) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ContentPresenter.CornerRadiusProperty, value, ValueNone) - + static member cornerRadius<'t when 't :> ContentPresenter>(value: float) : IAttr<'t> = CornerRadius(value) |> ContentPresenter.cornerRadius - + static member cornerRadius<'t when 't :> ContentPresenter>(horizontal: float, vertical: float) : IAttr<'t> = CornerRadius(horizontal, vertical) |> ContentPresenter.cornerRadius - + static member cornerRadius<'t when 't :> ContentPresenter>(left: float, top: float, right: float, bottom: float) : IAttr<'t> = CornerRadius(left, right, top, bottom) |> ContentPresenter.cornerRadius - + static member child<'t when 't :> ContentPresenter>(value: IView option) : IAttr<'t> = AttrBuilder<'t>.CreateContentSingle(ContentPresenter.ChildProperty, value) static member child<'t when 't :> ContentPresenter>(value: IView) : IAttr<'t> = value |> Some |> ContentPresenter.child - + static member content<'t when 't :> ContentPresenter>(value: IView option) : IAttr<'t> = AttrBuilder<'t>.CreateContentSingle(ContentPresenter.ContentProperty, value) static member content<'t when 't :> ContentPresenter>(value: IView) : IAttr<'t> = value |> Some |> ContentPresenter.content - + static member contentTemplate<'t when 't :> ContentPresenter>(template: IDataTemplate) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ContentPresenter.ContentTemplateProperty, template, ValueNone) - + static member horizontalContentAlignment<'t when 't :> ContentPresenter>(value: HorizontalAlignment) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ContentPresenter.HorizontalContentAlignmentProperty, value, ValueNone) - + static member verticalContentAlignment<'t when 't :> ContentPresenter>(value: VerticalAlignment) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ContentPresenter.VerticalContentAlignmentProperty, value, ValueNone) - + static member padding<'t when 't :> ContentPresenter>(value: Thickness) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ContentPresenter.PaddingProperty, value, ValueNone) - + static member padding<'t when 't :> ContentPresenter>(value: float) : IAttr<'t> = Thickness(value) |> ContentPresenter.padding - + static member padding<'t when 't :> ContentPresenter>(horizontal: float, vertical: float) : IAttr<'t> = Thickness(horizontal, vertical) |> ContentPresenter.padding - + static member padding<'t when 't :> ContentPresenter>(left: float, top: float, right: float, bottom: float) : IAttr<'t> = - Thickness(left, top, right, bottom) |> ContentPresenter.padding \ No newline at end of file + Thickness(left, top, right, bottom) |> ContentPresenter.padding + + static member recognizesAccessKey<'t when 't :> ContentPresenter>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ContentPresenter.RecognizesAccessKeyProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Base/ItemsPresenter.fs b/src/Avalonia.FuncUI/DSL/Base/ItemsPresenter.fs new file mode 100644 index 00000000..026d2e01 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Base/ItemsPresenter.fs @@ -0,0 +1,16 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia.Controls +open Avalonia.Controls.Presenters + +[] +module ItemsPresenter = + open Avalonia.FuncUI.Builder + open Avalonia.FuncUI.Types + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type ItemsPresenter with + static member itemsPanel<'t when 't :> ItemsPresenter>(value: ITemplate) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty>(ItemsPresenter.ItemsPanelProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Base/ScrollContentPresenter.fs b/src/Avalonia.FuncUI/DSL/Base/ScrollContentPresenter.fs new file mode 100644 index 00000000..03297565 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Base/ScrollContentPresenter.fs @@ -0,0 +1,40 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia +open Avalonia.Controls.Primitives +open Avalonia.Controls.Presenters + +[] +module ScrollContentPresenter = + open Avalonia.FuncUI.Builder + open Avalonia.FuncUI.Types + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type ScrollContentPresenter with + static member canHorizontallyScroll<'t when 't :> ScrollContentPresenter>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollContentPresenter.CanHorizontallyScrollProperty, value, ValueNone) + + static member canVerticallyScroll<'t when 't :> ScrollContentPresenter>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollContentPresenter.CanVerticallyScrollProperty, value, ValueNone) + + static member offset<'t when 't :> ScrollContentPresenter>(value: Vector) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollContentPresenter.OffsetProperty, value, ValueNone) + + static member offset<'t when 't :> ScrollContentPresenter>(x: double, y: double) : IAttr<'t> = + Vector(x, y) |> ScrollContentPresenter.offset + static member horizontalSnapPointsType<'t when 't :> ScrollContentPresenter>(value: SnapPointsType) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollContentPresenter.HorizontalSnapPointsTypeProperty, value, ValueNone) + + static member verticalSnapPointsType<'t when 't :> ScrollContentPresenter>(value: SnapPointsType) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollContentPresenter.VerticalSnapPointsTypeProperty, value, ValueNone) + + static member horizontalSnapPointsAlignment<'t when 't :> ScrollContentPresenter>(value: SnapPointsAlignment) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollContentPresenter.HorizontalSnapPointsAlignmentProperty, value, ValueNone) + + static member verticalSnapPointsAlignment<'t when 't :> ScrollContentPresenter>(value: SnapPointsAlignment) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollContentPresenter.VerticalSnapPointsAlignmentProperty, value, ValueNone) + + static member isScrollChainingEnabled<'t when 't :> ScrollContentPresenter>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollContentPresenter.IsScrollChainingEnabledProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Base/TextPresenter.fs b/src/Avalonia.FuncUI/DSL/Base/TextPresenter.fs new file mode 100644 index 00000000..9a2c1978 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Base/TextPresenter.fs @@ -0,0 +1,142 @@ +namespace Avalonia.FuncUI.DSL + +open System +open Avalonia.Controls.Presenters +open Avalonia.Media +open Avalonia.Media.Immutable + +[] +module TextPresenter = + open Avalonia.FuncUI.Builder + open Avalonia.FuncUI.Types + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type TextPresenter with + static member onCaretBoundsChanged<'t when 't :> TextPresenter>(func: 't -> unit, ?subPatchOptions) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.CaretBoundsChanged + let factory: SubscriptionFactory<'t> = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun s e -> func(s :?> 't)) + let event = control.CaretBoundsChanged + + event.AddHandler(handler) + token.Register(fun _ -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription<'t>(name, factory, func, ?subPatchOptions = subPatchOptions) + + static member background<'t when 't :> TextPresenter>(value: IBrush) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextPresenter.BackgroundProperty, value, ValueNone) + + static member background<'t when 't :> TextPresenter>(color: string) : IAttr<'t> = + color |> Color.Parse |> ImmutableSolidColorBrush |> TextPresenter.background + + static member background<'t when 't :> TextPresenter>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> TextPresenter.background + + static member preeditText<'t when 't :> TextPresenter>(value: string) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextPresenter.PreeditTextProperty, value, ValueNone) + + static member fontFamily<'t when 't :> TextPresenter>(value: FontFamily) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.FontFamily + let getter: 't -> FontFamily = (fun control -> control.FontFamily) + let setter: 't * FontFamily -> unit = (fun (control, value) -> control.FontFamily <- value) + + AttrBuilder<'t>.CreateProperty(name, value, ValueSome getter, ValueSome setter, ValueNone) + + static member fontSize<'t when 't :> TextPresenter>(value: double) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.FontSize + let getter: 't -> double = (fun control -> control.FontSize) + let setter: 't * double -> unit = (fun (control, value) -> control.FontSize <- value) + + AttrBuilder<'t>.CreateProperty(name, value, ValueSome getter, ValueSome setter, ValueNone) + + static member fontStyle<'t when 't :> TextPresenter>(value: FontStyle) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.FontStyle + let getter: 't -> FontStyle = (fun control -> control.FontStyle) + let setter: 't * FontStyle -> unit = (fun (control, value) -> control.FontStyle <- value) + + AttrBuilder<'t>.CreateProperty(name, value, ValueSome getter, ValueSome setter, ValueNone) + + static member fontWeight<'t when 't :> TextPresenter>(value: FontWeight) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.FontWeight + let getter: 't -> FontWeight = (fun control -> control.FontWeight) + let setter: 't * FontWeight -> unit = (fun (control, value) -> control.FontWeight <- value) + + AttrBuilder<'t>.CreateProperty(name, value, ValueSome getter, ValueSome setter, ValueNone) + + static member fontStretch<'t when 't :> TextPresenter>(value: FontStretch) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.FontStretch + let getter: 't -> FontStretch = (fun control -> control.FontStretch) + let setter: 't * FontStretch -> unit = (fun (control, value) -> control.FontStretch <- value) + + AttrBuilder<'t>.CreateProperty(name, value, ValueSome getter, ValueSome setter, ValueNone) + + static member foreground<'t when 't :> TextPresenter>(value: IBrush) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.Foreground + let getter: 't -> IBrush = (fun control -> control.Foreground) + let setter: 't * IBrush -> unit = (fun (control, value) -> control.Foreground <- value) + + AttrBuilder<'t>.CreateProperty(name, value, ValueSome getter, ValueSome setter, ValueNone) + + static member foreground<'t when 't :> TextPresenter>(color: string) : IAttr<'t> = + color |> Color.Parse |> ImmutableSolidColorBrush |> TextPresenter.foreground + + static member foreground<'t when 't :> TextPresenter>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> TextPresenter.foreground + + static member textWrapping<'t when 't :> TextPresenter>(value: TextWrapping) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextPresenter.TextWrappingProperty, value, ValueNone) + + static member lineHeight<'t when 't :> TextPresenter>(value: double) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextPresenter.LineHeightProperty, value, ValueNone) + + static member letterSpacing<'t when 't :> TextPresenter>(value: double) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextPresenter.LetterSpacingProperty, value, ValueNone) + + static member textAlignment<'t when 't :> TextPresenter>(value: TextAlignment) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextPresenter.TextAlignmentProperty, value, ValueNone) + + static member caretIndex<'t when 't :> TextPresenter>(value: int) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextPresenter.CaretIndexProperty, value, ValueNone) + + static member passwordChar<'t when 't :> TextPresenter>(value: char) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextPresenter.PasswordCharProperty, value, ValueNone) + + static member revealPassword<'t when 't :> TextPresenter>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextPresenter.RevealPasswordProperty, value, ValueNone) + + static member selectionBrush<'t when 't :> TextPresenter>(value: IBrush) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextPresenter.SelectionBrushProperty, value, ValueNone) + + static member selectionBrush<'t when 't :> TextPresenter>(color: string) : IAttr<'t> = + color |> Color.Parse |> ImmutableSolidColorBrush |> TextPresenter.selectionBrush + + static member selectionBrush<'t when 't :> TextPresenter>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> TextPresenter.selectionBrush + + static member selectionForegroundBrush<'t when 't :> TextPresenter>(value: IBrush) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextPresenter.SelectionForegroundBrushProperty, value, ValueNone) + + static member selectionForegroundBrush<'t when 't :> TextPresenter>(color: string) : IAttr<'t> = + color |> Color.Parse |> ImmutableSolidColorBrush |> TextPresenter.selectionForegroundBrush + + static member selectionForegroundBrush<'t when 't :> TextPresenter>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> TextPresenter.selectionForegroundBrush + + static member caretBrush<'t when 't :> TextPresenter>(value: IBrush) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextPresenter.CaretBrushProperty, value, ValueNone) + + static member caretBrush<'t when 't :> TextPresenter>(color: string) : IAttr<'t> = + color |> Color.Parse |> ImmutableSolidColorBrush |> TextPresenter.caretBrush + + static member caretBrush<'t when 't :> TextPresenter>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> TextPresenter.caretBrush + + static member selectionStart<'t when 't :> TextPresenter>(value: int) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextPresenter.SelectionStartProperty, value, ValueNone) + + static member selectionEnd<'t when 't :> TextPresenter>(value: int) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextPresenter.SelectionEndProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/BindingEvaluator.fs b/src/Avalonia.FuncUI/DSL/BindingEvaluator.fs new file mode 100644 index 00000000..f48f0aa9 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/BindingEvaluator.fs @@ -0,0 +1,36 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia +open Avalonia.Controls +open Avalonia.Data + +[] +module BindingEvaluator = + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create<'x> + (attrs: IAttr> list) + : IView> = + ViewBuilder.Create>(attrs) + + let createWith<'x> + (binding: IBinding) + (attrs: IAttr> list) + : IView> = + create attrs |> View.withConstructorArgs [| binding |] + + type AutoCompleteBox.BindingEvaluator<'x> with + + static member value<'t, 'x when 't :> AutoCompleteBox.BindingEvaluator<'x>>(value: 'x) : IAttr<'t> = + let prop: StyledProperty<'x> = AutoCompleteBox.BindingEvaluator.ValueProperty + AttrBuilder<'t>.CreateProperty<'x>(prop, value, ValueNone) + + static member valueBinding<'t, 'x when 't :> AutoCompleteBox.BindingEvaluator<'x>> + (value: IBinding) + : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.ValueBinding + let getter: 't -> IBinding = fun x -> x.ValueBinding + let setter: 't * IBinding -> unit = fun (x, v) -> x.ValueBinding <- v + + AttrBuilder<'t>.CreateProperty(name, value, ValueSome getter, ValueSome setter, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Buttons/Button.fs b/src/Avalonia.FuncUI/DSL/Buttons/Button.fs index 8ab42cd6..15dbc989 100644 --- a/src/Avalonia.FuncUI/DSL/Buttons/Button.fs +++ b/src/Avalonia.FuncUI/DSL/Buttons/Button.fs @@ -29,6 +29,9 @@ module Button = static member isDefault<'t when 't :> Button>(value: bool) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Button.IsDefaultProperty, value, ValueNone) + static member isCancel<'t when 't :> Button>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(Button.IsCancelProperty, value, ValueNone) + static member onIsPressedChanged<'t when 't :> Button>(func: bool -> unit, ?subPatchOptions) = AttrBuilder<'t>.CreateSubscription(Button.IsPressedProperty, func, ?subPatchOptions = subPatchOptions) diff --git a/src/Avalonia.FuncUI/DSL/Buttons/DropDownButton.fs b/src/Avalonia.FuncUI/DSL/Buttons/DropDownButton.fs new file mode 100644 index 00000000..9a0cde63 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Buttons/DropDownButton.fs @@ -0,0 +1,12 @@ +namespace Avalonia.FuncUI.DSL + +[] +module DropDownButton = + open Avalonia.Controls + open Avalonia.FuncUI.Types + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type DropDownButton with + end diff --git a/src/Avalonia.FuncUI/DSL/Buttons/ToggleSplitButton.fs b/src/Avalonia.FuncUI/DSL/Buttons/ToggleSplitButton.fs new file mode 100644 index 00000000..56f80f06 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Buttons/ToggleSplitButton.fs @@ -0,0 +1,26 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia.Controls +open Avalonia.Interactivity + +[] +module ToggleSplitButton = + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type ToggleSplitButton with + + /// + /// Raised when the property value changes. + /// + static member onIsCheckedChanged<'t when 't :> ToggleSplitButton>(func: RoutedEventArgs -> unit, ?subPatchOptions) = + AttrBuilder<'t>.CreateSubscription(ToggleSplitButton.IsCheckedChangedEvent, func, ?subPatchOptions = subPatchOptions) + + /// + /// Gets or sets a value indicating whether the is checked. + /// + static member isChecked<'t when 't :> ToggleSplitButton>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ToggleSplitButton.IsCheckedProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Buttons/ToggleSwitch.fs b/src/Avalonia.FuncUI/DSL/Buttons/ToggleSwitch.fs index 3f631fb5..412f38c8 100644 --- a/src/Avalonia.FuncUI/DSL/Buttons/ToggleSwitch.fs +++ b/src/Avalonia.FuncUI/DSL/Buttons/ToggleSwitch.fs @@ -4,24 +4,55 @@ [] module ToggleSwitch = + open Avalonia.Animation open Avalonia.Controls open Avalonia.Controls.Templates + open Avalonia.FuncUI open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder + open Avalonia.Collections let create (attrs: IAttr list): IView = ViewBuilder.Create(attrs) type ToggleSwitch with + + static member onContent<'t when 't :> ToggleSwitch>(text: string) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ToggleSwitch.OnContentProperty, text, ValueNone) + static member onContent<'t when 't :> ToggleSwitch>(value: obj) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ToggleSwitch.OnContentProperty, value, ValueNone) - + + static member onContent<'t when 't :> ToggleSwitch>(view: IView option) : IAttr<'t> = + AttrBuilder<'t>.CreateContentSingle(ToggleSwitch.OnContentProperty, view) + + static member onContent<'t when 't :> ToggleSwitch>(view: IView) : IAttr<'t> = + Some view |> ToggleSwitch.onContent + static member onContentTemplate<'t when 't :> ToggleSwitch>(template: IDataTemplate) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ToggleSwitch.OnContentTemplateProperty, template, ValueNone) - + + static member offContent<'t when 't :> ToggleSwitch>(text: string) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ToggleSwitch.OffContentProperty, text, ValueNone) + static member offContent<'t when 't :> ToggleSwitch>(value: obj) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ToggleSwitch.OffContentProperty, value, ValueNone) + static member offContent<'t when 't :> ToggleSwitch>(view: IView option) : IAttr<'t> = + AttrBuilder<'t>.CreateContentSingle(ToggleSwitch.OffContentProperty, view) + + static member offContent<'t when 't :> ToggleSwitch>(view: IView) : IAttr<'t> = + Some view |> ToggleSwitch.offContent + static member offContentTemplate<'t when 't :> ToggleSwitch>(template: IDataTemplate) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ToggleSwitch.OffContentTemplateProperty, template, ValueNone) - \ No newline at end of file + + static member knobTransitions<'t when 't :> ToggleSwitch>(value: Transitions) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ToggleSwitch.KnobTransitionsProperty, value, ValueNone) + + static member knobTransitions<'t when 't :> ToggleSwitch>(transitions: ITransition list) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.Transitions + let getter: 't -> ITransition list = fun x -> x.KnobTransitions |> Seq.toList + let setter: 't * ITransition list -> unit = fun (x, value) -> Setters.avaloniaList x.KnobTransitions value + + AttrBuilder<'t>.CreateProperty(name, transitions, ValueSome getter, ValueSome setter, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Calendar/Calendar.fs b/src/Avalonia.FuncUI/DSL/Calendar/Calendar.fs index 72008a84..0fa92cce 100644 --- a/src/Avalonia.FuncUI/DSL/Calendar/Calendar.fs +++ b/src/Avalonia.FuncUI/DSL/Calendar/Calendar.fs @@ -5,29 +5,60 @@ [] module Calendar = open System + open Avalonia.Controls.Primitives open Avalonia.Media open Avalonia.Media.Immutable open Avalonia.Controls + open Avalonia.FuncUI open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder - + let create (attrs: IAttr list): IView = ViewBuilder.Create(attrs) - + type Calendar with - + + static member onSelectedDatesChanged<'t when 't :> Calendar>(func: SelectionChangedEventArgs -> unit, ?subPatchOptions) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.SelectedDatesChanged + let factory: SubscriptionFactory = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun s e -> func e) + let event = control.SelectedDatesChanged + + event.AddHandler(handler) + token.Register(fun () -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription(name, factory, func, ?subPatchOptions = subPatchOptions) + + static member onDisplayDateChanged<'t when 't :> Calendar>(func: CalendarDateChangedEventArgs -> unit, ?subPatchOptions) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.DisplayDateChanged + let factory: SubscriptionFactory = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun s e -> func e) + let event = control.DisplayDateChanged + + 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(Calendar.FirstDayOfWeekProperty, value, ValueNone) - + static member isTodayHighlighted<'t when 't :> Calendar>(value: bool) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Calendar.IsTodayHighlightedProperty , value, ValueNone) static member headerBackground<'t when 't :> Calendar>(value: IBrush) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Calendar.HeaderBackgroundProperty, value, ValueNone) - + static member headerBackground<'t when 't :> Calendar>(color: string) : IAttr<'t> = color |> Color.Parse |> ImmutableSolidColorBrush |> Calendar.headerBackground + static member headerBackground<'t when 't :> Calendar>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> Calendar.headerBackground + static member displayMode<'t when 't :> Calendar>(value: CalendarMode) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Calendar.DisplayModeProperty, value, ValueNone) @@ -52,6 +83,21 @@ module Calendar = static member onSelectedDateChanged<'t when 't :> Calendar>(func: Nullable -> unit, ?subPatchOptions) : IAttr<'t> = AttrBuilder<'t>.CreateSubscription(Calendar.SelectedDateProperty, func, ?subPatchOptions = subPatchOptions) + static member selectedDates<'t when 't :> Calendar>(value: SelectedDatesCollection) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.SelectedDates + let getter: 't -> SelectedDatesCollection = fun control -> control.SelectedDates + let setter: 't * SelectedDatesCollection -> unit = fun (control, value) -> Setters.iList control.SelectedDates value + let compare: Comparer = EqualityComparers.compareSeq + + AttrBuilder<'t>.CreateProperty(name, value, ValueSome getter, ValueSome setter, ValueSome compare) + + static member selectedDates<'t when 't :> Calendar>(value: DateTime list) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.SelectedDates + let getter: 't -> DateTime list = fun control -> control.SelectedDates |> Seq.toList + let setter: 't * DateTime list -> unit = fun (control, value) -> Setters.iList control.SelectedDates value + + AttrBuilder<'t>.CreateProperty(name, value, ValueSome getter, ValueSome setter, ValueNone) + static member displayDate<'t when 't :> Calendar>(value: DateTime) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Calendar.DisplayDateProperty, value, ValueNone) @@ -72,4 +118,3 @@ module Calendar = static member displayDateEnd<'t when 't :> Calendar>(value: DateTime option) : IAttr<'t> = value |> Option.toNullable |> Calendar.displayDateEnd - diff --git a/src/Avalonia.FuncUI/DSL/Calendar/CalendarButton.fs b/src/Avalonia.FuncUI/DSL/Calendar/CalendarButton.fs new file mode 100644 index 00000000..8d1a5bdb --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Calendar/CalendarButton.fs @@ -0,0 +1,56 @@ +namespace Avalonia.FuncUI.DSL + +open System +open Avalonia.Controls.Primitives +open Avalonia.Input + +[] +module CalendarButton = + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type CalendarButton with + + /// + /// Occurs when the left mouse button is pressed (or when the tip of the + /// stylus touches the tablet PC) while the mouse pointer is over a + /// UIElement. + /// + /// + /// Because of CalendarButton is sealed, this binding is only for CalendarButton + static member onCalendarLeftMouseButtonDown(func: PointerPressedEventArgs -> unit, ?subPatchOptions) : IAttr = + let name = nameof Unchecked.defaultof.CalendarLeftMouseButtonDown + let factory: SubscriptionFactory = + fun (control, func, token) -> + let control = control :?> CalendarButton + let handler = EventHandler(fun s e -> func e) + let event = control.CalendarLeftMouseButtonDown + + event.AddHandler(handler) + token.Register(fun () -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder.CreateSubscription(name, factory, func, ?subPatchOptions = subPatchOptions) + + /// + /// Occurs when the left mouse button is released (or the tip of the + /// stylus is removed from the tablet PC) while the mouse (or the + /// stylus) is over a UIElement (or while a UIElement holds mouse + /// capture). + /// + /// + /// Because of CalendarButton is sealed, this binding is only for CalendarButton + static member onCalendarLeftMouseButtonUp(func: PointerReleasedEventArgs -> unit, ?subPatchOptions) : IAttr = + let name = nameof Unchecked.defaultof.CalendarLeftMouseButtonUp + let factory: SubscriptionFactory = + fun (control, func, token) -> + let control = control :?> CalendarButton + let handler = EventHandler(fun s e -> func e) + let event = control.CalendarLeftMouseButtonUp + + event.AddHandler(handler) + token.Register(fun () -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder.CreateSubscription(name, factory, func, ?subPatchOptions = subPatchOptions) diff --git a/src/Avalonia.FuncUI/DSL/Calendar/CalendarDatePicker.fs b/src/Avalonia.FuncUI/DSL/Calendar/CalendarDatePicker.fs index d21e1e16..c2a7cd2e 100644 --- a/src/Avalonia.FuncUI/DSL/Calendar/CalendarDatePicker.fs +++ b/src/Avalonia.FuncUI/DSL/Calendar/CalendarDatePicker.fs @@ -4,6 +4,7 @@ module CalendarDatePicker = open System open Avalonia.Controls + open Avalonia.Layout open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder @@ -11,7 +12,46 @@ module CalendarDatePicker = ViewBuilder.Create(attrs) type CalendarDatePicker with - + + static member onCalendarClosed<'t when 't :> CalendarDatePicker>(func: 't -> unit, ?subPatchOptions) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.CalendarClosed + let factory: SubscriptionFactory<'t> = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun s e -> func (s :?> 't)) + let event = control.CalendarClosed + + event.AddHandler(handler) + token.Register(fun () -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription(name, factory, func, ?subPatchOptions = subPatchOptions) + + static member onCalendarOpened<'t when 't :> CalendarDatePicker>(func: 't -> unit, ?subPatchOptions) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.CalendarOpened + let factory: SubscriptionFactory<'t> = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun s e -> func (s :?> 't)) + let event = control.CalendarOpened + + event.AddHandler(handler) + token.Register(fun () -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription(name, factory, func, ?subPatchOptions = subPatchOptions) + + static member onDateValidationError<'t when 't :> CalendarDatePicker>(func: CalendarDatePickerDateValidationErrorEventArgs -> unit, ?subPatchOptions) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.DateValidationError + let factory: SubscriptionFactory = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun s e -> func e) + let event = control.DateValidationError + + event.AddHandler(handler) + token.Register(fun () -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription(name, factory, func, ?subPatchOptions = subPatchOptions) + static member displayDate<'t when 't :> CalendarDatePicker>(value: DateTime) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(CalendarDatePicker.DisplayDateProperty, value, ValueNone) @@ -72,3 +112,8 @@ module CalendarDatePicker = static member useFloatingWatermark<'t when 't :> CalendarDatePicker>(value: bool) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(CalendarDatePicker.UseFloatingWatermarkProperty, value, ValueNone) + static member horizontalContentAlignment<'t when 't :> CalendarDatePicker>(value: HorizontalAlignment) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(CalendarDatePicker.HorizontalContentAlignmentProperty, value, ValueNone) + + static member verticalContentAlignment<'t when 't :> CalendarDatePicker>(value: VerticalAlignment) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(CalendarDatePicker.VerticalContentAlignmentProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Calendar/CalendarDayButton.fs b/src/Avalonia.FuncUI/DSL/Calendar/CalendarDayButton.fs new file mode 100644 index 00000000..4c516461 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Calendar/CalendarDayButton.fs @@ -0,0 +1,56 @@ +namespace Avalonia.FuncUI.DSL + +open System +open Avalonia.Controls.Primitives +open Avalonia.Input + +[] +module CalendarDayButton = + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type CalendarDayButton with + + /// + /// Occurs when the left mouse button is pressed (or when the tip of the + /// stylus touches the tablet PC) while the mouse pointer is over a + /// UIElement. + /// + /// + /// Because of CalendarDayButton is sealed, this binding is only for CalendarDayButton + static member onCalendarDayButtonMouseDown(func: PointerPressedEventArgs -> unit, ?subPatchOptions) : IAttr = + let name = nameof Unchecked.defaultof.CalendarDayButtonMouseDown + let factory: SubscriptionFactory = + fun (control, func, token) -> + let control = control :?> CalendarDayButton + let handler = EventHandler(fun s e -> func e) + let event = control.PointerPressed + + event.AddHandler(handler) + token.Register(fun () -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder.CreateSubscription(name, factory, func, ?subPatchOptions = subPatchOptions) + + /// + /// Occurs when the left mouse button is released (or the tip of the + /// stylus is removed from the tablet PC) while the mouse (or the + /// stylus) is over a UIElement (or while a UIElement holds mouse + /// capture). + /// + /// + /// Because of CalendarDayButton is sealed, this binding is only for CalendarDayButton + static member onCalendarDayButtonMouseUp(func: PointerReleasedEventArgs -> unit, ?subPatchOptions) : IAttr = + let name = nameof Unchecked.defaultof.CalendarDayButtonMouseUp + let factory: SubscriptionFactory = + fun (control, func, token) -> + let control = control :?> CalendarDayButton + let handler = EventHandler(fun s e -> func e) + let event = control.PointerReleased + + event.AddHandler(handler) + token.Register(fun () -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder.CreateSubscription(name, factory, func, ?subPatchOptions = subPatchOptions) diff --git a/src/Avalonia.FuncUI/DSL/ComboBox.fs b/src/Avalonia.FuncUI/DSL/ComboBox.fs index c6c85760..789c67d7 100644 --- a/src/Avalonia.FuncUI/DSL/ComboBox.fs +++ b/src/Avalonia.FuncUI/DSL/ComboBox.fs @@ -4,6 +4,8 @@ namespace Avalonia.FuncUI.DSL module ComboBox = open Avalonia.Controls open Avalonia.Layout + open Avalonia.Media + open Avalonia.Media.Immutable open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder @@ -11,7 +13,33 @@ module ComboBox = ViewBuilder.Create(attrs) type ComboBox with - + static member onDropDownClosed<'t when 't :> ComboBox>(func: 't -> unit, ?subPatchOptions) = + let name = nameof Unchecked.defaultof<'t>.DropDownClosed + + let factory: SubscriptionFactory<'t> = + fun (control, func, token) -> + let control = control :?> 't + let handler = System.EventHandler(fun s _ -> func (s :?> 't)) + let event = control.DropDownClosed + + event.AddHandler(handler) + token.Register(fun _ -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription<'t>(name, factory, func, ?subPatchOptions = subPatchOptions) + + static member onDropDownOpened<'t when 't :> ComboBox>(func: 't -> unit, ?subPatchOptions) = + let name = nameof Unchecked.defaultof<'t>.DropDownOpened + + let factory: SubscriptionFactory<'t> = + fun (control, func, token) -> + let control = control :?> 't + let handler = System.EventHandler(fun s _ -> func (s :?> 't)) + let event = control.DropDownOpened + + event.AddHandler(handler) + token.Register(fun _ -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription<'t>(name, factory, func, ?subPatchOptions = subPatchOptions) static member isDropDownOpen<'t when 't :> ComboBox>(value: bool) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ComboBox.IsDropDownOpenProperty, value, ValueNone) @@ -20,6 +48,17 @@ module ComboBox = static member maxDropDownHeight<'t when 't :> ComboBox>(height: float) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ComboBox.MaxDropDownHeightProperty, height, ValueNone) - + + static member placeholderText<'t when 't :> ComboBox>(text: string) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ComboBox.PlaceholderTextProperty, text, ValueNone) + + static member placeholderForeground<'t when 't :> ComboBox>(value: IBrush) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ComboBox.PlaceholderForegroundProperty, value, ValueNone) + + static member placeholderForeground<'t when 't :> ComboBox>(color:string) : IAttr<'t> = + color |> Color.Parse |> ImmutableSolidColorBrush |> ComboBox.placeholderForeground + + static member placeholderForeground<'t when 't :> ComboBox>(color:Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> ComboBox.placeholderForeground static member verticalContentAlignment<'t when 't :> ComboBox>(alignment: VerticalAlignment) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ComboBox.VerticalContentAlignmentProperty, alignment, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/DataGrid.fs b/src/Avalonia.FuncUI/DSL/DataGrid.fs index 1fe1f31b..d21142be 100644 --- a/src/Avalonia.FuncUI/DSL/DataGrid.fs +++ b/src/Avalonia.FuncUI/DSL/DataGrid.fs @@ -58,6 +58,16 @@ module DataGrid = multipleContent = columns ) +[] +module DataGridFrozenGrid = + open Avalonia.Controls.Primitives + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type Control with + static member isFrozen<'t when 't :> Control>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(DataGridFrozenGrid.IsFrozenProperty, value, ValueNone) + [] module DataGridColumn = diff --git a/src/Avalonia.FuncUI/DSL/DataValidationErrors.fs b/src/Avalonia.FuncUI/DSL/DataValidationErrors.fs index 7c55fa40..7084e698 100644 --- a/src/Avalonia.FuncUI/DSL/DataValidationErrors.fs +++ b/src/Avalonia.FuncUI/DSL/DataValidationErrors.fs @@ -19,5 +19,9 @@ module DataValidationErrors = AttrBuilder<'t>.CreateProperty(DataValidationErrors.HasErrorsProperty, hasErrors, ValueNone) type DataValidationErrors with + + static member owner<'t when 't :> DataValidationErrors>(value: Control) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(DataValidationErrors.OwnerProperty, value, ValueNone) + static member errorTemplate<'t when 't :> DataValidationErrors>(template: IDataTemplate) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(DataValidationErrors.ErrorTemplateProperty, template, ValueNone) \ No newline at end of file diff --git a/src/Avalonia.FuncUI/DSL/DatePickerPresenter.fs b/src/Avalonia.FuncUI/DSL/DatePickerPresenter.fs new file mode 100644 index 00000000..07b42d65 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/DatePickerPresenter.fs @@ -0,0 +1,49 @@ +namespace Avalonia.FuncUI.DSL + +open System +open Avalonia.Controls + +[] +module DatePickerPresenter = + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type DatePickerPresenter with + /// Gets or sets the current Date for the picker + static member date<'t when 't :> DatePickerPresenter>(value: DateTimeOffset) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(DatePickerPresenter.DateProperty, value, ValueNone) + + /// Gets or sets the DayFormat + static member dayFormat<'t when 't :> DatePickerPresenter>(value: string) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(DatePickerPresenter.DayFormatProperty, value, ValueNone) + + /// Get or sets whether the Day selector is visible + static member dayVisible<'t when 't :> DatePickerPresenter>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(DatePickerPresenter.DayVisibleProperty, value, ValueNone) + + /// Gets or sets the maximum pickable year + static member maxYear<'t when 't :> DatePickerPresenter>(value: DateTimeOffset) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(DatePickerPresenter.MaxYearProperty, value, ValueNone) + + /// Gets or sets the minimum pickable year + static member minYear<'t when 't :> DatePickerPresenter>(value: DateTimeOffset) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(DatePickerPresenter.MinYearProperty, value, ValueNone) + + /// Gets or sets the month format + static member monthFormat<'t when 't :> DatePickerPresenter>(value: string) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(DatePickerPresenter.MonthFormatProperty, value, ValueNone) + + /// Gets or sets whether the month selector is visible + static member monthVisible<'t when 't :> DatePickerPresenter>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(DatePickerPresenter.MonthVisibleProperty, value, ValueNone) + + /// Gets or sets the year format + static member yearFormat<'t when 't :> DatePickerPresenter>(value: string) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(DatePickerPresenter.YearFormatProperty, value, ValueNone) + + /// Gets or sets whether the year selector is visible + static member yearVisible<'t when 't :> DatePickerPresenter>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(DatePickerPresenter.YearVisibleProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Expander.fs b/src/Avalonia.FuncUI/DSL/Expander.fs index 73c44e85..ac4c1917 100644 --- a/src/Avalonia.FuncUI/DSL/Expander.fs +++ b/src/Avalonia.FuncUI/DSL/Expander.fs @@ -4,6 +4,7 @@ module Expander = open Avalonia.Animation open Avalonia.Controls + open Avalonia.Interactivity open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder @@ -12,6 +13,18 @@ module Expander = type Expander with + static member onCollapsed<'t when 't :> Expander>(func: RoutedEventArgs -> unit, ?subPatchOptions) = + AttrBuilder<'t>.CreateSubscription(Expander.CollapsedEvent, func, ?subPatchOptions = subPatchOptions) + + static member onCollapsing<'t when 't :> Expander>(func: CancelRoutedEventArgs -> unit, ?subPatchOptions) = + AttrBuilder<'t>.CreateSubscription(Expander.CollapsingEvent, func, ?subPatchOptions = subPatchOptions) + + static member onExpanded<'t when 't :> Expander>(func: RoutedEventArgs -> unit, ?subPatchOptions) = + AttrBuilder<'t>.CreateSubscription(Expander.ExpandedEvent, func, ?subPatchOptions = subPatchOptions) + + static member onExpanding<'t when 't :> Expander>(func: CancelRoutedEventArgs -> unit, ?subPatchOptions) = + AttrBuilder<'t>.CreateSubscription(Expander.ExpandingEvent, func, ?subPatchOptions = subPatchOptions) + static member contentTransition<'t when 't :> Expander>(value: IPageTransition) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Expander.ContentTransitionProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/ExperimentalAcrylicBorder.fs b/src/Avalonia.FuncUI/DSL/ExperimentalAcrylicBorder.fs new file mode 100644 index 00000000..56a31146 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/ExperimentalAcrylicBorder.fs @@ -0,0 +1,20 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia +open Avalonia.Controls +open Avalonia.Media + +[] +module ExperimentalAcrylicBorder = + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type ExperimentalAcrylicBorder with + static member cornerRadius<'t when 't :> ExperimentalAcrylicBorder>(value: CornerRadius) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ExperimentalAcrylicBorder.CornerRadiusProperty, value, ValueNone) + + static member material<'t when 't :> ExperimentalAcrylicBorder>(value: ExperimentalAcrylicMaterial) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ExperimentalAcrylicBorder.MaterialProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/MenuItem.fs b/src/Avalonia.FuncUI/DSL/MenuItem.fs index c0e86333..4464927b 100644 --- a/src/Avalonia.FuncUI/DSL/MenuItem.fs +++ b/src/Avalonia.FuncUI/DSL/MenuItem.fs @@ -44,6 +44,9 @@ module MenuItem = static member isSubMenuOpen<'t when 't :> MenuItem>(value: bool) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(MenuItem.IsSubMenuOpenProperty, value, ValueNone) + static member staysOpenOnClick<'t when 't :> MenuItem>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(MenuItem.StaysOpenOnClickProperty, value, ValueNone) + static member onIsSubMenuOpenChanged<'t when 't :> MenuItem>(func: bool -> unit, ?subPatchOptions) = AttrBuilder<'t>.CreateSubscription(MenuItem.IsSubMenuOpenProperty, func, ?subPatchOptions = subPatchOptions) diff --git a/src/Avalonia.FuncUI/DSL/NativeControlHost.fs b/src/Avalonia.FuncUI/DSL/NativeControlHost.fs new file mode 100644 index 00000000..2945e589 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/NativeControlHost.fs @@ -0,0 +1,10 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia.Controls + +[] +module NativeControlHost = + open Avalonia.FuncUI.Types + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) diff --git a/src/Avalonia.FuncUI/DSL/NumericUpDown.fs b/src/Avalonia.FuncUI/DSL/NumericUpDown.fs index d3bd6e8f..cbd89e72 100644 --- a/src/Avalonia.FuncUI/DSL/NumericUpDown.fs +++ b/src/Avalonia.FuncUI/DSL/NumericUpDown.fs @@ -7,6 +7,8 @@ module NumericUpDown = open Avalonia.Controls open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder + open Avalonia.Data.Converters + open Avalonia.Layout let create (attrs: IAttr list): IView = ViewBuilder.Create(attrs) @@ -76,6 +78,9 @@ module NumericUpDown = AttrBuilder<'t>.CreateProperty("Text", value, ValueSome getter, ValueSome setter, ValueNone) + static member textConverter<'t when 't :> NumericUpDown>(value: IValueConverter) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(NumericUpDown.TextConverterProperty, value, ValueNone) + static member onTextChanged<'t when 't :> NumericUpDown>(func: string -> unit, ?subPatchOptions) = AttrBuilder<'t>.CreateSubscription(NumericUpDown.TextProperty, func, ?subPatchOptions = subPatchOptions) @@ -91,4 +96,8 @@ module NumericUpDown = static member watermark<'t when 't :> NumericUpDown>(value: string) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(NumericUpDown.WatermarkProperty, value, ValueNone) + static member horizontalContentAlignment<'t when 't :> NumericUpDown>(value: HorizontalAlignment) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(NumericUpDown.HorizontalContentAlignmentProperty, value, ValueNone) + static member verticalContentAlignment<'t when 't :> NumericUpDown>(value: VerticalAlignment) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(NumericUpDown.VerticalContentAlignmentProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Panels/ReversibleStackPanel.fs b/src/Avalonia.FuncUI/DSL/Panels/ReversibleStackPanel.fs new file mode 100644 index 00000000..c93f37c9 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Panels/ReversibleStackPanel.fs @@ -0,0 +1,16 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia.Controls + +[] +module ReversibleStackPanel = + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type ReversibleStackPanel with + /// Gets or sets if the child controls will be layed out in reverse order. + static member reverseOrder<'t when 't :> ReversibleStackPanel>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ReversibleStackPanel.ReverseOrderProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Panels/StackPanel.fs b/src/Avalonia.FuncUI/DSL/Panels/StackPanel.fs index ad15f228..dbc8c426 100644 --- a/src/Avalonia.FuncUI/DSL/Panels/StackPanel.fs +++ b/src/Avalonia.FuncUI/DSL/Panels/StackPanel.fs @@ -3,20 +3,33 @@ namespace Avalonia.FuncUI.DSL [] module StackPanel = open Avalonia.Controls + open Avalonia.Interactivity open Avalonia.Layout open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder - + let create (attrs: IAttr list): IView = ViewBuilder.Create(attrs) type StackPanel with + /// + /// Occurs when the measurements for horizontal snap points change. + /// + static member onHorizontalSnapPointsChanged<'t when 't :> StackPanel>(func: RoutedEventArgs -> unit, ?subPatchOptions) : IAttr<'t> = + AttrBuilder<'t>.CreateSubscription(StackPanel.HorizontalSnapPointsChangedEvent, func, ?subPatchOptions = subPatchOptions) + + /// + /// Occurs when the measurements for vertical snap points change. + /// + static member onVerticalSnapPointsChanged<'t when 't :> StackPanel>(func: RoutedEventArgs -> unit, ?subPatchOptions) : IAttr<'t> = + AttrBuilder<'t>.CreateSubscription(StackPanel.VerticalSnapPointsChangedEvent, func, ?subPatchOptions = subPatchOptions) + /// /// Gets or sets the size of the spacing to place between child controls. /// static member spacing<'t when 't :> StackPanel>(value: double) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(StackPanel.SpacingProperty, value, ValueNone) - + /// /// Gets or sets the orientation in which child controls will be layed out. /// @@ -27,4 +40,4 @@ module StackPanel = AttrBuilder<'t>.CreateProperty(StackPanel.AreHorizontalSnapPointsRegularProperty, value, ValueNone) static member areVerticalSnapPointsRegular<'t when 't :> StackPanel>(value: bool) : IAttr<'t> = - AttrBuilder<'t>.CreateProperty(StackPanel.AreVerticalSnapPointsRegularProperty, value, ValueNone) \ No newline at end of file + AttrBuilder<'t>.CreateProperty(StackPanel.AreVerticalSnapPointsRegularProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Panels/VirtualizingCarouselPanel.fs b/src/Avalonia.FuncUI/DSL/Panels/VirtualizingCarouselPanel.fs new file mode 100644 index 00000000..90ffcbf8 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Panels/VirtualizingCarouselPanel.fs @@ -0,0 +1,13 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia.Controls + +[] +module VirtualizingCarouselPanel = + open Avalonia.FuncUI.Types + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type VirtualizingCarouselPanel with + end diff --git a/src/Avalonia.FuncUI/DSL/Panels/VirtualizingStackPanel.fs b/src/Avalonia.FuncUI/DSL/Panels/VirtualizingStackPanel.fs new file mode 100644 index 00000000..bd48db48 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Panels/VirtualizingStackPanel.fs @@ -0,0 +1,44 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia.Controls +open Avalonia.Interactivity +open Avalonia.Layout + +[] +module VirtualizingStackPanel = + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type VirtualizingStackPanel with + /// + /// Occurs when the measurements for horizontal snap points change. + /// + static member onHorizontalSnapPointsChanged<'t when 't :> VirtualizingStackPanel>(func: RoutedEventArgs -> unit, ?subPatchOptions) : IAttr<'t> = + AttrBuilder<'t>.CreateSubscription(VirtualizingStackPanel.HorizontalSnapPointsChangedEvent, func, ?subPatchOptions = subPatchOptions) + + /// + /// Occurs when the measurements for vertical snap points change. + /// + static member onVerticalSnapPointsChanged<'t when 't :> VirtualizingStackPanel>(func: RoutedEventArgs -> unit, ?subPatchOptions) : IAttr<'t> = + AttrBuilder<'t>.CreateSubscription(VirtualizingStackPanel.VerticalSnapPointsChangedEvent, func, ?subPatchOptions = subPatchOptions) + + /// + /// Gets or sets the axis along which items are laid out. + /// + static member orientation<'t when 't :> VirtualizingStackPanel>(orientation: Orientation) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(VirtualizingStackPanel.OrientationProperty, orientation, ValueNone) + + /// + /// Gets or sets whether the horizontal snap points for the ``Avalonia.Controls.VirtualizingStackPanel`` are equidistant from each other. + /// + static member areHorizontalSnapPointsRegular<'t when 't :> VirtualizingStackPanel>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(VirtualizingStackPanel.AreHorizontalSnapPointsRegularProperty, value, ValueNone) + + /// + /// Gets or sets whether the vertical snap points for the ``Avalonia.Controls.VirtualizingStackPanel`` are equidistant from each other. + /// + static member areVerticalSnapPointsRegular<'t when 't :> VirtualizingStackPanel>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(VirtualizingStackPanel.AreVerticalSnapPointsRegularProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Primitives/AdornerLayer.fs b/src/Avalonia.FuncUI/DSL/Primitives/AdornerLayer.fs new file mode 100644 index 00000000..e41fb6f4 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Primitives/AdornerLayer.fs @@ -0,0 +1,36 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia +open Avalonia.Controls +open Avalonia.Controls.Primitives + +[] +module AdornerLayer = + open Avalonia.FuncUI + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type Visual with + static member adornedElement<'t, 'u when 't :> Visual and 'u :> Visual>(value: 'u) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(AdornerLayer.AdornedElementProperty, value, ValueNone) + + static member adornedElement<'t, 'u when 't :> Visual and 'u :> Visual>(view: IView<'u>) : IAttr<'t> = + let view = generalize view + AttrBuilder<'t>.CreateContentSingle(AdornerLayer.AdornedElementProperty, Some view) + + static member isClipEnabled<'t when 't :> Visual>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(AdornerLayer.IsClipEnabledProperty, value, ValueNone) + + static member adorner<'t, 'c when 't :> Visual and 'c :> Control>(value: 'c) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(AdornerLayer.AdornerProperty, value, ValueNone) + + static member adorner<'t, 'c when 't :> Visual and 'c :> Control>(view: IView<'c>) : IAttr<'t> = + let view = generalize view + AttrBuilder<'t>.CreateContentSingle(AdornerLayer.AdornerProperty, Some view) + + type AdornerLayer with + static member fefaultFocusAdorner<'t, 'c when 't :> AdornerLayer and 'c :> Control>(value: ITemplate<'c>) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty>(AdornerLayer.DefaultFocusAdornerProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Primitives/CalendarItem.fs b/src/Avalonia.FuncUI/DSL/Primitives/CalendarItem.fs new file mode 100644 index 00000000..a45c9b59 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Primitives/CalendarItem.fs @@ -0,0 +1,40 @@ +namespace Avalonia.FuncUI.DSL + +[] +module CalendarItem = + open Avalonia.Controls.Primitives + open Avalonia.Controls.Templates + open Avalonia.Media + open Avalonia.Media.Immutable + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type CalendarItem with + + /// Set the background color of the header + /// + /// Because of CalendarItem is sealed, this binding is only for CalendarItem + static member headerBackground(value: IBrush) : IAttr = + AttrBuilder.CreateProperty(CalendarItem.HeaderBackgroundProperty, value, ValueNone) + + + /// Set the background color of the header + /// + /// Because of CalendarItem is sealed, this binding is only for CalendarItem + static member headerBackground(color: string) : IAttr = + color |> Color.Parse |> ImmutableSolidColorBrush |> CalendarItem.headerBackground + + /// Set the foreground color of the header + /// + /// Because of CalendarItem is sealed, this binding is only for CalendarItem + static member headerForeground(color: Color) : IAttr = + color |> ImmutableSolidColorBrush |> CalendarItem.headerBackground + + /// Set day title template. + /// + /// Because of CalendarItem is sealed, this binding is only for CalendarItem + static member dayTitleTemplate(value: IDataTemplate) : IAttr = + AttrBuilder.CreateProperty(CalendarItem.DayTitleTemplateProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Primitives/ChromeOverlayLayer.fs b/src/Avalonia.FuncUI/DSL/Primitives/ChromeOverlayLayer.fs new file mode 100644 index 00000000..60de5704 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Primitives/ChromeOverlayLayer.fs @@ -0,0 +1,13 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia.Controls.Primitives + +[] +module ChromeOverlayLayer = + open Avalonia.FuncUI.Types + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type ChromeOverlayLayer with + end diff --git a/src/Avalonia.FuncUI/DSL/Primitives/HeaderedItemsControl.fs b/src/Avalonia.FuncUI/DSL/Primitives/HeaderedItemsControl.fs index 1897e79f..bf605784 100644 --- a/src/Avalonia.FuncUI/DSL/Primitives/HeaderedItemsControl.fs +++ b/src/Avalonia.FuncUI/DSL/Primitives/HeaderedItemsControl.fs @@ -3,6 +3,7 @@ [] module HeaderedItemsControl = open Avalonia.Controls.Primitives + open Avalonia.Controls.Templates open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder @@ -21,4 +22,7 @@ module HeaderedItemsControl = AttrBuilder<'t>.CreateContentSingle(HeaderedItemsControl.HeaderProperty, value) static member header<'t when 't :> HeaderedItemsControl>(value: IView) : IAttr<'t> = - value |> Some |> HeaderedItemsControl.header \ No newline at end of file + value |> Some |> HeaderedItemsControl.header + + static member headerTemplate<'t when 't :> HeaderedItemsControl>(value: IDataTemplate) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(HeaderedItemsControl.HeaderTemplateProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Primitives/HeaderedSelectingItemsControl.fs b/src/Avalonia.FuncUI/DSL/Primitives/HeaderedSelectingItemsControl.fs index f96bb0ac..3e3ab42f 100644 --- a/src/Avalonia.FuncUI/DSL/Primitives/HeaderedSelectingItemsControl.fs +++ b/src/Avalonia.FuncUI/DSL/Primitives/HeaderedSelectingItemsControl.fs @@ -3,6 +3,7 @@ namespace Avalonia.FuncUI.DSL [] module HeaderedSelectingItemsControl = open Avalonia.Controls.Primitives + open Avalonia.Controls.Templates open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder @@ -20,4 +21,7 @@ module HeaderedSelectingItemsControl = AttrBuilder<'t>.CreateContentSingle(HeaderedSelectingItemsControl.HeaderProperty, value) static member header<'t when 't :> HeaderedSelectingItemsControl>(value: IView) : IAttr<'t> = - value |> Some |> HeaderedSelectingItemsControl.header \ No newline at end of file + value |> Some |> HeaderedSelectingItemsControl.header + + static member headerTemplate<'t when 't :> HeaderedSelectingItemsControl>(value: IDataTemplate) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(HeaderedSelectingItemsControl.HeaderTemplateProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Primitives/LightDismissOverlayLayer.fs b/src/Avalonia.FuncUI/DSL/Primitives/LightDismissOverlayLayer.fs new file mode 100644 index 00000000..24b006be --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Primitives/LightDismissOverlayLayer.fs @@ -0,0 +1,20 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia.Controls.Primitives +open Avalonia.Input + +[] +module LightDismissOverlayLayer = + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type LightDismissOverlayLayer with + static member inputPassThroughElement<'t when 't :> LightDismissOverlayLayer>(element: IInputElement) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.InputPassThroughElement + let getter: 't -> IInputElement = (fun control -> control.InputPassThroughElement) + let setter: 't * IInputElement -> unit = (fun (control, value) -> control.InputPassThroughElement <- value) + + AttrBuilder<'t>.CreateProperty(name, element, ValueSome getter, ValueSome setter, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Primitives/OverlayLayer.fs b/src/Avalonia.FuncUI/DSL/Primitives/OverlayLayer.fs new file mode 100644 index 00000000..a2ac9a61 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Primitives/OverlayLayer.fs @@ -0,0 +1,13 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia.Controls.Primitives + +[] +module OverlayLayer = + open Avalonia.FuncUI.Types + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type OverlayLayer with + end \ No newline at end of file diff --git a/src/Avalonia.FuncUI/DSL/Primitives/PickerPresenterBase.fs b/src/Avalonia.FuncUI/DSL/Primitives/PickerPresenterBase.fs new file mode 100644 index 00000000..fd3c8689 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Primitives/PickerPresenterBase.fs @@ -0,0 +1,34 @@ +namespace Avalonia.FuncUI.DSL + +[] +module PickerPresenterBase = + open System + open Avalonia.Controls.Primitives + open Avalonia.FuncUI.Builder + + type PickerPresenterBase with + static member onConfirmed<'t when 't :> PickerPresenterBase>(func: 't -> unit, ?subPatchOptions) = + let name = nameof Unchecked.defaultof<'t>.Confirmed + let factory: SubscriptionFactory<'t> = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun s e -> func(s :?> 't)) + let event = control.Confirmed + + event.AddHandler(handler) + token.Register(fun _ -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription<'t>(name, factory, func, ?subPatchOptions = subPatchOptions) + + static member onDismissed<'t when 't :> PickerPresenterBase>(func: 't -> unit, ?subPatchOptions) = + let name = nameof Unchecked.defaultof<'t>.Dismissed + let factory: SubscriptionFactory<'t> = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun s e -> func(s :?> 't)) + let event = control.Dismissed + + event.AddHandler(handler) + token.Register(fun _ -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription<'t>(name, factory, func, ?subPatchOptions = subPatchOptions) diff --git a/src/Avalonia.FuncUI/DSL/Primitives/Popup.fs b/src/Avalonia.FuncUI/DSL/Primitives/Popup.fs index f5b613ee..59a50b45 100644 --- a/src/Avalonia.FuncUI/DSL/Primitives/Popup.fs +++ b/src/Avalonia.FuncUI/DSL/Primitives/Popup.fs @@ -3,31 +3,68 @@ namespace Avalonia.FuncUI.DSL [] module Popup = + open System open Avalonia open Avalonia.Controls open Avalonia.Controls.Primitives open Avalonia.Controls.Primitives.PopupPositioning + open Avalonia.Input open Avalonia.FuncUI.Builder open Avalonia.FuncUI.Types - open System let create (attrs: IAttr list): IView = ViewBuilder.Create(attrs) - + type Popup with - + + static member onClosed<'t when 't :> Popup>(func: 't -> unit, ?subPatchOptions) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.Closed + let factory: SubscriptionFactory<'t> = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun s e -> func(s :?> 't)) + let event = control.Closed + + event.AddHandler(handler) + token.Register(fun _ -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription<'t>(name, factory, func, ?subPatchOptions = subPatchOptions) + + static member onOpened<'t when 't :> Popup>(func: 't -> unit, ?subPatchOptions) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.Opened + let factory: SubscriptionFactory<'t> = + fun (control, func, token) -> + let control = control :?> 't + let handler = EventHandler(fun s e -> func(s :?> 't)) + let event = control.Opened + + event.AddHandler(handler) + token.Register(fun _ -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription<'t>(name, factory, func, ?subPatchOptions = subPatchOptions) + static member child<'t when 't :> Popup>(value: IView option) : IAttr<'t> = AttrBuilder<'t>.CreateContentSingle(Popup.ChildProperty, value) - + static member child<'t when 't :> Popup>(value: IView) : IAttr<'t> = value |> Some |> Popup.child - + + static member dependencyResolver<'t when 't :> Popup>(value: IAvaloniaDependencyResolver) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.DependencyResolver + let getter: 't -> IAvaloniaDependencyResolver = (fun control -> control.DependencyResolver) + let setter: 't * IAvaloniaDependencyResolver -> unit = (fun (control, value) -> control.DependencyResolver <- value) + + AttrBuilder<'t>.CreateProperty(name, value, ValueSome getter, ValueSome setter, ValueNone) + + static member inheritsTransform<'t when 't :> Popup>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(Popup.InheritsTransformProperty, value, ValueNone) + static member isOpen<'t when 't :> Popup>(value: bool) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Popup.IsOpenProperty, value, ValueNone) - + static member isLightDismissEnabled<'t when 't :> Popup>(value: bool) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Popup.IsLightDismissEnabledProperty, value, ValueNone) - + static member topmost<'t when 't :> Popup>(value: bool) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Popup.TopmostProperty, value, ValueNone) @@ -36,7 +73,7 @@ module Popup = static member placementAnchor<'t when 't :> Popup>(value: PopupAnchor) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Popup.PlacementAnchorProperty, value, ValueNone) - + static member placementConstraintAdjustment<'t when 't :> Popup>(value: PopupPositionerConstraintAdjustment) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Popup.PlacementConstraintAdjustmentProperty, value, ValueNone) @@ -55,15 +92,21 @@ module Popup = [] static member placementMode<'t when 't :> Popup>(value: PlacementMode) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Popup.PlacementModeProperty, value, ValueNone) - + static member placementTarget<'t when 't :> Popup>(value: Control) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Popup.PlacementTargetProperty, value, ValueNone) - + + static member overlayDismissEventPassThrough<'t when 't :> Popup>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(Popup.OverlayDismissEventPassThroughProperty, value, ValueNone) + + static member overlayInputPassThroughElement<'t when 't :> Popup>(value: IInputElement) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(Popup.OverlayInputPassThroughElementProperty, value, ValueNone) + static member verticalOffset<'t when 't :> Popup>(value: double) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Popup.VerticalOffsetProperty, value, ValueNone) - + static member horizontalOffset<'t when 't :> Popup>(value: double) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Popup.HorizontalOffsetProperty, value, ValueNone) static member windowManagerAddShadowHint<'t when 't :> Popup>(value: bool) : IAttr<'t> = - AttrBuilder<'t>.CreateProperty(Popup.WindowManagerAddShadowHintProperty, value, ValueNone) \ No newline at end of file + AttrBuilder<'t>.CreateProperty(Popup.WindowManagerAddShadowHintProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Primitives/ScrollBar.fs b/src/Avalonia.FuncUI/DSL/Primitives/ScrollBar.fs index 5ba9970d..f4774b14 100644 --- a/src/Avalonia.FuncUI/DSL/Primitives/ScrollBar.fs +++ b/src/Avalonia.FuncUI/DSL/Primitives/ScrollBar.fs @@ -2,31 +2,56 @@ namespace Avalonia.FuncUI.DSL [] module ScrollBar = + open System open Avalonia.Layout open Avalonia.Controls.Primitives open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder - + let create (attrs: IAttr list): IView = ViewBuilder.Create(attrs) - + type ScrollBar with - + static member onScroll<'t when 't :> ScrollBar>(func: ScrollEventArgs -> unit, ?subPatchOptions) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.Scroll + let factory: SubscriptionFactory = + fun (control, func, token) -> + let content = control :?> 't + let handler = EventHandler(fun sender args -> func args) + let event = content.Scroll + + event.AddHandler(handler) + token.Register(fun () -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription(name, factory, func, ?subPatchOptions = subPatchOptions) + + /// + /// Gets a value that indicates whether the scrollbar can hide itself when user is not interacting with it. + /// static member allowAutoHide<'t when 't :> ScrollBar>(value: bool) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ScrollBar.AllowAutoHideProperty, value, ValueNone) + /// + /// Gets a value that determines how long will be the hide delay after user stops interacting with the scrollbar. + /// + static member hideDelay<'t when 't :> ScrollBar>(value: TimeSpan) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollBar.HideDelayProperty, value, ValueNone) + + /// + /// Gets a value that indicates whether the scrollbar is expanded. + /// static member isExpanded<'t when 't :> ScrollBar>(value: bool) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ScrollBar.IsExpandedProperty, value, ValueNone) - + /// /// Sets the amount of the scrollable content that is currently visible. /// static member viewportSize<'t when 't :> ScrollBar>(value: double) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ScrollBar.ViewportSizeProperty, value, ValueNone) - + /// /// Sets a value that indicates whether the scrollbar should hide itself when it is not needed. - /// + /// static member visibility<'t when 't :> ScrollBar>(visibility: ScrollBarVisibility) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ScrollBar.VisibilityProperty, visibility, ValueNone) @@ -34,4 +59,10 @@ module ScrollBar = /// Sets the orientation of the scrollbar. /// static member orientation<'t when 't :> ScrollBar>(orientation: Orientation) : IAttr<'t> = - AttrBuilder<'t>.CreateProperty(ScrollBar.OrientationProperty, orientation, ValueNone) \ No newline at end of file + AttrBuilder<'t>.CreateProperty(ScrollBar.OrientationProperty, orientation, ValueNone) + + /// + /// Gets a value that determines how long will be the show delay when user starts interacting with the scrollbar. + /// + static member showDelay<'t when 't :> ScrollBar>(value: TimeSpan) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollBar.ShowDelayProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Primitives/SelectingItemsControl.fs b/src/Avalonia.FuncUI/DSL/Primitives/SelectingItemsControl.fs index 25cd9002..1cf7668c 100644 --- a/src/Avalonia.FuncUI/DSL/Primitives/SelectingItemsControl.fs +++ b/src/Avalonia.FuncUI/DSL/Primitives/SelectingItemsControl.fs @@ -4,12 +4,18 @@ namespace Avalonia.FuncUI.DSL module SelectingItemsControl = open Avalonia.Controls.Primitives open Avalonia.Controls + open Avalonia.Data + open Avalonia.Interactivity open Avalonia.FuncUI.Builder open Avalonia.FuncUI.Types let create (attrs: IAttr list): IView = ViewBuilder.Create(attrs) + type Control with + static member isSelected<'t when 't :> Control>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(SelectingItemsControl.IsSelectedProperty, value, ValueNone) + type SelectingItemsControl with static member autoScrollToSelectedItem<'t when 't :> SelectingItemsControl>(value: bool) : IAttr<'t> = @@ -24,11 +30,26 @@ module SelectingItemsControl = static member selectedItem<'t when 't :> SelectingItemsControl>(item: obj) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(SelectingItemsControl.SelectedItemProperty, item, ValueNone) + static member selectedValueBinding<'t when 't :> SelectingItemsControl>(binding: IBinding) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(SelectingItemsControl.SelectedValueBindingProperty, binding, ValueNone) + + static member selectedValue<'t when 't :> SelectingItemsControl>(value: obj) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(SelectingItemsControl.SelectedValueProperty, value, ValueNone) + + static member isTextSearchEnabled<'t when 't :> SelectingItemsControl>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(SelectingItemsControl.IsTextSearchEnabledProperty, value, ValueNone) + + static member wrapSelection<'t when 't :> SelectingItemsControl>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(SelectingItemsControl.WrapSelectionProperty, value, ValueNone) + static member selection<'t when 't :> SelectingItemsControl>(model: Selection.ISelectionModel) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ListBox.SelectionProperty, model, ValueNone) static member onSelectedItemChanged<'t when 't :> SelectingItemsControl>(func: obj -> unit, ?subPatchOptions) = AttrBuilder<'t>.CreateSubscription(SelectingItemsControl.SelectedItemProperty, func, ?subPatchOptions = subPatchOptions) + static member onIsSelectedChanged<'t when 't :> SelectingItemsControl>(func: RoutedEventArgs -> unit, ?subPatchOptions) = + AttrBuilder<'t>.CreateSubscription(SelectingItemsControl.IsSelectedChangedEvent, func, ?subPatchOptions = subPatchOptions) + static member onSelectionChanged<'t when 't :> SelectingItemsControl>(func: SelectionChangedEventArgs -> unit, ?subPatchOptions) = AttrBuilder<'t>.CreateSubscription(SelectingItemsControl.SelectionChangedEvent, func, ?subPatchOptions = subPatchOptions) diff --git a/src/Avalonia.FuncUI/DSL/Primitives/TextElement.fs b/src/Avalonia.FuncUI/DSL/Primitives/TextElement.fs index eb4c66e7..d2fc0d94 100644 --- a/src/Avalonia.FuncUI/DSL/Primitives/TextElement.fs +++ b/src/Avalonia.FuncUI/DSL/Primitives/TextElement.fs @@ -1,45 +1,68 @@ namespace Avalonia.FuncUI.DSL +open Avalonia.Controls open Avalonia.Controls.Documents +open Avalonia.Media +open Avalonia.Media.Immutable [] module TextElement = - open Avalonia.Media.Immutable open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder - open Avalonia.Media - - let create (attrs: IAttr list): IView = - ViewBuilder.Create(attrs) - + + type Control with + static member fontFamily<'t when 't :> Control>(value: FontFamily) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextElement.FontFamilyProperty, value, ValueNone) + + static member fontSize<'t when 't :> Control>(value: double) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextElement.FontSizeProperty, value, ValueNone) + + static member fontStyle<'t when 't :> Control>(value: FontStyle) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextElement.FontStyleProperty, value, ValueNone) + + static member fontWeight<'t when 't :> Control>(value: FontWeight) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextElement.FontWeightProperty, value, ValueNone) + + static member fontStretch<'t when 't :> Control>(value: FontStretch) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextElement.FontStretchProperty, value, ValueNone) + + static member foreground<'t when 't :> Control>(value: IBrush) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TextElement.ForegroundProperty, value, ValueNone) + + static member foreground<'t when 't :> Control>(color: string) : IAttr<'t> = + Color.Parse(color) |> ImmutableSolidColorBrush |> Control.foreground + + static member foreground<'t when 't :> Control>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> Control.foreground + type TextElement with static member background<'t when 't :> TextElement>(value: IBrush) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TextElement.BackgroundProperty, value, ValueNone) - + static member background<'t when 't :> TextElement>(color: string) : IAttr<'t> = Color.Parse(color) |> ImmutableSolidColorBrush |> TextElement.background static member background<'t when 't :> TextElement>(color: Color) : IAttr<'t> = color |> ImmutableSolidColorBrush |> TextElement.background - + static member fontFamily<'t when 't :> TextElement>(value: FontFamily) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TextElement.FontFamilyProperty, value, ValueNone) - + static member fontSize<'t when 't :> TextElement>(value: double) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TextElement.FontSizeProperty, value, ValueNone) - + static member fontStyle<'t when 't :> TextElement>(value: FontStyle) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TextElement.FontStyleProperty, value, ValueNone) - + static member fontStretch<'t when 't :> TextElement>(value: FontStretch) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TextElement.FontStretchProperty, value, ValueNone) static member fontWeight<'t when 't :> TextElement>(value: FontWeight) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TextElement.FontWeightProperty, value, ValueNone) - + static member foreground<'t when 't :> TextElement>(value: IBrush) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TextElement.ForegroundProperty, value, ValueNone) - + static member foreground<'t when 't :> TextElement>(color: string) : IAttr<'t> = Color.Parse(color) |> ImmutableSolidColorBrush |> TextElement.foreground diff --git a/src/Avalonia.FuncUI/DSL/Primitives/VisualLayerManager.fs b/src/Avalonia.FuncUI/DSL/Primitives/VisualLayerManager.fs new file mode 100644 index 00000000..37752643 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Primitives/VisualLayerManager.fs @@ -0,0 +1,19 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia.Controls.Primitives + +[] +module VisualLayerManager = + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type VisualLayerManager with + static member isPopup<'t when 't :> VisualLayerManager>(value: bool) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.IsPopup + let getter: 't -> bool = (fun control -> control.IsPopup) + let setter: 't * bool -> unit = (fun (control, value) -> control.IsPopup <- value) + + AttrBuilder<'t>.CreateProperty(name, value, ValueSome getter, ValueSome setter, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/ProgressBar.fs b/src/Avalonia.FuncUI/DSL/ProgressBar.fs index 107f2c16..8dcf2af4 100644 --- a/src/Avalonia.FuncUI/DSL/ProgressBar.fs +++ b/src/Avalonia.FuncUI/DSL/ProgressBar.fs @@ -6,7 +6,7 @@ module ProgressBar = open Avalonia.Controls open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder - + let create (attrs: IAttr list): IView = ViewBuilder.Create(attrs) @@ -20,3 +20,6 @@ module ProgressBar = static member showProgressText<'t when 't :> ProgressBar>(value: bool) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ProgressBar.ShowProgressTextProperty, value, ValueNone) + + static member progressTextFormat<'t when 't :> ProgressBar>(value: string) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ProgressBar.ProgressTextFormatProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/RefreshContainer.fs b/src/Avalonia.FuncUI/DSL/RefreshContainer.fs new file mode 100644 index 00000000..59ca4653 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/RefreshContainer.fs @@ -0,0 +1,23 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia.Controls +open Avalonia.Input + +[] +module RefreshContainer = + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type RefreshContainer with + + static member onRefreshRequested<'t when 't :> RefreshContainer>(func: RefreshRequestedEventArgs -> unit, ?subPatchOptions) = + AttrBuilder<'t>.CreateSubscription(RefreshContainer.RefreshRequestedEvent, func, ?subPatchOptions = subPatchOptions) + + static member refreshVisualizer<'t when 't :> RefreshContainer>(value: RefreshVisualizer) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(RefreshContainer.VisualizerProperty, value, ValueNone) + + static member pullDirection<'t when 't :> RefreshContainer>(value: PullDirection) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(RefreshContainer.PullDirectionProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/RefreshVisualizer.fs b/src/Avalonia.FuncUI/DSL/RefreshVisualizer.fs new file mode 100644 index 00000000..b067e7fb --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/RefreshVisualizer.fs @@ -0,0 +1,19 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia.Controls + +[] +module RefreshVisualizer = + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type RefreshVisualizer with + + static member onRefreshRequested<'t when 't :> RefreshVisualizer>(func: RefreshRequestedEventArgs -> unit, ?subPatchOptions) : IAttr<'t> = + AttrBuilder<'t>.CreateSubscription(RefreshVisualizer.RefreshRequestedEvent, func, ?subPatchOptions = subPatchOptions) + + static member orientation<'t when 't :> RefreshVisualizer>(value: RefreshVisualizerOrientation) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(RefreshVisualizer.OrientationProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Remote/RemoteWidget.fs b/src/Avalonia.FuncUI/DSL/Remote/RemoteWidget.fs new file mode 100644 index 00000000..f93bebe9 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Remote/RemoteWidget.fs @@ -0,0 +1,21 @@ +namespace Avalonia.FuncUI.DSL + +[] +module RemoteWidget = + open Avalonia.Controls.Remote + open Avalonia.Remote.Protocol + + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (connection:IAvaloniaRemoteTransportConnection) (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + |> View.withConstructorArgs [|connection|] + + type RemoteWidget with + static member mode<'t when 't :> RemoteWidget>(value: RemoteWidget.SizingMode) : IAttr<'t> = + let name = nameof Unchecked.defaultof<'t>.Mode + let getter: 't -> RemoteWidget.SizingMode = fun x -> x.Mode + let setter: 't * RemoteWidget.SizingMode -> unit = fun (x, v) -> x.Mode <- v + + AttrBuilder<'t>.CreateProperty(name, value, ValueSome getter, ValueSome setter, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/ScrollViewer.fs b/src/Avalonia.FuncUI/DSL/ScrollViewer.fs index c6a2ff70..b1881e4d 100644 --- a/src/Avalonia.FuncUI/DSL/ScrollViewer.fs +++ b/src/Avalonia.FuncUI/DSL/ScrollViewer.fs @@ -13,34 +13,78 @@ module ScrollViewer = type Control with + /// + /// Gets or sets a value that determines whether the uses a + /// bring-into-view scroll behavior when an item in the view gets focus. + /// + /// + /// + /// true to use a behavior that brings focused items into view. false to use a behavior + /// that focused items do not automatically scroll into view. The default is true. + /// + static member bringIntoViewOnFocusChange<'t when 't :> Control>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollViewer.BringIntoViewOnFocusChangeProperty, value, ValueNone) + /// /// Sets the vertical scrollbar visibility. /// static member verticalScrollBarVisibility<'t when 't :> Control>(value: ScrollBarVisibility) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ScrollViewer.VerticalScrollBarVisibilityProperty, value, ValueNone) + /// + /// Gets or sets how scroll gesture reacts to the snap points along the vertical axis. + /// + static member verticalSnapPointsType<'t when 't :> Control>(value: SnapPointsType) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollViewer.VerticalSnapPointsTypeProperty, value, ValueNone) + + /// + /// Gets or sets how the existing snap points are vertically aligned versus the initial viewport. + /// + static member verticalSnapPointsAlignment<'t when 't :> Control>(value: SnapPointsAlignment) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollViewer.VerticalSnapPointsAlignmentProperty, value, ValueNone) + /// /// Sets the horizontal scrollbar visibility. /// static member horizontalScrollBarVisibility<'t when 't :> Control>(value: ScrollBarVisibility) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ScrollViewer.HorizontalScrollBarVisibilityProperty, value, ValueNone) - type ScrollViewer with + /// + /// Gets or sets how scroll gesture reacts to the snap points along the horizontal axis. + /// + static member horizontalSnapPointsType<'t when 't :> Control>(value: SnapPointsType) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollViewer.HorizontalSnapPointsTypeProperty, value, ValueNone) + + /// + /// Gets or sets how the existing snap points are horizontally aligned versus the initial viewport. + /// + static member horizontalSnapPointsAlignment<'t when 't :> Control>(value: SnapPointsAlignment) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollViewer.HorizontalSnapPointsAlignmentProperty, value, ValueNone) - static member allowAutoHide<'t when 't :> ScrollViewer>(value: bool) : IAttr<'t> = + /// + /// Gets a value that indicates whether scrollbars can hide itself when user is not interacting with it. + /// + static member allowAutoHide<'t when 't :> Control>(value: bool) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ScrollViewer.AllowAutoHideProperty, value, ValueNone) /// - /// Sets the extent of the scrollable content. + /// Gets or sets if scroll chaining is enabled. The default value is true. /// - static member extent<'t when 't :> ScrollViewer>(value: Size) : IAttr<'t> = - AttrBuilder<'t>.CreateProperty(ScrollViewer.ExtentProperty, value, ValueNone) + /// + /// After a user hits a scroll limit on an element that has been nested within another scrollable element, + /// you can specify whether that parent element should continue the scrolling operation begun in its child element. + /// This is called scroll chaining. + /// + static member isScrollChainingEnabled<'t when 't :> Control>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollViewer.IsScrollChainingEnabledProperty, value, ValueNone) - static member isExpanded<'t when 't :> ScrollViewer>(value: bool) : IAttr<'t> = - AttrBuilder<'t>.CreateProperty(ScrollViewer.IsExpandedProperty, value, ValueNone) + /// + /// Gets or sets whether scroll gestures should include inertia in their behavior and value. + /// + static member isScrollInertiaEnabled<'t when 't :> Control>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ScrollViewer.IsScrollInertiaEnabledProperty, value, ValueNone) - static member largeChange<'t when 't :> ScrollViewer>(value: Size) : IAttr<'t> = - AttrBuilder<'t>.CreateProperty(ScrollViewer.LargeChangeProperty, value, ValueNone) + type ScrollViewer with /// /// Sets the current scroll offset. @@ -48,14 +92,8 @@ module ScrollViewer = static member offset<'t when 't :> ScrollViewer>(value: Vector) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(ScrollViewer.OffsetProperty, value, ValueNone) - static member onScrollChanged<'t when 't :> ScrollViewer>(func: ScrollChangedEventArgs -> unit, ?subPatchOptions) = - AttrBuilder<'t>.CreateSubscription(ScrollViewer.ScrollChangedEvent, func, ?subPatchOptions = subPatchOptions) - - static member smallChange<'t when 't :> ScrollViewer>(value: Size) : IAttr<'t> = - AttrBuilder<'t>.CreateProperty(ScrollViewer.SmallChangeProperty, value, ValueNone) - /// - /// Sets the size of the viewport on the scrollable content. + /// Occurs when changes are detected to the scroll position, extent, or viewport size. /// - static member viewport<'t when 't :> ScrollViewer>(value: Size) : IAttr<'t> = - AttrBuilder<'t>.CreateProperty(ScrollViewer.ViewportProperty, value, ValueNone) \ No newline at end of file + static member onScrollChanged<'t when 't :> ScrollViewer>(func: ScrollChangedEventArgs -> unit, ?subPatchOptions) = + AttrBuilder<'t>.CreateSubscription(ScrollViewer.ScrollChangedEvent, func, ?subPatchOptions = subPatchOptions) diff --git a/src/Avalonia.FuncUI/DSL/SelectableTextBlock.fs b/src/Avalonia.FuncUI/DSL/SelectableTextBlock.fs index c47bb998..c5f95e05 100644 --- a/src/Avalonia.FuncUI/DSL/SelectableTextBlock.fs +++ b/src/Avalonia.FuncUI/DSL/SelectableTextBlock.fs @@ -1,11 +1,39 @@ namespace Avalonia.FuncUI.DSL +open Avalonia.Controls +open Avalonia.Interactivity +open Avalonia.Media +open Avalonia.Media.Immutable [] module SelectableTextBlock = - open Avalonia.Controls open Avalonia.FuncUI.Builder open Avalonia.FuncUI.Types let create (attrs: IAttr list): IView = ViewBuilder.Create(attrs) + + type SelectableTextBlock with + static member onCopyingToClipboard<'t when 't :> SelectableTextBlock>(func: RoutedEventArgs -> unit, ?subPatchOptions) : IAttr<'t> = + AttrBuilder<'t>.CreateSubscription(SelectableTextBlock.CopyingToClipboardEvent, func, ?subPatchOptions = subPatchOptions) + + static member onSelectedTextChanged<'t when 't :> SelectableTextBlock>(func: string -> unit, ?subPatchOptions) : IAttr<'t> = + AttrBuilder<'t>.CreateSubscription(SelectableTextBlock.SelectedTextProperty, func, ?subPatchOptions = subPatchOptions) + + static member onCanCopyChanged<'t when 't :> SelectableTextBlock>(func: bool -> unit, ?subPatchOptions) : IAttr<'t> = + AttrBuilder<'t>.CreateSubscription(SelectableTextBlock.CanCopyProperty, func, ?subPatchOptions = subPatchOptions) + + static member selectionBrush<'t when 't :> SelectableTextBlock>(value: IBrush) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(SelectableTextBlock.SelectionBrushProperty, value, ValueNone) + + static member selectionBrush<'t when 't :> SelectableTextBlock>(color: string) : IAttr<'t> = + Color.Parse(color) |> ImmutableSolidColorBrush |> SelectableTextBlock.selectionBrush + + static member selectionBrush<'t when 't :> SelectableTextBlock>(color: Color) : IAttr<'t> = + ImmutableSolidColorBrush(color) |> SelectableTextBlock.selectionBrush + + static member selectionStart<'t when 't :> SelectableTextBlock>(value: int) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(SelectableTextBlock.SelectionStartProperty, value, ValueNone) + + static member selectionEnd<'t when 't :> SelectableTextBlock>(value: int) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(SelectableTextBlock.SelectionEndProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Shapes/Arc.fs b/src/Avalonia.FuncUI/DSL/Shapes/Arc.fs new file mode 100644 index 00000000..a566fe2a --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Shapes/Arc.fs @@ -0,0 +1,18 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia.Controls.Shapes + +[] +module Arc = + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type Arc with + static member startAngle<'t when 't :> Arc>(value: double) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(Arc.StartAngleProperty, value, ValueNone) + + static member swwpAngle<'t when 't :> Arc>(value: double) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(Arc.SweepAngleProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Shapes/Rectangle.fs b/src/Avalonia.FuncUI/DSL/Shapes/Rectangle.fs index 9af7a20b..0e2ed210 100644 --- a/src/Avalonia.FuncUI/DSL/Shapes/Rectangle.fs +++ b/src/Avalonia.FuncUI/DSL/Shapes/Rectangle.fs @@ -5,6 +5,13 @@ module Rectangle = open Avalonia.Controls.Shapes open Avalonia.FuncUI.Builder open Avalonia.FuncUI.Types - + let create (attrs: IAttr list): IView = - ViewBuilder.Create(attrs) \ No newline at end of file + ViewBuilder.Create(attrs) + + type Rectangle with + static member radiusX<'t when 't :> Rectangle>(value: double) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(Rectangle.RadiusXProperty, value, ValueNone) + + static member radiusY<'t when 't :> Rectangle>(value: double) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(Rectangle.RadiusYProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Shapes/Sector.fs b/src/Avalonia.FuncUI/DSL/Shapes/Sector.fs new file mode 100644 index 00000000..d1bf8e83 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/Shapes/Sector.fs @@ -0,0 +1,17 @@ +namespace Avalonia.FuncUI.DSL + +[] +module Sector = + open Avalonia.Controls.Shapes + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type Sector with + static member startAngle<'t when 't :> Sector>(value: double) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(Sector.StartAngleProperty, value, ValueNone) + + static member sweepAngle<'t when 't :> Sector>(value: double) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(Sector.SweepAngleProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Shapes/Shape.fs b/src/Avalonia.FuncUI/DSL/Shapes/Shape.fs index f539d43e..e3dcdc62 100644 --- a/src/Avalonia.FuncUI/DSL/Shapes/Shape.fs +++ b/src/Avalonia.FuncUI/DSL/Shapes/Shape.fs @@ -6,6 +6,7 @@ open Avalonia.Media.Immutable module Shape = open Avalonia.Controls.Shapes open Avalonia.Media + open Avalonia.FuncUI open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder @@ -13,39 +14,43 @@ module Shape = static member fill<'t when 't :> Shape>(brush: IBrush) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Shape.FillProperty, brush, ValueNone) - + static member fill<'t when 't :> Shape>(color: string) : IAttr<'t> = color |> Color.Parse |> ImmutableSolidColorBrush |> Shape.fill static member fill<'t when 't :> Shape>(color: Color) : IAttr<'t> = color |> ImmutableSolidColorBrush |> Shape.fill - + static member stretch<'t when 't :> Shape>(value: Stretch) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Shape.StretchProperty, value, ValueNone) - + static member stroke<'t when 't :> Shape>(brush: IBrush) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Shape.StrokeProperty, brush, ValueNone) - + static member stroke<'t when 't :> Shape>(color: string) : IAttr<'t> = color |> Color.Parse |> ImmutableSolidColorBrush |> Shape.stroke static member stroke<'t when 't :> Shape>(color: Color) : IAttr<'t> = color |> ImmutableSolidColorBrush |> Shape.stroke - + static member strokeThickness<'t when 't :> Shape>(value: double) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Shape.StrokeThicknessProperty, value, ValueNone) - + static member strokeDashArray<'t when 't :> Shape>(value: AvaloniaList) : IAttr<'t> = AttrBuilder<'t>.CreateProperty>(Shape.StrokeDashArrayProperty, value, ValueNone) - + static member strokeDashArray<'t when 't :> Shape>(value: double list) : IAttr<'t> = - value |> AvaloniaList |> Shape.strokeDashArray - + let name = nameof Unchecked.defaultof<'t>.StrokeDashArray + let getter: 't -> double list = fun x -> Seq.toList x.StrokeDashArray + let setter: 't * double list -> unit = fun (x, value) -> Setters.avaloniaList x.StrokeDashArray value + + AttrBuilder<'t>.CreateProperty(name, value, ValueSome getter, ValueSome setter, ValueNone) + static member strokeDashOffset<'t when 't :> Shape>(value: double) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Shape.StrokeDashOffsetProperty, value, ValueNone) - + static member strokeLineCap<'t when 't :> Shape>(value: PenLineCap) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Shape.StrokeLineCapProperty, value, ValueNone) - static member strokeJoinCap<'t when 't :> Shape>(value: PenLineJoin) : IAttr<'t> = - AttrBuilder<'t>.CreateProperty(Shape.StrokeJoinProperty, value, ValueNone) \ No newline at end of file + static member strokeJoin<'t when 't :> Shape>(value: PenLineJoin) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(Shape.StrokeJoinProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Slider.fs b/src/Avalonia.FuncUI/DSL/Slider.fs index 30e59d89..0a903901 100644 --- a/src/Avalonia.FuncUI/DSL/Slider.fs +++ b/src/Avalonia.FuncUI/DSL/Slider.fs @@ -5,13 +5,14 @@ module Slider = open Avalonia.Collections open Avalonia.Controls open Avalonia.Layout + open Avalonia.FuncUI open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder - + let create (attrs: IAttr list): IView = ViewBuilder.Create(attrs) - type Slider with + type Slider with /// /// Sets the orientation of a . @@ -31,11 +32,31 @@ module Slider = static member tickFrequency<'t when 't :> Slider>(value: float) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Slider.TickFrequencyProperty, value, ValueNone) + /// + /// Gets or sets a value that indicates where to draw tick marks in relation to the track. + /// static member tickPlacement<'t when 't :> Slider>(value: TickPlacement) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Slider.TickPlacementProperty, value, ValueNone) + /// + /// Defines the ticks to be drawn on the tick bar. + /// static member ticks<'t when 't :> Slider>(value: AvaloniaList) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Slider.TicksProperty, value, ValueNone) + /// + /// Defines the ticks to be drawn on the tick bar. + /// static member ticks<'t when 't :> Slider>(value: seq) : IAttr<'t> = - value |> AvaloniaList |> Slider.ticks \ No newline at end of file + let name = nameof Unchecked.defaultof<'t>.Ticks + let getter: 't -> float seq = fun (x: 't) -> x.Ticks + let setter: 't * float seq -> unit = fun (x: 't, v) -> Setters.avaloniaList x.Ticks v + let factory: unit -> float seq = fun () -> [] + + AttrBuilder<'t>.CreateProperty(name, value, ValueSome getter, ValueSome setter, ValueNone, factory) + + /// + /// Gets or sets the direction of increasing value. + /// + static member isDirectionReversed<'t when 't :> Slider>(value: bool) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(Slider.IsDirectionReversedProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/SplitView.fs b/src/Avalonia.FuncUI/DSL/SplitView.fs index f3dea8ca..34e4abfc 100644 --- a/src/Avalonia.FuncUI/DSL/SplitView.fs +++ b/src/Avalonia.FuncUI/DSL/SplitView.fs @@ -3,6 +3,8 @@ [] module SplitView = open Avalonia.Controls + open Avalonia.Controls.Templates + open Avalonia.Interactivity open Avalonia.Media open Avalonia.Media.Immutable open Avalonia.FuncUI.Types @@ -11,7 +13,19 @@ module SplitView = let create (attrs: IAttr list): IView = ViewBuilder.Create(attrs) - type SplitView with + type SplitView with + + static member onPaneClosed<'t when 't :> SplitView>(func: RoutedEventArgs -> unit, ?subPatchOptions) = + AttrBuilder<'t>.CreateSubscription(SplitView.PaneClosedEvent, func, ?subPatchOptions = subPatchOptions) + + static member onPaneClosing<'t when 't :> SplitView>(func: CancelRoutedEventArgs -> unit, ?subPatchOptions) = + AttrBuilder<'t>.CreateSubscription(SplitView.PaneClosingEvent, func, ?subPatchOptions = subPatchOptions) + + static member onPaneOpened<'t when 't :> SplitView>(func: RoutedEventArgs -> unit, ?subPatchOptions) = + AttrBuilder<'t>.CreateSubscription(SplitView.PaneOpenedEvent, func, ?subPatchOptions = subPatchOptions) + + static member onPaneOpening<'t when 't :> SplitView>(func: CancelRoutedEventArgs -> unit, ?subPatchOptions) = + AttrBuilder<'t>.CreateSubscription(SplitView.PaneOpeningEvent, func, ?subPatchOptions = subPatchOptions) static member content<'t when 't :> SplitView>(value: IView option) : IAttr<'t> = AttrBuilder<'t>.CreateContentSingle(SplitView.ContentProperty, value) @@ -49,6 +63,9 @@ module SplitView = static member pane<'t when 't :> SplitView>(value: IView) : IAttr<'t> = value |> Some |> SplitView.pane + static member paneTemplate<'t when 't :> SplitView>(value: IDataTemplate) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(SplitView.PaneTemplateProperty, value, ValueNone) + static member useLightDismissOverlayMode<'t when 't :> SplitView>(value: bool) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(SplitView.UseLightDismissOverlayModeProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/ThemeVariantScope.fs b/src/Avalonia.FuncUI/DSL/ThemeVariantScope.fs new file mode 100644 index 00000000..e0f22522 --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/ThemeVariantScope.fs @@ -0,0 +1,16 @@ +namespace Avalonia.FuncUI.DSL + +open Avalonia.Controls +open Avalonia.Styling + +[] +module ThemeVariantScope = + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type ThemeVariantScope with + static member requestedThemeVariant<'t when 't :> ThemeVariantScope>(value: ThemeVariant) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(ThemeVariantScope.RequestedThemeVariantProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/TickBar.fs b/src/Avalonia.FuncUI/DSL/TickBar.fs index 7cfb0853..30d3c64a 100644 --- a/src/Avalonia.FuncUI/DSL/TickBar.fs +++ b/src/Avalonia.FuncUI/DSL/TickBar.fs @@ -8,12 +8,13 @@ module TickBar = open Avalonia.Media open Avalonia.Media.Immutable open Avalonia.Layout + open Avalonia.FuncUI open Avalonia.FuncUI.Types open Avalonia.FuncUI.Builder - + let create (attrs: IAttr list): IView = ViewBuilder.Create(attrs) - + type TickBar with static member fill<'t when 't :> TickBar>(value: IBrush) : IAttr<'t> = @@ -50,4 +51,10 @@ module TickBar = AttrBuilder<'t>.CreateProperty(TickBar.TicksProperty, value, ValueNone) static member ticks<'t when 't :> TickBar>(value: seq) : IAttr<'t> = - value |> AvaloniaList |> TickBar.ticks + let name = nameof Unchecked.defaultof<'t>.Ticks + let getter: 't -> seq = (fun control -> control.Ticks) + let setter: 't * seq -> unit = (fun (control, value) -> Setters.avaloniaList control.Ticks value) + let compare: obj * obj -> bool = fun (a, b) -> EqualityComparers.compareSeq<_,float>(a, b) + let factory = fun () -> Seq.empty + + AttrBuilder<'t>.CreateProperty>(name, value, ValueSome getter, ValueSome setter, ValueSome compare, factory) diff --git a/src/Avalonia.FuncUI/DSL/TimePickerPresenter.fs b/src/Avalonia.FuncUI/DSL/TimePickerPresenter.fs new file mode 100644 index 00000000..adb4baab --- /dev/null +++ b/src/Avalonia.FuncUI/DSL/TimePickerPresenter.fs @@ -0,0 +1,25 @@ +namespace Avalonia.FuncUI.DSL + +open System +open Avalonia.Controls + +[] +module TimePickerPresenter = + open Avalonia.FuncUI.Types + open Avalonia.FuncUI.Builder + + let create (attrs: IAttr list): IView = + ViewBuilder.Create(attrs) + + type TimePickerPresenter with + /// Gets or sets the minute increment in the selector + static member minuteIncrement<'t when 't :> TimePickerPresenter>(value: int) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TimePickerPresenter.MinuteIncrementProperty, value, ValueNone) + + /// Gets or sets the current clock identifier, either 12HourClock or 24HourClock + static member clockIdentifier<'t when 't :> TimePickerPresenter>(value: string) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TimePickerPresenter.ClockIdentifierProperty, value, ValueNone) + + /// Gets or sets the current time + static member time<'t when 't :> TimePickerPresenter>(value: TimeSpan) : IAttr<'t> = + AttrBuilder<'t>.CreateProperty(TimePickerPresenter.TimeProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/TreeView.fs b/src/Avalonia.FuncUI/DSL/TreeView.fs index f81b6b09..6656b3f7 100644 --- a/src/Avalonia.FuncUI/DSL/TreeView.fs +++ b/src/Avalonia.FuncUI/DSL/TreeView.fs @@ -11,6 +11,21 @@ module TreeView = ViewBuilder.Create(attrs) type TreeView with + /// + /// Occurs when the control's selection changes. + /// + static member onSelectionChanged<'t when 't :> TreeView>(func: SelectionChangedEventArgs -> unit, ?subPatchOptions) = + let name = nameof Unchecked.defaultof<'t>.SelectionChanged + let factory: SubscriptionFactory = + fun (control, func, token) -> + let control = control :?> 't + let handler = System.EventHandler(fun s e -> func e) + let event = control.SelectionChanged + + event.AddHandler(handler) + token.Register(fun _ -> event.RemoveHandler(handler)) |> ignore + + AttrBuilder<'t>.CreateSubscription(name, factory, func, ?subPatchOptions = subPatchOptions) /// /// Sets a value indicating whether to automatically scroll to newly selected items.