Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting TextBlock, Inlines, Flow Layout from WPF #5461

Closed
wants to merge 11 commits into from
54 changes: 54 additions & 0 deletions Avalonia.sln
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.FreeDesktop", "src
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Controls.DataGrid.UnitTests", "tests\Avalonia.Controls.DataGrid.UnitTests\Avalonia.Controls.DataGrid.UnitTests.csproj", "{351337F5-D66F-461B-A957-4EF60BDB4BA6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Documents", "src\Avalonia.Documents\Avalonia.Documents.csproj", "{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Documents.UnitTests", "tests\Avalonia.Documents.UnitTests\Avalonia.Documents.UnitTests.csproj", "{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeEmbedSample", "samples\interop\NativeEmbedSample\NativeEmbedSample.csproj", "{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Themes.Fluent", "src\Avalonia.Themes.Fluent\Avalonia.Themes.Fluent.csproj", "{C42D2FC1-A531-4ED4-84B9-89AEC7C962FC}"
Expand All @@ -236,6 +239,8 @@ Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Shared\RenderHelpers\RenderHelpers.projitems*{3c4c0cb4-0c0f-4450-a37b-148c84ff905f}*SharedItemsImports = 13
src\Shared\RenderHelpers\RenderHelpers.projitems*{3e908f67-5543-4879-a1dc-08eace79b3cd}*SharedItemsImports = 5
src\Shared\PlatformSupport\PlatformSupport.projitems*{4488ad85-1495-4809-9aa4-ddfe0a48527e}*SharedItemsImports = 4
src\Shared\PlatformSupport\PlatformSupport.projitems*{7b92af71-6287-4693-9dcb-bd5b6e927e23}*SharedItemsImports = 4
src\Shared\PlatformSupport\PlatformSupport.projitems*{7b92af71-6287-4693-9dcb-bd5b6e927e23}*SharedItemsImports = 5
src\Shared\RenderHelpers\RenderHelpers.projitems*{7d2d3083-71dd-4cc9-8907-39a0d86fb322}*SharedItemsImports = 5
src\Shared\PlatformSupport\PlatformSupport.projitems*{88060192-33d5-4932-b0f9-8bd2763e857d}*SharedItemsImports = 5
Expand Down Expand Up @@ -1902,6 +1907,54 @@ Global
{351337F5-D66F-461B-A957-4EF60BDB4BA6}.Release|iPhone.Build.0 = Release|Any CPU
{351337F5-D66F-461B-A957-4EF60BDB4BA6}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{351337F5-D66F-461B-A957-4EF60BDB4BA6}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.AppStore|iPhone.Build.0 = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Debug|iPhone.Build.0 = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Release|Any CPU.Build.0 = Release|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Release|iPhone.ActiveCfg = Release|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Release|iPhone.Build.0 = Release|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{1F01FC28-7EDA-43C3-B8A5-3BD9858B2CF7}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.AppStore|iPhone.Build.0 = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Debug|iPhone.Build.0 = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Release|Any CPU.Build.0 = Release|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Release|iPhone.ActiveCfg = Release|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Release|iPhone.Build.0 = Release|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -2198,6 +2251,7 @@ Global
{D775DECB-4E00-4ED5-A75A-5FCE58ADFF0B} = {9B9E3891-2366-4253-A952-D08BCEB71098}
{AF915D5C-AB00-4EA0-B5E6-001F4AE84E68} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B}
{351337F5-D66F-461B-A957-4EF60BDB4BA6} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B}
{F0589BDA-BFBC-4BDE-9E79-EFE101EED592} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B}
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3} = {A0CC0258-D18C-4AB3-854F-7101680FC3F9}
{909A8CBD-7D0E-42FD-B841-022AD8925820} = {8B6A8209-894F-4BA1-B880-965FD453982C}
{11BE52AF-E2DD-4CF0-B19A-05285ACAF571} = {9B9E3891-2366-4253-A952-D08BCEB71098}
Expand Down
1 change: 1 addition & 0 deletions samples/ControlCatalog/ControlCatalog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<ItemGroup>
<ProjectReference Include="..\..\packages\Avalonia\Avalonia.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Documents\Avalonia.Documents.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Controls.DataGrid\Avalonia.Controls.DataGrid.csproj" />
<ProjectReference Include="..\MiniMvvm\MiniMvvm.csproj" />
</ItemGroup>
Expand Down
21 changes: 21 additions & 0 deletions samples/ControlCatalog/Pages/TextBlockPage.xaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:internal="clr-namespace:Avalonia.Documents.Internal;assembly=Avalonia.Documents"
xmlns:documents="clr-namespace:System.Windows.Documents;assembly=Avalonia.Documents"
x:Class="ControlCatalog.Pages.TextBlockPage">
<StackPanel>
<TextBlock Classes="h1">TextBlock</TextBlock>
Expand All @@ -16,6 +18,25 @@
<Setter Property="Padding" Value="2"/>
</Style>
</StackPanel.Styles>
<Border>
<internal:NewTextBlock Width="200">
<documents:Span Foreground="Red">Red</documents:Span>
<documents:Span Foreground="Green">Green</documents:Span>
<documents:Span Foreground="Blue">Blue</documents:Span>

<documents:Span FontWeight="Normal" FontStyle="Normal"
FontFamily="avares://ControlCatalog/Assets/Fonts#Source Sans Pro">
Custom font regular
<documents:Span FontWeight="Bold">Custom font bold</documents:Span>
<documents:Span FontStyle="Italic">
Custom font italic
<documents:Span FontWeight="Bold">
Custom font bold italic
</documents:Span>
</documents:Span>
</documents:Span>
</internal:NewTextBlock>
</Border>
<Border>
<StackPanel Width="200" Spacing="8">
<TextBlock Margin="0 0 10 0" TextTrimming="CharacterEllipsis" Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit."/>
Expand Down
4 changes: 4 additions & 0 deletions src/Avalonia.Base/ApiCompatBaseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Compat issues with assembly Avalonia.Base:
InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.LocalValueEnumerator Avalonia.IAvaloniaObject.GetLocalValueEnumerator()' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.Object Avalonia.IAvaloniaObject.ReadLocalValue(Avalonia.AvaloniaProperty)' is present in the implementation but not in the contract.
Total Issues: 2
10 changes: 10 additions & 0 deletions src/Avalonia.Base/AvaloniaObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,16 @@ private void LogPropertySet<T>(AvaloniaProperty<T> property, T value, BindingPri
priority);
}

public object ReadLocalValue(AvaloniaProperty property)
{
throw new NotImplementedException();
}

public LocalValueEnumerator GetLocalValueEnumerator()
{
throw new NotImplementedException();
}

private class DirectBindingSubscription<T> : IObserver<BindingValue<T>>, IDisposable
{
private readonly AvaloniaObject _owner;
Expand Down
4 changes: 4 additions & 0 deletions src/Avalonia.Base/IAvaloniaObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,9 @@ void InheritedPropertyChanged<T>(
AvaloniaProperty<T> property,
Optional<T> oldValue,
Optional<T> newValue);

object ReadLocalValue(AvaloniaProperty property);

LocalValueEnumerator GetLocalValueEnumerator();
}
}
209 changes: 209 additions & 0 deletions src/Avalonia.Base/LocalValueEnumerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections;
//using System.Diagnostics;
//using MS.Internal.WindowsBase;

#pragma warning disable 1634, 1691 // suppressing PreSharp warnings

namespace Avalonia
{
/// <summary>
/// Local value enumeration object
/// </summary>
/// <remarks>
/// Modifying local values (via SetValue or ClearValue) during enumeration
/// is unsupported
/// </remarks>
public struct LocalValueEnumerator : IEnumerator
{
/// <summary>
/// Overrides Object.GetHashCode
/// </summary>
/// <returns>An integer that represents the hashcode for this object</returns>
public override int GetHashCode()
{
return base.GetHashCode();
}

/// <summary>
/// Determine equality
/// </summary>
public override bool Equals(object obj)
{
if(obj is LocalValueEnumerator)
{
LocalValueEnumerator other = (LocalValueEnumerator) obj;

return (_count == other._count &&
_index == other._index &&
_snapshot == other._snapshot);
}
else
{
// being compared against something that isn't a LocalValueEnumerator.
return false;
}
}

/// <summary>
/// Determine equality
/// </summary>
public static bool operator ==(LocalValueEnumerator obj1, LocalValueEnumerator obj2)
{
return obj1.Equals(obj2);
}

/// <summary>
/// Determine inequality
/// </summary>
public static bool operator !=(LocalValueEnumerator obj1, LocalValueEnumerator obj2)
{
return !(obj1 == obj2);
}

/// <summary>
/// Get current entry
/// </summary>
public LocalValueEntry Current
{
get
{
if(_index == -1 )
{
#pragma warning suppress 6503 // IEnumerator.Current is documented to throw this exception
throw new InvalidOperationException(/*SR.Get(SRID.LocalValueEnumerationReset)*/);
}

if(_index >= Count )
{
#pragma warning suppress 6503 // IEnumerator.Current is documented to throw this exception
throw new InvalidOperationException(/*SR.Get(SRID.LocalValueEnumerationOutOfBounds)*/);
}

return _snapshot[_index];
}
}

/// <summary>
/// Get current entry (object reference based)
/// </summary>
object IEnumerator.Current
{
get { return Current; }
}

/// <summary>
/// Move to the next item in the enumerator
/// </summary>
/// <returns>Success of the method</returns>
public bool MoveNext()
{
_index++;

return _index < Count;
}

/// <summary>
/// Reset enumeration
/// </summary>
public void Reset()
{
_index = -1;
}

/// <summary>
/// Return number of items represented in the collection
/// </summary>
public int Count
{
get { return _count; }
}

internal LocalValueEnumerator(LocalValueEntry[] snapshot, int count)
{
_index = -1;
_count = count;
_snapshot = snapshot;
}

private int _index;
private LocalValueEntry[] _snapshot;
private int _count;
}


/// <summary>
/// Represents a Property-Value pair for local value enumeration
/// </summary>
public struct LocalValueEntry
{
/// <summary>
/// Overrides Object.GetHashCode
/// </summary>
/// <returns>An integer that represents the hashcode for this object</returns>
public override int GetHashCode()
{
return base.GetHashCode();
}

/// <summary>
/// Determine equality
/// </summary>
public override bool Equals(object obj)
{
LocalValueEntry other = (LocalValueEntry) obj;

return (_dp == other._dp &&
_value == other._value);
}

/// <summary>
/// Determine equality
/// </summary>
public static bool operator ==(LocalValueEntry obj1, LocalValueEntry obj2)
{
return obj1.Equals(obj2);
}

/// <summary>
/// Determine inequality
/// </summary>
public static bool operator !=(LocalValueEntry obj1, LocalValueEntry obj2)
{
return !(obj1 == obj2);
}

/// <summary>
/// Dependency property
/// </summary>
public AvaloniaProperty Property
{
get { return _dp; }
}

/// <summary>
/// Value of the property
/// </summary>
public object Value
{
get { return _value; }
}

internal LocalValueEntry(AvaloniaProperty dp, object value)
{
_dp = dp;
_value = value;
}

// Internal here because we need to change these around when building
// the snapshot for the LocalValueEnumerator, and we can't make internal
// setters when we have public getters.
internal AvaloniaProperty _dp;
internal object _value;
}
}

Loading