From dbd68e31b7d481712b5c85abf26dbeed8b451381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Aneer?= <3542167+beyon@users.noreply.github.com> Date: Fri, 27 Oct 2023 20:20:34 +0200 Subject: [PATCH 1/2] Added Color overloads to IBrush properties for consistency and ergonomics Some Controls already allowed to set brush properties with Color directly while others only had color: string This adds such overloads where they were missing --- src/Avalonia.FuncUI/DSL/Base/ContentPresenter.fs | 6 ++++++ src/Avalonia.FuncUI/DSL/Base/Panel.fs | 5 ++++- src/Avalonia.FuncUI/DSL/Border.fs | 3 +++ src/Avalonia.FuncUI/DSL/DataGrid.fs | 3 +++ src/Avalonia.FuncUI/DSL/Primitives/TemplatedControl.fs | 6 ++++++ src/Avalonia.FuncUI/DSL/Primitives/TextElement.fs | 6 ++++++ src/Avalonia.FuncUI/DSL/Shapes/Shape.fs | 6 ++++++ src/Avalonia.FuncUI/DSL/SplitView.fs | 4 ++-- src/Avalonia.FuncUI/DSL/TextBlock.fs | 6 ++++++ src/Avalonia.FuncUI/DSL/TextBox.fs | 9 +++++++++ src/Avalonia.FuncUI/DSL/TickBar.fs | 4 ++-- 11 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.FuncUI/DSL/Base/ContentPresenter.fs b/src/Avalonia.FuncUI/DSL/Base/ContentPresenter.fs index 68403afa..9605d0b2 100644 --- a/src/Avalonia.FuncUI/DSL/Base/ContentPresenter.fs +++ b/src/Avalonia.FuncUI/DSL/Base/ContentPresenter.fs @@ -21,11 +21,17 @@ module ContentPresenter = static member background<'t when 't :> ContentPresenter>(color: string) : IAttr<'t> = Color.Parse(color) |> ImmutableSolidColorBrush |> ContentPresenter.background + static member background<'t when 't :> ContentPresenter>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> ContentPresenter.background + 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) diff --git a/src/Avalonia.FuncUI/DSL/Base/Panel.fs b/src/Avalonia.FuncUI/DSL/Base/Panel.fs index ad1f7828..4c510bcd 100644 --- a/src/Avalonia.FuncUI/DSL/Base/Panel.fs +++ b/src/Avalonia.FuncUI/DSL/Base/Panel.fs @@ -19,4 +19,7 @@ module Panel = AttrBuilder<'t>.CreateProperty(Panel.BackgroundProperty, value, ValueNone) static member background<'t when 't :> Panel>(color: string) : IAttr<'t> = - color |> Color.Parse |> ImmutableSolidColorBrush |> Panel.background \ No newline at end of file + color |> Color.Parse |> ImmutableSolidColorBrush |> Panel.background + + static member background<'t when 't :> Panel>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> Panel.background \ No newline at end of file diff --git a/src/Avalonia.FuncUI/DSL/Border.fs b/src/Avalonia.FuncUI/DSL/Border.fs index 587a25c6..2431e42a 100644 --- a/src/Avalonia.FuncUI/DSL/Border.fs +++ b/src/Avalonia.FuncUI/DSL/Border.fs @@ -27,6 +27,9 @@ module Border = static member borderBrush<'t when 't :> Border>(color: string) : IAttr<'t> = color |> Color.Parse |> ImmutableSolidColorBrush |> Border.borderBrush + + static member borderBrush<'t when 't :> Border>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> Border.borderBrush static member borderThickness<'t when 't :> Border>(value: Thickness) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(Border.BorderThicknessProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/DataGrid.fs b/src/Avalonia.FuncUI/DSL/DataGrid.fs index 33441a23..ae854053 100644 --- a/src/Avalonia.FuncUI/DSL/DataGrid.fs +++ b/src/Avalonia.FuncUI/DSL/DataGrid.fs @@ -109,6 +109,9 @@ module DataGridTextColumn = static member foreground<'t when 't :> DataGridTextColumn>(color: string) : IAttr<'t> = color |> Color.Parse |> ImmutableSolidColorBrush |> DataGridTextColumn.foreground + static member foreground<'t when 't :> DataGridTextColumn>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> DataGridTextColumn.foreground + [] module DataGridCheckBoxColumn = diff --git a/src/Avalonia.FuncUI/DSL/Primitives/TemplatedControl.fs b/src/Avalonia.FuncUI/DSL/Primitives/TemplatedControl.fs index b81aa996..fbd30d85 100644 --- a/src/Avalonia.FuncUI/DSL/Primitives/TemplatedControl.fs +++ b/src/Avalonia.FuncUI/DSL/Primitives/TemplatedControl.fs @@ -20,11 +20,17 @@ module TemplatedControl = static member background<'t when 't :> TemplatedControl>(color: string) : IAttr<'t> = Color.Parse(color) |> ImmutableSolidColorBrush |> TemplatedControl.background + static member background<'t when 't :> TemplatedControl>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> TemplatedControl.background + static member borderBrush<'t when 't :> TemplatedControl>(value: IBrush) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TemplatedControl.BorderBrushProperty, value, ValueNone) static member borderBrush<'t when 't :> TemplatedControl>(color: string) : IAttr<'t> = Color.Parse(color) |> ImmutableSolidColorBrush |> TemplatedControl.borderBrush + + static member borderBrush<'t when 't :> TemplatedControl>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> TemplatedControl.borderBrush static member borderThickness<'t when 't :> TemplatedControl>(value: Thickness) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TemplatedControl.BorderThicknessProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/Primitives/TextElement.fs b/src/Avalonia.FuncUI/DSL/Primitives/TextElement.fs index 61a59392..eb4c66e7 100644 --- a/src/Avalonia.FuncUI/DSL/Primitives/TextElement.fs +++ b/src/Avalonia.FuncUI/DSL/Primitives/TextElement.fs @@ -18,6 +18,9 @@ module TextElement = 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) @@ -39,3 +42,6 @@ module TextElement = static member foreground<'t when 't :> TextElement>(color: string) : IAttr<'t> = Color.Parse(color) |> ImmutableSolidColorBrush |> TextElement.foreground + + static member foreground<'t when 't :> TextElement>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> TextElement.foreground diff --git a/src/Avalonia.FuncUI/DSL/Shapes/Shape.fs b/src/Avalonia.FuncUI/DSL/Shapes/Shape.fs index 7cd6acb1..f539d43e 100644 --- a/src/Avalonia.FuncUI/DSL/Shapes/Shape.fs +++ b/src/Avalonia.FuncUI/DSL/Shapes/Shape.fs @@ -16,6 +16,9 @@ module Shape = 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) @@ -25,6 +28,9 @@ module Shape = 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) diff --git a/src/Avalonia.FuncUI/DSL/SplitView.fs b/src/Avalonia.FuncUI/DSL/SplitView.fs index f3dea8ca..8ab5703d 100644 --- a/src/Avalonia.FuncUI/DSL/SplitView.fs +++ b/src/Avalonia.FuncUI/DSL/SplitView.fs @@ -37,8 +37,8 @@ module SplitView = static member paneBackground<'t when 't :> SplitView>(color: string) : IAttr<'t> = color |> Color.Parse |> ImmutableSolidColorBrush |> SplitView.paneBackground - static member paneBackground<'t when 't :> SplitView>(value: Color) : IAttr<'t> = - value |> ImmutableSolidColorBrush |> SplitView.paneBackground + static member paneBackground<'t when 't :> SplitView>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> SplitView.paneBackground static member panePlacement<'t when 't :> SplitView>(value: SplitViewPanePlacement) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(SplitView.PanePlacementProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/TextBlock.fs b/src/Avalonia.FuncUI/DSL/TextBlock.fs index 36b914d0..b964da0b 100644 --- a/src/Avalonia.FuncUI/DSL/TextBlock.fs +++ b/src/Avalonia.FuncUI/DSL/TextBlock.fs @@ -23,6 +23,9 @@ module TextBlock = static member background<'t when 't :> TextBlock>(color: string) : IAttr<'t> = color |> Color.Parse |> ImmutableSolidColorBrush |> TextBlock.background + + static member background<'t when 't :> TextBlock>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> TextBlock.background static member fontFamily<'t when 't :> TextBlock>(value: FontFamily) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TextBlock.FontFamilyProperty, value, ValueNone) @@ -42,6 +45,9 @@ module TextBlock = static member foreground<'t when 't :> TextBlock>(color: string) : IAttr<'t> = color |> Color.Parse |> ImmutableSolidColorBrush |> TextBlock.foreground + static member foreground<'t when 't :> TextBlock>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> TextBlock.foreground + static member inlines<'t when 't :> TextBlock>(value: InlineCollection) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TextBlock.InlinesProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/TextBox.fs b/src/Avalonia.FuncUI/DSL/TextBox.fs index 6ea503e6..cb19f13a 100644 --- a/src/Avalonia.FuncUI/DSL/TextBox.fs +++ b/src/Avalonia.FuncUI/DSL/TextBox.fs @@ -38,18 +38,27 @@ module TextBox = static member selectionBrush<'t when 't :> TextBox>(color: string) : IAttr<'t> = color |> Color.Parse |> ImmutableSolidColorBrush |> TextBox.selectionBrush + static member selectionBrush<'t when 't :> TextBox>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> TextBox.selectionBrush + static member selectionForegroundBrush<'t when 't :> TextBox>(value: IBrush) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TextBox.SelectionForegroundBrushProperty, value, ValueNone) static member selectionForegroundBrush<'t when 't :> TextBox>(color: string) : IAttr<'t> = color |> Color.Parse |> ImmutableSolidColorBrush |> TextBox.selectionForegroundBrush + static member selectionForegroundBrush<'t when 't :> TextBox>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> TextBox.selectionForegroundBrush + static member caretBrush<'t when 't :> TextBox>(value: IBrush) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TextBox.CaretBrushProperty, value, ValueNone) static member caretBrush<'t when 't :> TextBox>(color: string) : IAttr<'t> = color |> Color.Parse |> ImmutableSolidColorBrush |> TextBox.selectionBrush + static member caretBrush<'t when 't :> TextBox>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> TextBox.selectionBrush + static member selectionStart<'t when 't :> TextBox>(value: int) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TextBox.SelectionStartProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/TickBar.fs b/src/Avalonia.FuncUI/DSL/TickBar.fs index 7cfb0853..884d7401 100644 --- a/src/Avalonia.FuncUI/DSL/TickBar.fs +++ b/src/Avalonia.FuncUI/DSL/TickBar.fs @@ -19,8 +19,8 @@ module TickBar = static member fill<'t when 't :> TickBar>(value: IBrush) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TickBar.FillProperty, value, ValueNone) - static member fill<'t when 't :> TickBar>(value: Color) : IAttr<'t> = - value |> ImmutableSolidColorBrush |> TickBar.fill + static member fill<'t when 't :> TickBar>(color: Color) : IAttr<'t> = + color |> ImmutableSolidColorBrush |> TickBar.fill static member fill<'t when 't :> TickBar>(color: string) : IAttr<'t> = color |> Color.Parse |> TickBar.fill From fc4290c98484d740f4c9b32b53905f3f1b6bd7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Aneer?= <3542167+beyon@users.noreply.github.com> Date: Mon, 30 Oct 2023 16:46:38 +0100 Subject: [PATCH 2/2] Revert parameter renaming of value->color Renaming could potentially break code using named parameters, however with only one parameter such usage seems unlikely --- src/Avalonia.FuncUI/DSL/SplitView.fs | 4 ++-- src/Avalonia.FuncUI/DSL/TickBar.fs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.FuncUI/DSL/SplitView.fs b/src/Avalonia.FuncUI/DSL/SplitView.fs index 8ab5703d..f3dea8ca 100644 --- a/src/Avalonia.FuncUI/DSL/SplitView.fs +++ b/src/Avalonia.FuncUI/DSL/SplitView.fs @@ -37,8 +37,8 @@ module SplitView = static member paneBackground<'t when 't :> SplitView>(color: string) : IAttr<'t> = color |> Color.Parse |> ImmutableSolidColorBrush |> SplitView.paneBackground - static member paneBackground<'t when 't :> SplitView>(color: Color) : IAttr<'t> = - color |> ImmutableSolidColorBrush |> SplitView.paneBackground + static member paneBackground<'t when 't :> SplitView>(value: Color) : IAttr<'t> = + value |> ImmutableSolidColorBrush |> SplitView.paneBackground static member panePlacement<'t when 't :> SplitView>(value: SplitViewPanePlacement) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(SplitView.PanePlacementProperty, value, ValueNone) diff --git a/src/Avalonia.FuncUI/DSL/TickBar.fs b/src/Avalonia.FuncUI/DSL/TickBar.fs index 884d7401..7cfb0853 100644 --- a/src/Avalonia.FuncUI/DSL/TickBar.fs +++ b/src/Avalonia.FuncUI/DSL/TickBar.fs @@ -19,8 +19,8 @@ module TickBar = static member fill<'t when 't :> TickBar>(value: IBrush) : IAttr<'t> = AttrBuilder<'t>.CreateProperty(TickBar.FillProperty, value, ValueNone) - static member fill<'t when 't :> TickBar>(color: Color) : IAttr<'t> = - color |> ImmutableSolidColorBrush |> TickBar.fill + static member fill<'t when 't :> TickBar>(value: Color) : IAttr<'t> = + value |> ImmutableSolidColorBrush |> TickBar.fill static member fill<'t when 't :> TickBar>(color: string) : IAttr<'t> = color |> Color.Parse |> TickBar.fill