Browse Source

Introduce ConfigureFonts AppBuilder action

Introduce WithInterFont extension method
pull/10455/head
Benedikt Stebner 4 years ago
parent
commit
c55747f328
  1. 2
      samples/ControlCatalog.NetCore/Program.cs
  2. 16
      src/Avalonia.Controls/AppBuilder.cs
  3. 13
      src/Avalonia.Fonts.Inter/AppBuilderExtension.cs
  4. 1
      src/Avalonia.Fonts.Inter/Avalonia.Fonts.Inter.csproj

2
samples/ControlCatalog.NetCore/Program.cs

@ -125,7 +125,7 @@ namespace ControlCatalog.NetCore
EnableIme = true
})
.UseSkia()
.WithFonts(new InterFontCollection())
.WithInterFont()
.AfterSetup(builder =>
{
builder.Instance!.AttachDevTools(new Avalonia.Diagnostics.DevToolsOptions()

16
src/Avalonia.Controls/AppBuilder.cs

@ -208,23 +208,15 @@ namespace Avalonia
}
/// <summary>
/// Registers a custom font collection with the font manager.
/// Registers an action that is executed with the current font manager.
/// </summary>
/// <param name="fontCollection">The font collection.</param>
/// <param name="action">The action.</param>
/// <returns>An <see cref="AppBuilder"/> instance.</returns>
/// <exception cref="ArgumentNullException"></exception>
public AppBuilder WithFonts(IFontCollection fontCollection)
public AppBuilder ConfigureFonts(Action<FontManager> action)
{
if(fontCollection == null)
{
throw new ArgumentNullException(nameof(fontCollection), "Font collection can't be null.");
}
return AfterSetup(appBuilder =>
{
var fontManager = FontManager.Current;
fontManager.AddFontCollection(fontCollection);
action?.Invoke(FontManager.Current);
});
}

13
src/Avalonia.Fonts.Inter/AppBuilderExtension.cs

@ -0,0 +1,13 @@
namespace Avalonia.Fonts.Inter
{
public static class AppBuilderExtension
{
public static AppBuilder WithInterFont(this AppBuilder appBuilder)
{
return appBuilder.ConfigureFonts(fontManager =>
{
fontManager.AddFontCollection(new InterFontCollection());
});
}
}
}

1
src/Avalonia.Fonts.Inter/Avalonia.Fonts.Inter.csproj

@ -8,6 +8,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Avalonia.Base\Avalonia.Base.csproj" />
<ProjectReference Include="..\Avalonia.Controls\Avalonia.Controls.csproj" />
</ItemGroup>
<Import Project="..\..\build\BuildTargets.targets" />
</Project>

Loading…
Cancel
Save