Browse Source

Merge branch 'master' into volume_names_fixes

pull/8134/head
Jumar Macato 4 years ago
committed by GitHub
parent
commit
2c178071f5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      build/CoreLibraries.props
  2. 1
      samples/BindingDemo/BindingDemo.csproj
  3. 2
      samples/ControlCatalog/ControlCatalog.csproj
  4. 6
      samples/ControlCatalog/Pages/TextBoxPage.xaml
  5. 3
      samples/IntegrationTestApp/IntegrationTestApp.csproj
  6. 1
      samples/PlatformSanityChecks/PlatformSanityChecks.csproj
  7. 3
      samples/Previewer/Previewer.csproj
  8. 1
      samples/RenderDemo/RenderDemo.csproj
  9. 1
      samples/Sandbox/Sandbox.csproj
  10. 1
      samples/VirtualizationDemo/VirtualizationDemo.csproj
  11. 1
      samples/interop/Direct3DInteropSample/Direct3DInteropSample.csproj
  12. 1
      samples/interop/NativeEmbedSample/NativeEmbedSample.csproj
  13. 5
      src/Avalonia.Base/DirectPropertyBase.cs
  14. 2
      src/Avalonia.Base/Input/InputElement.cs
  15. 8
      src/Avalonia.Base/StyledPropertyBase.cs
  16. 5
      src/Avalonia.Base/Styling/IStyleInstance.cs
  17. 10
      src/Avalonia.Base/Styling/PropertySetterInstance.cs
  18. 31
      src/Avalonia.Base/Styling/PropertySetterTemplateInstance.cs
  19. 9
      src/Avalonia.Base/Styling/Setter.cs
  20. 35
      src/Avalonia.Base/Styling/StyleInstance.cs
  21. 33
      src/Avalonia.Controls/Calendar/CalendarItem.cs
  22. 25
      src/Avalonia.Controls/Presenters/TextPresenter.cs
  23. 19
      src/Avalonia.Controls/TextBox.cs
  24. 3
      src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlDetailsViewModel.cs
  25. 1
      src/Avalonia.Themes.Default/Controls/TextBox.xaml
  26. 1
      src/Avalonia.Themes.Fluent/Controls/TextBox.xaml
  27. 4
      tests/Avalonia.Base.UnitTests/Input/PointerOverTests.cs
  28. 11
      tests/Avalonia.Base.UnitTests/Styling/SetterTests.cs
  29. 2
      tests/Avalonia.Controls.UnitTests/CalendarTests.cs

2
build/CoreLibraries.props

@ -3,8 +3,6 @@
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Base/Avalonia.Base.csproj" /> <ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Base/Avalonia.Base.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Controls/Avalonia.Controls.csproj" /> <ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Controls/Avalonia.Controls.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.DesignerSupport/Avalonia.DesignerSupport.csproj" /> <ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.DesignerSupport/Avalonia.DesignerSupport.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Themes.Default/Avalonia.Themes.Default.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Themes.Fluent/Avalonia.Themes.Fluent.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.OpenGL/Avalonia.OpenGL.csproj" /> <ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.OpenGL/Avalonia.OpenGL.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Dialogs/Avalonia.Dialogs.csproj" /> <ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Dialogs/Avalonia.Dialogs.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Markup/Avalonia.Markup/Avalonia.Markup.csproj" /> <ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Markup/Avalonia.Markup/Avalonia.Markup.csproj" />

1
samples/BindingDemo/BindingDemo.csproj

@ -5,6 +5,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" /> <ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Themes.Default\Avalonia.Themes.Default.csproj" />
<ProjectReference Include="..\..\src\Linux\Avalonia.LinuxFramebuffer\Avalonia.LinuxFramebuffer.csproj" /> <ProjectReference Include="..\..\src\Linux\Avalonia.LinuxFramebuffer\Avalonia.LinuxFramebuffer.csproj" />
<ProjectReference Include="..\MiniMvvm\MiniMvvm.csproj" /> <ProjectReference Include="..\MiniMvvm\MiniMvvm.csproj" />
</ItemGroup> </ItemGroup>

2
samples/ControlCatalog/ControlCatalog.csproj

@ -25,6 +25,8 @@
<ProjectReference Include="..\..\packages\Avalonia\Avalonia.csproj" /> <ProjectReference Include="..\..\packages\Avalonia\Avalonia.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Controls.ColorPicker\Avalonia.Controls.ColorPicker.csproj" /> <ProjectReference Include="..\..\src\Avalonia.Controls.ColorPicker\Avalonia.Controls.ColorPicker.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Controls.DataGrid\Avalonia.Controls.DataGrid.csproj" /> <ProjectReference Include="..\..\src\Avalonia.Controls.DataGrid\Avalonia.Controls.DataGrid.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Themes.Default\Avalonia.Themes.Default.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Themes.Fluent\Avalonia.Themes.Fluent.csproj" />
<ProjectReference Include="..\MiniMvvm\MiniMvvm.csproj" /> <ProjectReference Include="..\MiniMvvm\MiniMvvm.csproj" />
<ProjectReference Include="..\SampleControls\ControlSamples.csproj" /> <ProjectReference Include="..\SampleControls\ControlSamples.csproj" />
</ItemGroup> </ItemGroup>

6
samples/ControlCatalog/Pages/TextBoxPage.xaml

@ -66,6 +66,12 @@
FontFamily="Comic Sans MS" FontFamily="Comic Sans MS"
InputMethod.IsInputMethodEnabled="False" InputMethod.IsInputMethodEnabled="False"
Foreground="Red"/> Foreground="Red"/>
<TextBox AcceptsReturn="True"
TextWrapping="Wrap"
Width="200"
Height="125"
LineHeight="32"
Text="Multiline TextBox with TextWrapping and increased LineHeight.&#xD;&#xD;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est." />
</StackPanel> </StackPanel>
<StackPanel Orientation="Vertical" Spacing="8" Margin="8"> <StackPanel Orientation="Vertical" Spacing="8" Margin="8">
<Label Classes="h2" Target="{Binding #firstResMFont}">res_m fonts</Label> <Label Classes="h2" Target="{Binding #firstResMFont}">res_m fonts</Label>

3
samples/IntegrationTestApp/IntegrationTestApp.csproj

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
@ -18,6 +18,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" /> <ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Themes.Fluent\Avalonia.Themes.Fluent.csproj" />
</ItemGroup> </ItemGroup>
<Import Project="..\..\build\BuildTargets.targets" /> <Import Project="..\..\build\BuildTargets.targets" />

1
samples/PlatformSanityChecks/PlatformSanityChecks.csproj

@ -7,6 +7,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\Avalonia.Desktop\Avalonia.Desktop.csproj" /> <ProjectReference Include="..\..\src\Avalonia.Desktop\Avalonia.Desktop.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Themes.Default\Avalonia.Themes.Default.csproj" />
<ProjectReference Include="..\..\src\Avalonia.X11\Avalonia.X11.csproj" /> <ProjectReference Include="..\..\src\Avalonia.X11\Avalonia.X11.csproj" />
</ItemGroup> </ItemGroup>

3
samples/Previewer/Previewer.csproj

@ -9,6 +9,9 @@
</Compile> </Compile>
<EmbeddedResource Include="**\*.xaml" /> <EmbeddedResource Include="**\*.xaml" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Avalonia.Themes.Default\Avalonia.Themes.Default.csproj" />
</ItemGroup>
<Import Project="..\..\build\SampleApp.props" /> <Import Project="..\..\build\SampleApp.props" />
<Import Project="..\..\build\ReferenceCoreLibraries.props" /> <Import Project="..\..\build\ReferenceCoreLibraries.props" />

1
samples/RenderDemo/RenderDemo.csproj

@ -12,6 +12,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" /> <ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Themes.Fluent\Avalonia.Themes.Fluent.csproj" />
<ProjectReference Include="..\..\src\Linux\Avalonia.LinuxFramebuffer\Avalonia.LinuxFramebuffer.csproj" /> <ProjectReference Include="..\..\src\Linux\Avalonia.LinuxFramebuffer\Avalonia.LinuxFramebuffer.csproj" />
<ProjectReference Include="..\MiniMvvm\MiniMvvm.csproj" /> <ProjectReference Include="..\MiniMvvm\MiniMvvm.csproj" />
<ProjectReference Include="..\SampleControls\ControlSamples.csproj" /> <ProjectReference Include="..\SampleControls\ControlSamples.csproj" />

1
samples/Sandbox/Sandbox.csproj

@ -10,6 +10,7 @@
<ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" /> <ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Controls.ColorPicker\Avalonia.Controls.ColorPicker.csproj" /> <ProjectReference Include="..\..\src\Avalonia.Controls.ColorPicker\Avalonia.Controls.ColorPicker.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Controls.DataGrid\Avalonia.Controls.DataGrid.csproj" /> <ProjectReference Include="..\..\src\Avalonia.Controls.DataGrid\Avalonia.Controls.DataGrid.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Themes.Fluent\Avalonia.Themes.Fluent.csproj" />
</ItemGroup> </ItemGroup>
<Import Project="..\..\build\SampleApp.props" /> <Import Project="..\..\build\SampleApp.props" />

1
samples/VirtualizationDemo/VirtualizationDemo.csproj

@ -5,6 +5,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" /> <ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Themes.Default\Avalonia.Themes.Default.csproj" />
<ProjectReference Include="..\..\src\Linux\Avalonia.LinuxFramebuffer\Avalonia.LinuxFramebuffer.csproj" /> <ProjectReference Include="..\..\src\Linux\Avalonia.LinuxFramebuffer\Avalonia.LinuxFramebuffer.csproj" />
<ProjectReference Include="..\MiniMvvm\MiniMvvm.csproj" /> <ProjectReference Include="..\MiniMvvm\MiniMvvm.csproj" />
</ItemGroup> </ItemGroup>

1
samples/interop/Direct3DInteropSample/Direct3DInteropSample.csproj

@ -22,6 +22,7 @@
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\src\Avalonia.Themes.Default\Avalonia.Themes.Default.csproj" />
<ProjectReference Include="..\..\..\src\Windows\Avalonia.Direct2D1\Avalonia.Direct2D1.csproj" /> <ProjectReference Include="..\..\..\src\Windows\Avalonia.Direct2D1\Avalonia.Direct2D1.csproj" />
<ProjectReference Include="..\..\..\src\Windows\Avalonia.Win32\Avalonia.Win32.csproj" /> <ProjectReference Include="..\..\..\src\Windows\Avalonia.Win32\Avalonia.Win32.csproj" />
<ProjectReference Include="..\..\MiniMvvm\MiniMvvm.csproj" /> <ProjectReference Include="..\..\MiniMvvm\MiniMvvm.csproj" />

1
samples/interop/NativeEmbedSample/NativeEmbedSample.csproj

@ -9,6 +9,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="MonoMac.NetStandard" Version="0.0.4" /> <PackageReference Include="MonoMac.NetStandard" Version="0.0.4" />
<ProjectReference Include="..\..\..\src\Avalonia.Themes.Default\Avalonia.Themes.Default.csproj" />
<ProjectReference Include="..\..\..\src\Windows\Avalonia.Direct2D1\Avalonia.Direct2D1.csproj" /> <ProjectReference Include="..\..\..\src\Windows\Avalonia.Direct2D1\Avalonia.Direct2D1.csproj" />
<ProjectReference Include="..\..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" /> <ProjectReference Include="..\..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" />
<ProjectReference Include="..\..\..\src\Avalonia.X11\Avalonia.X11.csproj" /> <ProjectReference Include="..\..\..\src\Avalonia.X11\Avalonia.X11.csproj" />

5
src/Avalonia.Base/DirectPropertyBase.cs

@ -2,7 +2,6 @@
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Reactive; using Avalonia.Reactive;
using Avalonia.Styling; using Avalonia.Styling;
using Avalonia.Utilities;
namespace Avalonia namespace Avalonia
{ {
@ -188,10 +187,10 @@ namespace Avalonia
} }
else if (value is ITemplate template && !typeof(ITemplate).IsAssignableFrom(PropertyType)) else if (value is ITemplate template && !typeof(ITemplate).IsAssignableFrom(PropertyType))
{ {
return new PropertySetterLazyInstance<TValue>( return new PropertySetterTemplateInstance<TValue>(
target, target,
this, this,
() => (TValue)template.Build()); template);
} }
else else
{ {

2
src/Avalonia.Base/Input/InputElement.cs

@ -144,7 +144,7 @@ namespace Avalonia.Input
/// </summary> /// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerMovedEvent = public static readonly RoutedEvent<PointerEventArgs> PointerMovedEvent =
RoutedEvent.Register<InputElement, PointerEventArgs>( RoutedEvent.Register<InputElement, PointerEventArgs>(
"PointerMove", "PointerMoved",
RoutingStrategies.Tunnel | RoutingStrategies.Bubble); RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
/// <summary> /// <summary>

8
src/Avalonia.Base/StyledPropertyBase.cs

@ -1,9 +1,7 @@
using System; using System;
using System.Diagnostics;
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Reactive; using Avalonia.Reactive;
using Avalonia.Styling; using Avalonia.Styling;
using Avalonia.Utilities;
namespace Avalonia namespace Avalonia
{ {
@ -12,7 +10,7 @@ namespace Avalonia
/// </summary> /// </summary>
public abstract class StyledPropertyBase<TValue> : AvaloniaProperty<TValue>, IStyledPropertyAccessor public abstract class StyledPropertyBase<TValue> : AvaloniaProperty<TValue>, IStyledPropertyAccessor
{ {
private bool _inherits; private readonly bool _inherits;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="StyledPropertyBase{T}"/> class. /// Initializes a new instance of the <see cref="StyledPropertyBase{T}"/> class.
@ -243,10 +241,10 @@ namespace Avalonia
} }
else if (value is ITemplate template && !typeof(ITemplate).IsAssignableFrom(PropertyType)) else if (value is ITemplate template && !typeof(ITemplate).IsAssignableFrom(PropertyType))
{ {
return new PropertySetterLazyInstance<TValue>( return new PropertySetterTemplateInstance<TValue>(
target, target,
this, this,
() => (TValue)template.Build()); template);
} }
else else
{ {

5
src/Avalonia.Base/Styling/IStyleInstance.cs

@ -14,6 +14,11 @@ namespace Avalonia.Styling
/// </summary> /// </summary>
IStyle Source { get; } IStyle Source { get; }
/// <summary>
/// Gets a value indicating whether this style has an activator.
/// </summary>
bool HasActivator { get; }
/// <summary> /// <summary>
/// Gets a value indicating whether this style is active. /// Gets a value indicating whether this style is active.
/// </summary> /// </summary>

10
src/Avalonia.Base/Styling/PropertySetterInstance.cs

@ -44,7 +44,7 @@ namespace Avalonia.Styling
{ {
if (hasActivator) if (hasActivator)
{ {
if (_styledProperty is object) if (_styledProperty is not null)
{ {
_subscription = _target.Bind(_styledProperty, this, BindingPriority.StyleTrigger); _subscription = _target.Bind(_styledProperty, this, BindingPriority.StyleTrigger);
} }
@ -55,13 +55,15 @@ namespace Avalonia.Styling
} }
else else
{ {
if (_styledProperty is object) var target = (AvaloniaObject) _target;
if (_styledProperty is not null)
{ {
_subscription = _target.SetValue(_styledProperty!, _value, BindingPriority.Style); _subscription = target.SetValue(_styledProperty!, _value, BindingPriority.Style);
} }
else else
{ {
_target.SetValue(_directProperty!, _value); target.SetValue(_directProperty!, _value);
} }
} }
} }

31
src/Avalonia.Base/Styling/PropertySetterLazyInstance.cs → src/Avalonia.Base/Styling/PropertySetterTemplateInstance.cs

@ -11,42 +11,42 @@ namespace Avalonia.Styling
/// evaluated. /// evaluated.
/// </summary> /// </summary>
/// <typeparam name="T">The target property type.</typeparam> /// <typeparam name="T">The target property type.</typeparam>
internal class PropertySetterLazyInstance<T> : SingleSubscriberObservableBase<BindingValue<T>>, internal class PropertySetterTemplateInstance<T> : SingleSubscriberObservableBase<BindingValue<T>>,
ISetterInstance ISetterInstance
{ {
private readonly IStyleable _target; private readonly IStyleable _target;
private readonly StyledPropertyBase<T>? _styledProperty; private readonly StyledPropertyBase<T>? _styledProperty;
private readonly DirectPropertyBase<T>? _directProperty; private readonly DirectPropertyBase<T>? _directProperty;
private readonly Func<T> _valueFactory; private readonly ITemplate _template;
private BindingValue<T> _value; private BindingValue<T> _value;
private IDisposable? _subscription; private IDisposable? _subscription;
private bool _isActive; private bool _isActive;
public PropertySetterLazyInstance( public PropertySetterTemplateInstance(
IStyleable target, IStyleable target,
StyledPropertyBase<T> property, StyledPropertyBase<T> property,
Func<T> valueFactory) ITemplate template)
{ {
_target = target; _target = target;
_styledProperty = property; _styledProperty = property;
_valueFactory = valueFactory; _template = template;
} }
public PropertySetterLazyInstance( public PropertySetterTemplateInstance(
IStyleable target, IStyleable target,
DirectPropertyBase<T> property, DirectPropertyBase<T> property,
Func<T> valueFactory) ITemplate template)
{ {
_target = target; _target = target;
_directProperty = property; _directProperty = property;
_valueFactory = valueFactory; _template = template;
} }
public void Start(bool hasActivator) public void Start(bool hasActivator)
{ {
_isActive = !hasActivator; _isActive = !hasActivator;
if (_styledProperty is object) if (_styledProperty is not null)
{ {
var priority = hasActivator ? BindingPriority.StyleTrigger : BindingPriority.Style; var priority = hasActivator ? BindingPriority.StyleTrigger : BindingPriority.Style;
_subscription = _target.Bind(_styledProperty, this, priority); _subscription = _target.Bind(_styledProperty, this, priority);
@ -77,7 +77,7 @@ namespace Avalonia.Styling
public override void Dispose() public override void Dispose()
{ {
if (_subscription is object) if (_subscription is not null)
{ {
var sub = _subscription; var sub = _subscription;
_subscription = null; _subscription = null;
@ -85,7 +85,7 @@ namespace Avalonia.Styling
} }
else if (_isActive) else if (_isActive)
{ {
if (_styledProperty is object) if (_styledProperty is not null)
{ {
_target.ClearValue(_styledProperty); _target.ClearValue(_styledProperty);
} }
@ -101,22 +101,21 @@ namespace Avalonia.Styling
protected override void Subscribed() => PublishNext(); protected override void Subscribed() => PublishNext();
protected override void Unsubscribed() { } protected override void Unsubscribed() { }
private T GetValue() private void EnsureTemplate()
{ {
if (_value.HasValue) if (_value.HasValue)
{ {
return _value.Value; return;
} }
_value = _valueFactory(); _value = (T) _template.Build();
return _value.Value;
} }
private void PublishNext() private void PublishNext()
{ {
if (_isActive) if (_isActive)
{ {
GetValue(); EnsureTemplate();
PublishNext(_value); PublishNext(_value);
} }
else else

9
src/Avalonia.Base/Styling/Setter.cs

@ -1,9 +1,7 @@
using System; using System;
using Avalonia.Animation; using Avalonia.Animation;
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Data.Core;
using Avalonia.Metadata; using Avalonia.Metadata;
using Avalonia.Utilities;
#nullable enable #nullable enable
@ -70,12 +68,5 @@ namespace Avalonia.Styling
return Property.CreateSetterInstance(target, Value); return Property.CreateSetterInstance(target, Value);
} }
private struct SetterVisitorData
{
public IStyleable target;
public object? value;
public ISetterInstance? result;
}
} }
} }

35
src/Avalonia.Base/Styling/StyleInstance.cs

@ -11,10 +11,10 @@ namespace Avalonia.Styling
/// <summary> /// <summary>
/// A <see cref="Style"/> which has been instanced on a control. /// A <see cref="Style"/> which has been instanced on a control.
/// </summary> /// </summary>
internal class StyleInstance : IStyleInstance, IStyleActivatorSink internal sealed class StyleInstance : IStyleInstance, IStyleActivatorSink
{ {
private readonly List<ISetterInstance>? _setters; private readonly ISetterInstance[]? _setters;
private readonly List<IDisposable>? _animations; private readonly IDisposable[]? _animations;
private readonly IStyleActivator? _activator; private readonly IStyleActivator? _activator;
private readonly Subject<bool>? _animationTrigger; private readonly Subject<bool>? _animationTrigger;
@ -30,41 +30,42 @@ namespace Avalonia.Styling
_activator = activator; _activator = activator;
IsActive = _activator is null; IsActive = _activator is null;
if (setters is object) if (setters is not null)
{ {
var setterCount = setters.Count; var setterCount = setters.Count;
_setters = new List<ISetterInstance>(setterCount); _setters = new ISetterInstance[setterCount];
for (var i = 0; i < setterCount; ++i) for (var i = 0; i < setterCount; ++i)
{ {
_setters.Add(setters[i].Instance(Target)); _setters[i] = setters[i].Instance(Target);
} }
} }
if (animations is object && target is Animatable animatable) if (animations is not null && target is Animatable animatable)
{ {
var animationsCount = animations.Count; var animationsCount = animations.Count;
_animations = new List<IDisposable>(animationsCount); _animations = new IDisposable[animationsCount];
_animationTrigger = new Subject<bool>(); _animationTrigger = new Subject<bool>();
for (var i = 0; i < animationsCount; ++i) for (var i = 0; i < animationsCount; ++i)
{ {
_animations.Add(animations[i].Apply(animatable, null, _animationTrigger)); _animations[i] = animations[i].Apply(animatable, null, _animationTrigger);
} }
} }
} }
public bool HasActivator => _activator is not null;
public bool IsActive { get; private set; } public bool IsActive { get; private set; }
public IStyle Source { get; } public IStyle Source { get; }
public IStyleable Target { get; } public IStyleable Target { get; }
public void Start() public void Start()
{ {
var hasActivator = _activator is object; var hasActivator = HasActivator;
if (_setters is object) if (_setters is not null)
{ {
foreach (var setter in _setters) foreach (var setter in _setters)
{ {
@ -76,7 +77,7 @@ namespace Avalonia.Styling
{ {
_activator!.Subscribe(this, 0); _activator!.Subscribe(this, 0);
} }
else if (_animationTrigger != null) else if (_animationTrigger is not null)
{ {
_animationTrigger.OnNext(true); _animationTrigger.OnNext(true);
} }
@ -84,7 +85,7 @@ namespace Avalonia.Styling
public void Dispose() public void Dispose()
{ {
if (_setters is object) if (_setters is not null)
{ {
foreach (var setter in _setters) foreach (var setter in _setters)
{ {
@ -92,11 +93,11 @@ namespace Avalonia.Styling
} }
} }
if (_animations is object) if (_animations is not null)
{ {
foreach (var subscripion in _animations) foreach (var subscription in _animations)
{ {
subscripion.Dispose(); subscription.Dispose();
} }
} }
@ -111,7 +112,7 @@ namespace Avalonia.Styling
_animationTrigger?.OnNext(value); _animationTrigger?.OnNext(value);
if (_setters is object) if (_setters is not null)
{ {
if (IsActive) if (IsActive)
{ {

33
src/Avalonia.Controls/Calendar/CalendarItem.cs

@ -7,6 +7,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using Avalonia.Collections.Pooled;
using Avalonia.Controls.Metadata; using Avalonia.Controls.Metadata;
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Input; using Avalonia.Input;
@ -172,13 +173,13 @@ namespace Avalonia.Controls.Primitives
if (MonthView != null) if (MonthView != null)
{ {
var childCount = Calendar.RowsPerMonth + Calendar.RowsPerMonth * Calendar.ColumnsPerMonth; var childCount = Calendar.RowsPerMonth + Calendar.RowsPerMonth * Calendar.ColumnsPerMonth;
var children = new List<IControl>(childCount); using var children = new PooledList<IControl>(childCount);
for (int i = 0; i < Calendar.RowsPerMonth; i++) for (int i = 0; i < Calendar.RowsPerMonth; i++)
{ {
if (_dayTitleTemplate != null) if (_dayTitleTemplate != null)
{ {
var cell = _dayTitleTemplate.Build(); var cell = (Control) _dayTitleTemplate.Build();
cell.DataContext = string.Empty; cell.DataContext = string.Empty;
cell.SetValue(Grid.RowProperty, 0); cell.SetValue(Grid.RowProperty, 0);
cell.SetValue(Grid.ColumnProperty, i); cell.SetValue(Grid.ColumnProperty, i);
@ -186,11 +187,16 @@ namespace Avalonia.Controls.Primitives
} }
} }
EventHandler<PointerPressedEventArgs> cellMouseLeftButtonDown = Cell_MouseLeftButtonDown;
EventHandler<PointerReleasedEventArgs> cellMouseLeftButtonUp = Cell_MouseLeftButtonUp;
EventHandler<PointerEventArgs> cellMouseEnter = Cell_MouseEnter;
EventHandler<RoutedEventArgs> cellClick = Cell_Click;
for (int i = 1; i < Calendar.RowsPerMonth; i++) for (int i = 1; i < Calendar.RowsPerMonth; i++)
{ {
for (int j = 0; j < Calendar.ColumnsPerMonth; j++) for (int j = 0; j < Calendar.ColumnsPerMonth; j++)
{ {
CalendarDayButton cell = new CalendarDayButton(); var cell = new CalendarDayButton();
if (Owner != null) if (Owner != null)
{ {
@ -198,10 +204,10 @@ namespace Avalonia.Controls.Primitives
} }
cell.SetValue(Grid.RowProperty, i); cell.SetValue(Grid.RowProperty, i);
cell.SetValue(Grid.ColumnProperty, j); cell.SetValue(Grid.ColumnProperty, j);
cell.CalendarDayButtonMouseDown += Cell_MouseLeftButtonDown; cell.CalendarDayButtonMouseDown += cellMouseLeftButtonDown;
cell.CalendarDayButtonMouseUp += Cell_MouseLeftButtonUp; cell.CalendarDayButtonMouseUp += cellMouseLeftButtonUp;
cell.PointerEnter += Cell_MouseEnter; cell.PointerEnter += cellMouseEnter;
cell.Click += Cell_Click; cell.Click += cellClick;
children.Add(cell); children.Add(cell);
} }
} }
@ -214,12 +220,15 @@ namespace Avalonia.Controls.Primitives
var childCount = Calendar.RowsPerYear * Calendar.ColumnsPerYear; var childCount = Calendar.RowsPerYear * Calendar.ColumnsPerYear;
var children = new List<IControl>(childCount); var children = new List<IControl>(childCount);
CalendarButton month; EventHandler<PointerPressedEventArgs> monthCalendarButtonMouseDown = Month_CalendarButtonMouseDown;
EventHandler<PointerReleasedEventArgs> monthCalendarButtonMouseUp = Month_CalendarButtonMouseUp;
EventHandler<PointerEventArgs> monthMouseEnter = Month_MouseEnter;
for (int i = 0; i < Calendar.RowsPerYear; i++) for (int i = 0; i < Calendar.RowsPerYear; i++)
{ {
for (int j = 0; j < Calendar.ColumnsPerYear; j++) for (int j = 0; j < Calendar.ColumnsPerYear; j++)
{ {
month = new CalendarButton(); var month = new CalendarButton();
if (Owner != null) if (Owner != null)
{ {
@ -227,9 +236,9 @@ namespace Avalonia.Controls.Primitives
} }
month.SetValue(Grid.RowProperty, i); month.SetValue(Grid.RowProperty, i);
month.SetValue(Grid.ColumnProperty, j); month.SetValue(Grid.ColumnProperty, j);
month.CalendarLeftMouseButtonDown += Month_CalendarButtonMouseDown; month.CalendarLeftMouseButtonDown += monthCalendarButtonMouseDown;
month.CalendarLeftMouseButtonUp += Month_CalendarButtonMouseUp; month.CalendarLeftMouseButtonUp += monthCalendarButtonMouseUp;
month.PointerEnter += Month_MouseEnter; month.PointerEnter += monthMouseEnter;
children.Add(month); children.Add(month);
} }
} }

25
src/Avalonia.Controls/Presenters/TextPresenter.cs

@ -33,7 +33,7 @@ namespace Avalonia.Controls.Presenters
public static readonly StyledProperty<IBrush?> CaretBrushProperty = public static readonly StyledProperty<IBrush?> CaretBrushProperty =
AvaloniaProperty.Register<TextPresenter, IBrush?>(nameof(CaretBrush)); AvaloniaProperty.Register<TextPresenter, IBrush?>(nameof(CaretBrush));
public static readonly DirectProperty<TextPresenter, int> SelectionStartProperty = public static readonly DirectProperty<TextPresenter, int> SelectionStartProperty =
TextBox.SelectionStartProperty.AddOwner<TextPresenter>( TextBox.SelectionStartProperty.AddOwner<TextPresenter>(
o => o.SelectionStart, o => o.SelectionStart,
@ -43,7 +43,7 @@ namespace Avalonia.Controls.Presenters
TextBox.SelectionEndProperty.AddOwner<TextPresenter>( TextBox.SelectionEndProperty.AddOwner<TextPresenter>(
o => o.SelectionEnd, o => o.SelectionEnd,
(o, v) => o.SelectionEnd = v); (o, v) => o.SelectionEnd = v);
/// <summary> /// <summary>
/// Defines the <see cref="Text"/> property. /// Defines the <see cref="Text"/> property.
/// </summary> /// </summary>
@ -65,6 +65,12 @@ namespace Avalonia.Controls.Presenters
public static readonly StyledProperty<TextWrapping> TextWrappingProperty = public static readonly StyledProperty<TextWrapping> TextWrappingProperty =
TextBlock.TextWrappingProperty.AddOwner<TextPresenter>(); TextBlock.TextWrappingProperty.AddOwner<TextPresenter>();
/// <summary>
/// Defines the <see cref="LineHeight"/> property.
/// </summary>
public static readonly StyledProperty<double> LineHeightProperty =
TextBlock.LineHeightProperty.AddOwner<TextPresenter>();
/// <summary> /// <summary>
/// Defines the <see cref="Background"/> property. /// Defines the <see cref="Background"/> property.
/// </summary> /// </summary>
@ -179,6 +185,15 @@ namespace Avalonia.Controls.Presenters
get => GetValue(TextWrappingProperty); get => GetValue(TextWrappingProperty);
set => SetValue(TextWrappingProperty, value); set => SetValue(TextWrappingProperty, value);
} }
/// <summary>
/// Gets or sets the line height. By default, this is set to <see cref="double.NaN"/>, which determines the appropriate height automatically.
/// </summary>
public double LineHeight
{
get => GetValue(LineHeightProperty);
set => SetValue(LineHeightProperty, value);
}
/// <summary> /// <summary>
/// Gets or sets the text alignment. /// Gets or sets the text alignment.
@ -253,7 +268,7 @@ namespace Avalonia.Controls.Presenters
get => GetValue(CaretBrushProperty); get => GetValue(CaretBrushProperty);
set => SetValue(CaretBrushProperty, value); set => SetValue(CaretBrushProperty, value);
} }
public int SelectionStart public int SelectionStart
{ {
get get
@ -281,7 +296,7 @@ namespace Avalonia.Controls.Presenters
SetAndRaise(SelectionEndProperty, ref _selectionEnd, value); SetAndRaise(SelectionEndProperty, ref _selectionEnd, value);
} }
} }
protected override bool BypassFlowDirectionPolicies => true; protected override bool BypassFlowDirectionPolicies => true;
/// <summary> /// <summary>
@ -301,7 +316,7 @@ namespace Avalonia.Controls.Presenters
var textLayout = new TextLayout(text, typeface, FontSize, foreground, TextAlignment, var textLayout = new TextLayout(text, typeface, FontSize, foreground, TextAlignment,
TextWrapping, maxWidth: maxWidth, maxHeight: maxHeight, textStyleOverrides: textStyleOverrides, TextWrapping, maxWidth: maxWidth, maxHeight: maxHeight, textStyleOverrides: textStyleOverrides,
flowDirection: FlowDirection); flowDirection: FlowDirection, lineHeight: LineHeight);
return textLayout; return textLayout;
} }

19
src/Avalonia.Controls/TextBox.cs

@ -79,8 +79,8 @@ namespace Avalonia.Controls
AvaloniaProperty.Register<TextBox, int>(nameof(MaxLength), defaultValue: 0); AvaloniaProperty.Register<TextBox, int>(nameof(MaxLength), defaultValue: 0);
public static readonly StyledProperty<int> MaxLinesProperty = public static readonly StyledProperty<int> MaxLinesProperty =
AvaloniaProperty.Register<TextBox, int>(nameof(MaxLines), defaultValue: 0); AvaloniaProperty.Register<TextBox, int>(nameof(MaxLines), defaultValue: 0);
public static readonly DirectProperty<TextBox, string?> TextProperty = public static readonly DirectProperty<TextBox, string?> TextProperty =
TextBlock.TextProperty.AddOwnerWithDataValidation<TextBox>( TextBlock.TextProperty.AddOwnerWithDataValidation<TextBox>(
o => o.Text, o => o.Text,
@ -105,6 +105,12 @@ namespace Avalonia.Controls
public static readonly StyledProperty<TextWrapping> TextWrappingProperty = public static readonly StyledProperty<TextWrapping> TextWrappingProperty =
TextBlock.TextWrappingProperty.AddOwner<TextBox>(); TextBlock.TextWrappingProperty.AddOwner<TextBox>();
/// <summary>
/// Defines see <see cref="TextPresenter.LineHeight"/> property.
/// </summary>
public static readonly StyledProperty<double> LineHeightProperty =
TextBlock.LineHeightProperty.AddOwner<TextBox>();
public static readonly StyledProperty<string?> WatermarkProperty = public static readonly StyledProperty<string?> WatermarkProperty =
AvaloniaProperty.Register<TextBox, string?>(nameof(Watermark)); AvaloniaProperty.Register<TextBox, string?>(nameof(Watermark));
@ -358,6 +364,15 @@ namespace Avalonia.Controls
get { return GetValue(MaxLinesProperty); } get { return GetValue(MaxLinesProperty); }
set { SetValue(MaxLinesProperty, value); } set { SetValue(MaxLinesProperty, value); }
} }
/// <summary>
/// Gets or sets the line height.
/// </summary>
public double LineHeight
{
get { return GetValue(LineHeightProperty); }
set { SetValue(LineHeightProperty, value); }
}
[Content] [Content]
public string? Text public string? Text

3
src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlDetailsViewModel.cs

@ -60,7 +60,8 @@ namespace Avalonia.Diagnostics.ViewModels
var styleDiagnostics = styledElement.GetStyleDiagnostics(); var styleDiagnostics = styledElement.GetStyleDiagnostics();
foreach (var appliedStyle in styleDiagnostics.AppliedStyles) // We need to place styles without activator first, such styles will be overwritten by ones with activators.
foreach (var appliedStyle in styleDiagnostics.AppliedStyles.OrderBy(s => s.HasActivator))
{ {
var styleSource = appliedStyle.Source; var styleSource = appliedStyle.Source;

1
src/Avalonia.Themes.Default/Controls/TextBox.xaml

@ -76,6 +76,7 @@
SelectionEnd="{TemplateBinding SelectionEnd}" SelectionEnd="{TemplateBinding SelectionEnd}"
TextAlignment="{TemplateBinding TextAlignment}" TextAlignment="{TemplateBinding TextAlignment}"
TextWrapping="{TemplateBinding TextWrapping}" TextWrapping="{TemplateBinding TextWrapping}"
LineHeight="{TemplateBinding LineHeight}"
PasswordChar="{TemplateBinding PasswordChar}" PasswordChar="{TemplateBinding PasswordChar}"
RevealPassword="{TemplateBinding RevealPassword}" RevealPassword="{TemplateBinding RevealPassword}"
SelectionBrush="{TemplateBinding SelectionBrush}" SelectionBrush="{TemplateBinding SelectionBrush}"

1
src/Avalonia.Themes.Fluent/Controls/TextBox.xaml

@ -89,6 +89,7 @@
SelectionEnd="{TemplateBinding SelectionEnd}" SelectionEnd="{TemplateBinding SelectionEnd}"
TextAlignment="{TemplateBinding TextAlignment}" TextAlignment="{TemplateBinding TextAlignment}"
TextWrapping="{TemplateBinding TextWrapping}" TextWrapping="{TemplateBinding TextWrapping}"
LineHeight="{TemplateBinding LineHeight}"
PasswordChar="{TemplateBinding PasswordChar}" PasswordChar="{TemplateBinding PasswordChar}"
RevealPassword="{TemplateBinding RevealPassword}" RevealPassword="{TemplateBinding RevealPassword}"
SelectionBrush="{TemplateBinding SelectionBrush}" SelectionBrush="{TemplateBinding SelectionBrush}"

4
tests/Avalonia.Base.UnitTests/Input/PointerOverTests.cs

@ -247,10 +247,10 @@ namespace Avalonia.Base.UnitTests.Input
new[] new[]
{ {
((object?)decorator, "PointerEnter"), ((object?)decorator, "PointerEnter"),
(decorator, "PointerMove"), (decorator, "PointerMoved"),
(decorator, "PointerLeave"), (decorator, "PointerLeave"),
(canvas, "PointerEnter"), (canvas, "PointerEnter"),
(canvas, "PointerMove") (canvas, "PointerMoved")
}, },
result); result);
} }

11
tests/Avalonia.Base.UnitTests/Styling/SetterTests.cs

@ -91,16 +91,13 @@ namespace Avalonia.Base.UnitTests.Styling
[Fact] [Fact]
public void Setter_Should_Apply_Value_Without_Activator_With_Style_Priority() public void Setter_Should_Apply_Value_Without_Activator_With_Style_Priority()
{ {
var control = new Mock<IStyleable>(); var control = new Control();
var style = Mock.Of<Style>();
var setter = new Setter(TextBlock.TagProperty, "foo"); var setter = new Setter(TextBlock.TagProperty, "foo");
setter.Instance(control.Object).Start(false); setter.Instance(control).Start(false);
control.Verify(x => x.SetValue( Assert.Equal("foo", control.Tag);
TextBlock.TagProperty, Assert.Equal(BindingPriority.Style, control.GetDiagnostic(TextBlock.TagProperty).Priority);
"foo",
BindingPriority.Style));
} }
[Fact] [Fact]

2
tests/Avalonia.Controls.UnitTests/CalendarTests.cs

@ -15,7 +15,7 @@ namespace Avalonia.Controls.UnitTests
first.Day == second.Day; first.Day == second.Day;
} }
[Fact(Skip ="FIX ME ASAP")] [Fact]
public void SelectedDatesChanged_Should_Fire_When_SelectedDate_Set() public void SelectedDatesChanged_Should_Fire_When_SelectedDate_Set()
{ {
bool handled = false; bool handled = false;

Loading…
Cancel
Save