-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix classes and styles properties on StyledElement - fix classes property on StyledElement. - move styles property to IStyleHost.fs. * control catalog: add styles demo back - add styles demo back - update styles.xaml for FluentTheme * fix IStyleHost.styles - compare list of IStyle correctly - setter should also update Resources * add tests for `IStyleHost.styles` and `Control.classes` properties. * add dataTemplates property. * add onPropertyChanged event. * add Net Event Attr functions. * add Visual DSL functions. * use `nameof` expression * add Layoutable DSL functions. * add InputElement DSL functions. * add Control DSL functions. * add Inline DSL functions. * add TextDecoration DSL functions. * add TextBlock DSL functions. * add Image DSL functions. * move stryles DSL into StyledElement.fs * add Flyout DSL functions. * refactor subscription function if passing event source, to use AddHandler/RemoveHandler. * add TemplatedControl bindings. * add TextBox bindings. * add ItemsControl bindings. * Type parameters Modified to explicitly. * documentation for updating `Classes`' standard classes Expanded the documentation for the `patchStandardClasses` function, which updates the standard classes of `Classes`, with detailed explanations about the mixture of standard classes and pseudoclasses. * fix isPseudoClass - StartsWith ... use Char instead of String. - update comment. * move dataTemplates binding functions to Control.fs * Remove onTextChanged (TextBox.TextChangingEvent -> unit) binding. * add test for AttrBuilder<'t>.CreateSubscription<'arg>(name, factory, func, ?subPatchOptions) * Refactor list / AvaloniaList / IList value bindings - Add helper function for IList<'t>. - Use helper function instead of custom Internals functions. - For list<'t> binding, remove custom compare function. * fix compare function.
- Loading branch information
Showing
21 changed files
with
1,082 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
src/Avalonia.FuncUI.UnitTests/DSL/Base/StyledElementTests.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
namespace Avalonia.FuncUI.UnitTests.DSL | ||
|
||
open Avalonia | ||
open Avalonia.Controls | ||
open global.Xunit | ||
|
||
module StyledElementTests = | ||
open Avalonia.FuncUI.VirtualDom | ||
open Avalonia.FuncUI.DSL | ||
open Avalonia.FuncUI.Types | ||
open Avalonia.Styling | ||
|
||
let twoAttrs<'x, 't> (attr: 'x -> IAttr<'t>) a b = | ||
[ attr a :> IAttr ], [ attr b :> IAttr ] | ||
|
||
[<Fact>] | ||
let ``classes equality with string list`` () = | ||
let valueList() = [ "class1"; "class2" ] | ||
|
||
let classes1 = valueList() | ||
let classes2 = valueList() | ||
|
||
let stringList = | ||
(classes1, classes2) | ||
||> twoAttrs StyledElement.classes | ||
|> Differ.diffAttributes | ||
|
||
Assert.Empty stringList | ||
|
||
[<Fact>] | ||
let ``classes equality with same classes instance`` () = | ||
let classes = Classes() | ||
classes.Add "class1" | ||
classes.Add "class2" | ||
|
||
let sameClassesInstance = | ||
(classes, classes) ||> twoAttrs StyledElement.classes |> Differ.diffAttributes | ||
|
||
Assert.Empty sameClassesInstance | ||
|
||
[<Fact>] | ||
let ``classes equality with different classes instance`` () = | ||
let classes1 = Classes() | ||
classes1.Add "class1" | ||
classes1.Add "class2" | ||
|
||
let classes2 = Classes() | ||
classes2.Add "class1" | ||
classes2.Add "class2" | ||
|
||
let differentClassesInstance = | ||
(classes1, classes2) ||> twoAttrs StyledElement.classes |> Differ.diffAttributes | ||
|
||
Assert.Empty differentClassesInstance | ||
|
||
let initStyle () = | ||
let s = Style(fun x -> x.Is<Control>()) | ||
s.Setters.Add(Setter(Control.TagProperty, "foo")) | ||
s :> IStyle | ||
|
||
[<Fact>] | ||
let ``styles equality with style list has same style instance`` () = | ||
let style = initStyle () | ||
|
||
let styleList () = [ style ] | ||
|
||
let styles1 = styleList () | ||
let styles2 = styleList () | ||
|
||
let styleList = | ||
(styles1, styles2) ||> twoAttrs StyledElement.styles |> Differ.diffAttributes | ||
|
||
Assert.Empty styleList | ||
|
||
|
||
[<Fact>] | ||
let ``styles equality with style list has different style instance`` () = | ||
|
||
let style1 = initStyle () | ||
let style2 = initStyle () | ||
|
||
let styleList = | ||
([ style1 ], [ style2 ]) ||> twoAttrs StyledElement.styles |> Differ.diffAttributes | ||
|
||
match Assert.Single styleList with | ||
| Delta.AttrDelta.Property { Accessor = InstanceProperty { Name = propName } | ||
Value = Some(:? list<IStyle> as [ value ]) } -> | ||
Assert.Equal("Styles", propName) | ||
Assert.NotEqual(style1, value) | ||
Assert.Equal(style2, value) | ||
|
||
| _ -> Assert.Fail $"Not expected delta\n{styleList}" | ||
|
||
[<Fact>] | ||
let ``styles equality with Styles property has same instance`` () = | ||
let style = initStyle () | ||
|
||
let styles = Styles() | ||
styles.Add style | ||
|
||
let styles1 = styles | ||
let styles2 = styles | ||
|
||
let styleList = | ||
(styles1, styles2) ||> twoAttrs StyledElement.styles |> Differ.diffAttributes | ||
|
||
Assert.Empty styleList | ||
|
||
[<Fact>] | ||
let ``styles equality with Styles property has different Styles instance has same style instance`` () = | ||
let style = initStyle () | ||
|
||
let styles1 = Styles() | ||
styles1.Add style | ||
styles1.Resources.Add("key", "value") | ||
|
||
let styles2 = Styles() | ||
styles2.Add style | ||
styles2.Resources.Add("key", "value") | ||
|
||
let styleList = | ||
(styles1, styles2) ||> twoAttrs StyledElement.styles |> Differ.diffAttributes | ||
|
||
Assert.Empty styleList | ||
|
||
[<Fact>] | ||
let ``styles equality with Styles property has different Styles instance has different style instance`` () = | ||
let style1 = initStyle () | ||
let style2 = initStyle () | ||
|
||
let styles1 = Styles() | ||
styles1.Add style1 | ||
styles1.Resources.Add("key", "value") | ||
|
||
let styles2 = Styles() | ||
styles2.Add style2 | ||
styles2.Resources.Add("key", "value") | ||
|
||
let styleList = | ||
(styles1, styles2) ||> twoAttrs StyledElement.styles |> Differ.diffAttributes | ||
|
||
match Assert.Single styleList with | ||
| Delta.AttrDelta.Property { Accessor = InstanceProperty { Name = propName } | ||
Value = Some(:? Styles as value) } -> | ||
Assert.Equal("Styles", propName) | ||
Assert.NotEqual<Styles>(styles1, value) | ||
Assert.Equal<Styles>(styles2, value) | ||
|
||
| _ -> Assert.Fail $"Not expected delta\n{styleList}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.