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

Initial implementation of TextBlock.Inlines #1689

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Avalonia.sln
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Designer.HostApp.NetFX", "src\tools\Avalonia.Designer.HostApp.NetFX\Avalonia.Designer.HostApp.NetFX.csproj", "{4ADA61C8-D191-428D-9066-EF4F0D86520F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Skia.UnitTests", "tests\Avalonia.Skia.UnitTests\Avalonia.Skia.UnitTests.csproj", "{E1240B49-7B4B-4371-A00E-068778C5CF0B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Documents", "src\Avalonia.Documents\Avalonia.Documents.csproj", "{2A17D38C-F012-495D-9595-8FC8D01B4D81}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Expand Down Expand Up @@ -2514,6 +2515,46 @@ Global
{E1240B49-7B4B-4371-A00E-068778C5CF0B}.Release|NetCoreOnly.Build.0 = Release|Any CPU
{E1240B49-7B4B-4371-A00E-068778C5CF0B}.Release|x86.ActiveCfg = Release|Any CPU
{E1240B49-7B4B-4371-A00E-068778C5CF0B}.Release|x86.Build.0 = Release|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Ad-Hoc|NetCoreOnly.ActiveCfg = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Ad-Hoc|NetCoreOnly.Build.0 = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.AppStore|iPhone.Build.0 = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.AppStore|NetCoreOnly.ActiveCfg = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.AppStore|NetCoreOnly.Build.0 = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.AppStore|x86.ActiveCfg = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.AppStore|x86.Build.0 = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Debug|iPhone.Build.0 = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Debug|NetCoreOnly.ActiveCfg = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Debug|NetCoreOnly.Build.0 = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Debug|x86.ActiveCfg = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Debug|x86.Build.0 = Debug|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Release|Any CPU.Build.0 = Release|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Release|iPhone.ActiveCfg = Release|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Release|iPhone.Build.0 = Release|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Release|NetCoreOnly.ActiveCfg = Release|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Release|NetCoreOnly.Build.0 = Release|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Release|x86.ActiveCfg = Release|Any CPU
{2A17D38C-F012-495D-9595-8FC8D01B4D81}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
7 changes: 7 additions & 0 deletions samples/ControlCatalog/ControlCatalog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<EmbeddedResource Include="Assets\Fonts\SourceSansPro-BoldItalic.ttf" />
<EmbeddedResource Include="Assets\Fonts\SourceSansPro-Italic.ttf" />
<EmbeddedResource Include="Assets\Fonts\SourceSansPro-Regular.ttf" />
<None Remove="Pages\TextBlockPage.xaml" />
</ItemGroup>

<ItemGroup>
Expand All @@ -33,6 +34,12 @@
<ProjectReference Include="..\..\src\Avalonia.Styling\Avalonia.Styling.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Themes.Default\Avalonia.Themes.Default.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Pages\TextBlockPage.xaml.cs">
<DependentUpon>TextBlockPage.xaml</DependentUpon>
</Compile>
</ItemGroup>

<Import Project="..\..\build\Serilog.props" />
</Project>
1 change: 1 addition & 0 deletions samples/ControlCatalog/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<TabItem Header="ProgressBar"><pages:ProgressBarPage/></TabItem>
<TabItem Header="RadioButton"><pages:RadioButtonPage/></TabItem>
<TabItem Header="Slider"><pages:SliderPage/></TabItem>
<TabItem Header="TextBlock"><pages:TextBlockPage/></TabItem>
<TabItem Header="TextBox"><pages:TextBoxPage/></TabItem>
<TabItem Header="ToolTip"><pages:ToolTipPage/></TabItem>
<TabItem Header="TreeView"><pages:TreeViewPage/></TabItem>
Expand Down
35 changes: 35 additions & 0 deletions samples/ControlCatalog/Pages/TextBlockPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<UserControl xmlns="https://github.com/avaloniaui">
<UserControl.Styles>
<Style Selector="Run.code">
<Setter Property="FontFamily" Value="Courier New"/>
</Style>
</UserControl.Styles>

<StackPanel Orientation="Vertical" Gap="4">
<TextBlock Classes="h1">TextBlock</TextBlock>
<TextBlock Classes="h2">A control that displays a block of text</TextBlock>

<StackPanel Orientation="Horizontal"
Margin="0,16,0,0"
HorizontalAlignment="Center"
Gap="16">
<StackPanel Orientation="Vertical" Gap="8">
<TextBlock>A simple TextBlock with unformatted text.</TextBlock>
<TextBlock>
A <Run Classes="code">TextBlock</Run> with <Run FontWeight="Bold">differing</Run>
<Run FontStyle="Italic">styles</Run> <Run FontSize="24">and fonts</Run>.
</TextBlock>
<TextBlock>
A <Run Classes="code" Foreground="Gray">TextBlock</Run> with <Run Foreground="Red">differing</Run>
<Run Foreground="Green">colors</Run>.
</TextBlock>
<TextBlock>
A <Run Classes="code">TextBlock</Run> with <Run Foreground="Orange" FontStyle="Italic" Text="{Binding}"/>.
</TextBlock>
<TextBlock>
A <Run Classes="code">TextBlock</Run> with a <LineBreak/> line break.
</TextBlock>
</StackPanel>
</StackPanel>
</StackPanel>
</UserControl>
19 changes: 19 additions & 0 deletions samples/ControlCatalog/Pages/TextBlockPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace ControlCatalog.Pages
{
public class TextBlockPage : UserControl
{
public TextBlockPage()
{
this.InitializeComponent();
DataContext = "a databound run";
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}
15 changes: 15 additions & 0 deletions src/Avalonia.Base/Metadata/ContentWrapperAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace Avalonia.Metadata
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public sealed class ContentWrapperAttribute : Attribute
{
public ContentWrapperAttribute(Type contentWrapper)
{
ContentWrapper = contentWrapper;
}

public Type ContentWrapper { get; private set; }
}
}
12 changes: 12 additions & 0 deletions src/Avalonia.Base/Metadata/TrimSurroundingWhitespaceAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.

using System;

namespace Avalonia.Metadata
{
[AttributeUsage(AttributeTargets.Class)]
public class TrimSurroundingWhitespaceAttribute : Attribute
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.

using System;

namespace Avalonia.Metadata
{
[AttributeUsage(AttributeTargets.Class)]
public class WhitespaceSignificantCollectionAttribute : Attribute
{
}
}
1 change: 1 addition & 0 deletions src/Avalonia.Controls/Avalonia.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<ItemGroup>
<ProjectReference Include="..\Avalonia.Animation\Avalonia.Animation.csproj" />
<ProjectReference Include="..\Avalonia.Base\Avalonia.Base.csproj" />
<ProjectReference Include="..\Avalonia.Documents\Avalonia.Documents.csproj" />
<ProjectReference Include="..\Avalonia.Input\Avalonia.Input.csproj" />
<ProjectReference Include="..\Avalonia.Interactivity\Avalonia.Interactivity.csproj" />
<ProjectReference Include="..\Avalonia.Layout\Avalonia.Layout.csproj" />
Expand Down
6 changes: 3 additions & 3 deletions src/Avalonia.Controls/Presenters/TextPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,17 @@ internal void CaretIndexChanged(int caretIndex)
/// <param name="constraint">The constraint of the text.</param>
/// <param name="text">The text to generated the <see cref="FormattedText"/> for.</param>
/// <returns>A <see cref="FormattedText"/> object.</returns>
protected override FormattedText CreateFormattedText(Size constraint, string text)
protected override FormattedText CreateFormattedText(Size constraint)
{
FormattedText result = null;

if (PasswordChar != default(char))
{
result = base.CreateFormattedText(constraint, new string(PasswordChar, text?.Length ?? 0));
result = base.CreateFormattedText(constraint, new string(PasswordChar, Text?.Length ?? 0));
}
else
{
result = base.CreateFormattedText(constraint, text);
result = base.CreateFormattedText(constraint);
}

var selectionStart = SelectionStart;
Expand Down
9 changes: 7 additions & 2 deletions src/Avalonia.Controls/Primitives/AccessText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public override void Render(DrawingContext context)
}

/// <inheritdoc/>
protected override FormattedText CreateFormattedText(Size constraint, string text)
protected override FormattedText CreateFormattedText(Size constraint)
{
return base.CreateFormattedText(constraint, StripAccessKey(text));
return base.CreateFormattedText(constraint, StripAccessKey(Text));
}

/// <summary>
Expand Down Expand Up @@ -126,6 +126,11 @@ protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e
/// <returns>The text with the first underscore stripped.</returns>
private string StripAccessKey(string text)
{
if (text == null)
{
return string.Empty;
}

var position = text.IndexOf('_');

if (position == -1)
Expand Down
9 changes: 5 additions & 4 deletions src/Avalonia.Controls/Primitives/TemplatedControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using Avalonia.Controls.Templates;
using Avalonia.Documents;
using Avalonia.Interactivity;
using Avalonia.Logging;
using Avalonia.LogicalTree;
Expand Down Expand Up @@ -45,25 +46,25 @@ public class TemplatedControl : Control, ITemplatedControl
/// Defines the <see cref="FontSize"/> property.
/// </summary>
public static readonly StyledProperty<double> FontSizeProperty =
TextBlock.FontSizeProperty.AddOwner<TemplatedControl>();
TextElement.FontSizeProperty.AddOwner<TemplatedControl>();

/// <summary>
/// Defines the <see cref="FontStyle"/> property.
/// </summary>
public static readonly StyledProperty<FontStyle> FontStyleProperty =
TextBlock.FontStyleProperty.AddOwner<TemplatedControl>();
TextElement.FontStyleProperty.AddOwner<TemplatedControl>();

/// <summary>
/// Defines the <see cref="FontWeight"/> property.
/// </summary>
public static readonly StyledProperty<FontWeight> FontWeightProperty =
TextBlock.FontWeightProperty.AddOwner<TemplatedControl>();
TextElement.FontWeightProperty.AddOwner<TemplatedControl>();

/// <summary>
/// Defines the <see cref="Foreground"/> property.
/// </summary>
public static readonly StyledProperty<IBrush> ForegroundProperty =
TextBlock.ForegroundProperty.AddOwner<TemplatedControl>();
TextElement.ForegroundProperty.AddOwner<TemplatedControl>();

/// <summary>
/// Defines the <see cref="Padding"/> property.
Expand Down
Loading