Skip to content

Commit

Permalink
Adding more Color overloads for brush properties (#363)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
beyon authored Oct 30, 2023
1 parent 4727963 commit 33a0cd7
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Avalonia.FuncUI/DSL/Base/ContentPresenter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IBrush>(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<Thickness>(ContentPresenter.BorderThicknessProperty, value, ValueNone)
Expand Down
5 changes: 4 additions & 1 deletion src/Avalonia.FuncUI/DSL/Base/Panel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ module Panel =
AttrBuilder<'t>.CreateProperty<IBrush>(Panel.BackgroundProperty, value, ValueNone)

static member background<'t when 't :> Panel>(color: string) : IAttr<'t> =
color |> Color.Parse |> ImmutableSolidColorBrush |> Panel.background
color |> Color.Parse |> ImmutableSolidColorBrush |> Panel.background

static member background<'t when 't :> Panel>(color: Color) : IAttr<'t> =
color |> ImmutableSolidColorBrush |> Panel.background
3 changes: 3 additions & 0 deletions src/Avalonia.FuncUI/DSL/Border.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Thickness>(Border.BorderThicknessProperty, value, ValueNone)
Expand Down
3 changes: 3 additions & 0 deletions src/Avalonia.FuncUI/DSL/DataGrid.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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


[<AutoOpen>]
module DataGridCheckBoxColumn =
Expand Down
6 changes: 6 additions & 0 deletions src/Avalonia.FuncUI/DSL/Primitives/TemplatedControl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IBrush>(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<Thickness>(TemplatedControl.BorderThicknessProperty, value, ValueNone)
Expand Down
6 changes: 6 additions & 0 deletions src/Avalonia.FuncUI/DSL/Primitives/TextElement.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FontFamily>(TextElement.FontFamilyProperty, value, ValueNone)
Expand All @@ -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
6 changes: 6 additions & 0 deletions src/Avalonia.FuncUI/DSL/Shapes/Shape.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Stretch>(Shape.StretchProperty, value, ValueNone)
Expand All @@ -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<double>(Shape.StrokeThicknessProperty, value, ValueNone)
Expand Down
6 changes: 6 additions & 0 deletions src/Avalonia.FuncUI/DSL/TextBlock.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FontFamily>(TextBlock.FontFamilyProperty, value, ValueNone)
Expand All @@ -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<InlineCollection>(TextBlock.InlinesProperty, value, ValueNone)

Expand Down
9 changes: 9 additions & 0 deletions src/Avalonia.FuncUI/DSL/TextBox.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IBrush>(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<IBrush>(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<int>(TextBox.SelectionStartProperty, value, ValueNone)

Expand Down

0 comments on commit 33a0cd7

Please sign in to comment.