From 33a0cd795a7f31244a646f4ffd6b874709dd5f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= <3542167+beyon@users.noreply.github.com> Date: Mon, 30 Oct 2023 18:46:09 +0100 Subject: [PATCH] Adding more Color overloads for brush properties (#363) * 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 * 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/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/TextBlock.fs | 6 ++++++ src/Avalonia.FuncUI/DSL/TextBox.fs | 9 +++++++++ 9 files changed, 49 insertions(+), 1 deletion(-) 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 928961a6..83fe1ba1 100644 --- a/src/Avalonia.FuncUI/DSL/DataGrid.fs +++ b/src/Avalonia.FuncUI/DSL/DataGrid.fs @@ -118,6 +118,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/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)