Browse Source

Merge branch 'master' into fix-scrollbar-default-visibility

pull/5102/head
Steven Kirk 6 years ago
committed by GitHub
parent
commit
3d0a2a3764
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      Documentation/build.md
  2. 2
      src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs
  3. 11
      src/Avalonia.Controls/Slider.cs
  4. 2
      src/Avalonia.Input/NavigationDirection.cs
  5. 3
      src/Avalonia.Styling/ApiCompatBaseline.txt
  6. 13
      src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs
  7. 15
      src/Avalonia.Themes.Default/PathIcon.xaml
  8. 15
      src/Avalonia.Themes.Fluent/PathIcon.xaml
  9. 18
      src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs
  10. 17
      tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/DynamicResourceExtensionTests.cs

11
Documentation/build.md

@ -60,15 +60,10 @@ git submodule update --init --recursive
### Build native libraries (macOS only)
On macOS it is necessary to build and manually install the respective native libraries using [Xcode](https://developer.apple.com/xcode/). The steps to get this working correctly are:
- (for revisions after 2 Nov 2020) Run `./build.sh GenerateCppHeaders` to generate `avalonia-native.h` from `avn.idl`
- Navigate to the Avalonia/native/Avalonia.Native/src/OSX folder and open the `Avalonia.Native.OSX.xcodeproj` project
- Build the library via the Product->Build menu. This will generate binaries in your local path under ~/Library/Developer/Xcode/DerivedData/Avalonia.Native.OSX-*guid* where "guid" is uniquely generated every time you build.
- Manually install the native library by copying it from the build artifacts folder into the shared dynamic library path:
On macOS it is necessary to build and manually install the respective native libraries using [Xcode](https://developer.apple.com/xcode/). Execute the build script in the root project with the `CompileNative` task. It will build the headers, build the libraries, and place them in the appropriate place to allow .NET to find them at compilation and run time.
```
cd ~/Library/Developer/Xcode/DerivedData/Avalonia.Native.OSX-[guid]/Build/Products/Debug
cp libAvalonia.Native.OSX.dylib /usr/local/lib/libAvaloniaNative.dylib
```bash
./build.sh CompileNative
```
### Build and Run Avalonia

2
src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs

@ -231,7 +231,7 @@ namespace Avalonia.Controls.Platform
{
var direction = e.Key.ToNavigationDirection();
if (direction.HasValue)
if (direction?.IsDirectional() == true)
{
if (item == null && _isContextMenu)
{

11
src/Avalonia.Controls/Slider.cs

@ -3,6 +3,7 @@ using Avalonia.Collections;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Mixins;
using Avalonia.Controls.Primitives;
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Layout;
@ -94,6 +95,8 @@ namespace Avalonia.Controls
Thumb.DragStartedEvent.AddClassHandler<Slider>((x, e) => x.OnThumbDragStarted(e), RoutingStrategies.Bubble);
Thumb.DragCompletedEvent.AddClassHandler<Slider>((x, e) => x.OnThumbDragCompleted(e),
RoutingStrategies.Bubble);
ValueProperty.OverrideMetadata<Slider>(new DirectPropertyMetadata<double>(enableDataValidation: true));
}
/// <summary>
@ -225,6 +228,14 @@ namespace Avalonia.Controls
Value = IsSnapToTickEnabled ? SnapToTick(finalValue) : finalValue;
}
protected override void UpdateDataValidation<T>(AvaloniaProperty<T> property, BindingValue<T> value)
{
if (property == ValueProperty)
{
DataValidationErrors.SetError(this, value.Error);
}
}
protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{
base.OnPropertyChanged(change);

2
src/Avalonia.Input/NavigationDirection.cs

@ -83,7 +83,7 @@ namespace Avalonia.Input
/// </returns>
public static bool IsDirectional(this NavigationDirection direction)
{
return direction > NavigationDirection.Previous ||
return direction > NavigationDirection.Previous &&
direction <= NavigationDirection.PageDown;
}

3
src/Avalonia.Styling/ApiCompatBaseline.txt

@ -0,0 +1,3 @@
Compat issues with assembly Avalonia.Styling:
MembersMustExist : Member 'public System.IObservable<System.Object> Avalonia.Controls.ResourceNodeExtensions.GetResourceObservable(Avalonia.IStyledElement, System.Object, System.Func<System.Object, System.Object>)' does not exist in the implementation but it does exist in the contract.
Total Issues: 1

13
src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs

@ -60,7 +60,7 @@ namespace Avalonia.Controls
}
public static IObservable<object?> GetResourceObservable(
this IStyledElement control,
this IResourceHost control,
object key,
Func<object?, object?>? converter = null)
{
@ -83,11 +83,11 @@ namespace Avalonia.Controls
private class ResourceObservable : LightweightObservableBase<object?>
{
private readonly IStyledElement _target;
private readonly IResourceHost _target;
private readonly object _key;
private readonly Func<object?, object?>? _converter;
public ResourceObservable(IStyledElement target, object key, Func<object?, object?>? converter)
public ResourceObservable(IResourceHost target, object key, Func<object?, object?>? converter)
{
_target = target;
_key = key;
@ -147,13 +147,16 @@ namespace Avalonia.Controls
{
if (_target.Owner is object)
{
observer.OnNext(Convert(_target.Owner?.FindResource(_key)));
observer.OnNext(Convert(_target.Owner.FindResource(_key)));
}
}
private void PublishNext()
{
PublishNext(Convert(_target.Owner?.FindResource(_key)));
if (_target.Owner is object)
{
PublishNext(Convert(_target.Owner.FindResource(_key)));
}
}
private void OwnerChanged(object sender, EventArgs e)

15
src/Avalonia.Themes.Default/PathIcon.xaml

@ -2,16 +2,19 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style Selector="PathIcon">
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundColor}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Height" Value="{DynamicResource IconElementThemeHeight}" />
<Setter Property="Width" Value="{DynamicResource IconElementThemeWidth}" />
<Setter Property="Template">
<ControlTemplate>
<Viewbox Height="{TemplateBinding Height}"
Width="{TemplateBinding Width}">
<Path Fill="{TemplateBinding Foreground}"
Data="{TemplateBinding Data}"
Stretch="Uniform" />
</Viewbox>
<Border Background="{TemplateBinding Background}">
<Viewbox Height="{TemplateBinding Height}"
Width="{TemplateBinding Width}">
<Path Fill="{TemplateBinding Foreground}"
Data="{TemplateBinding Data}"
Stretch="Uniform" />
</Viewbox>
</Border>
</ControlTemplate>
</Setter>
</Style>

15
src/Avalonia.Themes.Fluent/PathIcon.xaml

@ -10,16 +10,19 @@
</Design.PreviewWith>
<Style Selector="PathIcon">
<Setter Property="Foreground" Value="{DynamicResource TextControlForeground}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Height" Value="{DynamicResource IconElementThemeHeight}" />
<Setter Property="Width" Value="{DynamicResource IconElementThemeWidth}" />
<Setter Property="Template">
<ControlTemplate>
<Viewbox Height="{TemplateBinding Height}"
Width="{TemplateBinding Width}">
<Path Fill="{TemplateBinding Foreground}"
Data="{TemplateBinding Data}"
Stretch="Uniform" />
</Viewbox>
<Border Background="{TemplateBinding Background}">
<Viewbox Height="{TemplateBinding Height}"
Width="{TemplateBinding Width}">
<Path Fill="{TemplateBinding Foreground}"
Data="{TemplateBinding Data}"
Stretch="Uniform" />
</Viewbox>
</Border>
</ControlTemplate>
</Setter>
</Style>

18
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs

@ -10,8 +10,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
{
public class DynamicResourceExtension : IBinding
{
private IStyledElement? _anchor;
private IResourceProvider? _resourceProvider;
private object? _anchor;
public DynamicResourceExtension()
{
@ -30,12 +29,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
if (!(provideTarget.TargetObject is IStyledElement))
{
_anchor = serviceProvider.GetFirstParent<IStyledElement>();
if (_anchor is null)
{
_resourceProvider = serviceProvider.GetFirstParent<IResourceProvider>();
}
_anchor = serviceProvider.GetFirstParent<IStyledElement>() ??
serviceProvider.GetFirstParent<IResourceProvider>() ??
(object?)serviceProvider.GetFirstParent<IResourceHost>();
}
return this;
@ -52,16 +48,16 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
return null;
}
var control = target as IStyledElement ?? _anchor as IStyledElement;
var control = target as IResourceHost ?? _anchor as IResourceHost;
if (control != null)
{
var source = control.GetResourceObservable(ResourceKey, GetConverter(targetProperty));
return InstancedBinding.OneWay(source);
}
else if (_resourceProvider is object)
else if (_anchor is IResourceProvider resourceProvider)
{
var source = _resourceProvider.GetResourceObservable(ResourceKey, GetConverter(targetProperty));
var source = resourceProvider.GetResourceObservable(ResourceKey, GetConverter(targetProperty));
return InstancedBinding.OneWay(source);
}

17
tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/DynamicResourceExtensionTests.cs

@ -345,6 +345,23 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
Assert.Equal(0xff506070, brush.Color.ToUint32());
}
[Fact]
public void DynamicResource_Can_Be_Assigned_To_Resource_Property_In_Application()
{
var xaml = @"
<Application xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Application.Resources>
<Color x:Key='color'>#ff506070</Color>
<SolidColorBrush x:Key='brush' Color='{DynamicResource color}'/>
</Application.Resources>
</Application>";
var application = (Application)AvaloniaRuntimeXamlLoader.Load(xaml);
var brush = (SolidColorBrush)application.Resources["brush"];
Assert.Equal(0xff506070, brush.Color.ToUint32());
}
[Fact]
public void DynamicResource_Can_Be_Assigned_To_ItemTemplate_Property()

Loading…
Cancel
Save