283 changed files with 4255 additions and 6440 deletions
@ -0,0 +1,5 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<PropertyGroup> |
|||
<EnableNETAnalyzers>true</EnableNETAnalyzers> |
|||
</PropertyGroup> |
|||
</Project> |
|||
@ -0,0 +1,17 @@ |
|||
using Avalonia; |
|||
using Avalonia.Web.Blazor; |
|||
|
|||
namespace ControlCatalog.Blazor.Web; |
|||
|
|||
public partial class App |
|||
{ |
|||
protected override void OnParametersSet() |
|||
{ |
|||
AppBuilder.Configure<ControlCatalog.App>() |
|||
.UseBlazor() |
|||
// .With(new SkiaOptions { CustomGpuFactory = null }) // uncomment to disable GPU/GL rendering
|
|||
.SetupWithSingleViewLifetime(); |
|||
|
|||
base.OnParametersSet(); |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> |
|||
<PropertyGroup> |
|||
<TargetFramework>net7.0</TargetFramework> |
|||
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier> |
|||
<Nullable>enable</Nullable> |
|||
<EmccTotalMemory>16777216</EmccTotalMemory> |
|||
<BlazorEnableTimeZoneSupport>false</BlazorEnableTimeZoneSupport> |
|||
<BlazorWebAssemblyPreserveCollationData>false</BlazorWebAssemblyPreserveCollationData> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0-rc.1.22427.2" /> |
|||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0-rc.1.22427.2" PrivateAssets="all" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Skia\Avalonia.Skia\Avalonia.Skia.csproj" /> |
|||
<ProjectReference Include="..\..\src\Web\Avalonia.Web.Blazor\Avalonia.Web.Blazor.csproj" /> |
|||
<ProjectReference Include="..\ControlCatalog\ControlCatalog.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<Import Project="..\..\build\ReferenceCoreLibraries.props" /> |
|||
<Import Project="..\..\build\BuildTargets.targets" /> |
|||
|
|||
<Import Project="..\..\src\Web\Avalonia.Web\Avalonia.Web.props" /> |
|||
<Import Project="..\..\src\Web\Avalonia.Web\Avalonia.Web.targets" /> |
|||
|
|||
</Project> |
|||
|
|||
@ -0,0 +1,29 @@ |
|||
using System; |
|||
using System.Net.Http; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using ControlCatalog.Blazor.Web; |
|||
|
|||
public class Program |
|||
{ |
|||
public static async Task Main(string[] args) |
|||
{ |
|||
await CreateHostBuilder(args).Build().RunAsync(); |
|||
} |
|||
|
|||
public static WebAssemblyHostBuilder CreateHostBuilder(string[] args) |
|||
{ |
|||
var builder = WebAssemblyHostBuilder.CreateDefault(args); |
|||
|
|||
builder.RootComponents.Add<App>("#app"); |
|||
|
|||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); |
|||
|
|||
return builder; |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
Before Width: | Height: | Size: 172 KiB After Width: | Height: | Size: 172 KiB |
@ -1,20 +0,0 @@ |
|||
using Avalonia; |
|||
using Avalonia.Web.Blazor; |
|||
|
|||
namespace ControlCatalog.Web; |
|||
|
|||
public partial class App |
|||
{ |
|||
protected override void OnParametersSet() |
|||
{ |
|||
WebAppBuilder.Configure<ControlCatalog.App>() |
|||
.AfterSetup(_ => |
|||
{ |
|||
ControlCatalog.Pages.EmbedSample.Implementation = new EmbedSampleWeb(); |
|||
}) |
|||
.With(new SkiaOptions { CustomGpuFactory = null }) // uncomment to disable GPU/GL rendering
|
|||
.SetupWithSingleViewLifetime(); |
|||
|
|||
base.OnParametersSet(); |
|||
} |
|||
} |
|||
@ -1,34 +1,42 @@ |
|||
using System; |
|||
|
|||
using Avalonia; |
|||
using System.Runtime.InteropServices.JavaScript; |
|||
using Avalonia.Platform; |
|||
using Avalonia.Web.Blazor; |
|||
using Avalonia.Web; |
|||
|
|||
using ControlCatalog.Pages; |
|||
|
|||
using Microsoft.JSInterop; |
|||
|
|||
namespace ControlCatalog.Web; |
|||
|
|||
public class EmbedSampleWeb : INativeDemoControl |
|||
{ |
|||
public IPlatformHandle CreateControl(bool isSecond, IPlatformHandle parent, Func<IPlatformHandle> createDefault) |
|||
{ |
|||
var runtime = AvaloniaLocator.Current.GetRequiredService<IJSInProcessRuntime>(); |
|||
|
|||
if (isSecond) |
|||
{ |
|||
var iframe = runtime.Invoke<IJSInProcessObjectReference>("document.createElement", "iframe"); |
|||
iframe.InvokeVoid("setAttribute", "src", "https://www.youtube.com/embed/kZCIporjJ70"); |
|||
var iframe = EmbedInterop.CreateElement("iframe"); |
|||
iframe.SetProperty("src", "https://www.youtube.com/embed/kZCIporjJ70"); |
|||
|
|||
return new JSObjectControlHandle(iframe); |
|||
} |
|||
else |
|||
{ |
|||
// window.createAppButton source is defined in "app.js" file.
|
|||
var button = runtime.Invoke<IJSInProcessObjectReference>("window.createAppButton"); |
|||
var defaultHandle = (JSObjectControlHandle)createDefault(); |
|||
|
|||
_ = JSHost.ImportAsync("embed.js", "./embed.js").ContinueWith(_ => |
|||
{ |
|||
EmbedInterop.AddAppButton(defaultHandle.Object); |
|||
}); |
|||
|
|||
return new JSObjectControlHandle(button); |
|||
return defaultHandle; |
|||
} |
|||
} |
|||
} |
|||
|
|||
internal static partial class EmbedInterop |
|||
{ |
|||
[JSImport("globalThis.document.createElement")] |
|||
public static partial JSObject CreateElement(string tagName); |
|||
|
|||
[JSImport("addAppButton", "embed.js")] |
|||
public static partial void AddAppButton(JSObject parentObject); |
|||
} |
|||
|
|||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
@ -0,0 +1,6 @@ |
|||
<linker> |
|||
<assembly fullname="ControlCatalog" preserve="All" /> |
|||
<assembly fullname="ControlCatalog.Web" preserve="All" /> |
|||
<assembly fullname="Avalonia.Themes.Fluent" preserve="All" /> |
|||
<assembly fullname="Avalonia.Themes.Simple" preserve="All" /> |
|||
</linker> |
|||
|
Before Width: | Height: | Size: 172 KiB After Width: | Height: | Size: 172 KiB |
@ -1,105 +0,0 @@ |
|||
using Android.OS; |
|||
using AndroidX.AppCompat.App; |
|||
using Android.Content.Res; |
|||
using AndroidX.Lifecycle; |
|||
using Avalonia.Controls.ApplicationLifetimes; |
|||
using Avalonia.Controls; |
|||
using Android.Runtime; |
|||
using Android.App; |
|||
using Android.Content; |
|||
using System; |
|||
|
|||
namespace Avalonia.Android |
|||
{ |
|||
public abstract class AvaloniaActivity : AppCompatActivity |
|||
{ |
|||
internal class SingleViewLifetime : ISingleViewApplicationLifetime |
|||
{ |
|||
public AvaloniaView View { get; internal set; } |
|||
|
|||
public Control MainView |
|||
{ |
|||
get => (Control)View.Content; |
|||
set => View.Content = value; |
|||
} |
|||
} |
|||
|
|||
internal Action<int, Result, Intent> ActivityResult; |
|||
internal AvaloniaView View; |
|||
internal AvaloniaViewModel _viewModel; |
|||
|
|||
protected abstract AppBuilder CreateAppBuilder(); |
|||
|
|||
protected override void OnCreate(Bundle savedInstanceState) |
|||
{ |
|||
var builder = CreateAppBuilder(); |
|||
|
|||
|
|||
var lifetime = new SingleViewLifetime(); |
|||
|
|||
builder.AfterSetup(x => |
|||
{ |
|||
_viewModel = new ViewModelProvider(this).Get(Java.Lang.Class.FromType(typeof(AvaloniaViewModel))) as AvaloniaViewModel; |
|||
|
|||
View = new AvaloniaView(this); |
|||
if (_viewModel.Content != null) |
|||
{ |
|||
View.Content = _viewModel.Content; |
|||
} |
|||
|
|||
SetContentView(View); |
|||
lifetime.View = View; |
|||
|
|||
View.Prepare(); |
|||
}); |
|||
|
|||
builder.SetupWithLifetime(lifetime); |
|||
|
|||
base.OnCreate(savedInstanceState); |
|||
} |
|||
public object Content |
|||
{ |
|||
get |
|||
{ |
|||
return _viewModel.Content; |
|||
} |
|||
set |
|||
{ |
|||
_viewModel.Content = value; |
|||
if (View != null) |
|||
View.Content = value; |
|||
} |
|||
} |
|||
|
|||
public override void OnConfigurationChanged(Configuration newConfig) |
|||
{ |
|||
base.OnConfigurationChanged(newConfig); |
|||
} |
|||
|
|||
protected override void OnDestroy() |
|||
{ |
|||
View.Content = null; |
|||
|
|||
base.OnDestroy(); |
|||
} |
|||
|
|||
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) |
|||
{ |
|||
base.OnActivityResult(requestCode, resultCode, data); |
|||
|
|||
ActivityResult?.Invoke(requestCode, resultCode, data); |
|||
} |
|||
} |
|||
|
|||
public abstract class AvaloniaActivity<TApp> : AvaloniaActivity where TApp : Application, new() |
|||
{ |
|||
protected virtual AppBuilder CustomizeAppBuilder(AppBuilder builder) => builder.UseAndroid(); |
|||
|
|||
protected override AppBuilder CreateAppBuilder() |
|||
{ |
|||
var builder = AppBuilder.Configure<TApp>(); |
|||
|
|||
return CustomizeAppBuilder(builder); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,70 @@ |
|||
using System; |
|||
using Android.App; |
|||
using Android.Content; |
|||
using Android.Content.Res; |
|||
using Android.OS; |
|||
using Android.Runtime; |
|||
using AndroidX.AppCompat.App; |
|||
using AndroidX.Lifecycle; |
|||
|
|||
namespace Avalonia.Android |
|||
{ |
|||
public abstract class AvaloniaMainActivity : AppCompatActivity, IActivityResultHandler |
|||
{ |
|||
internal static object ViewContent; |
|||
|
|||
public Action<int, Result, Intent> ActivityResult { get; set; } |
|||
internal AvaloniaView View; |
|||
|
|||
protected override void OnCreate(Bundle savedInstanceState) |
|||
{ |
|||
View = new AvaloniaView(this); |
|||
if (ViewContent != null) |
|||
{ |
|||
View.Content = ViewContent; |
|||
} |
|||
|
|||
if (Avalonia.Application.Current.ApplicationLifetime is SingleViewLifetime lifetime) |
|||
{ |
|||
lifetime.View = View; |
|||
} |
|||
|
|||
base.OnCreate(savedInstanceState); |
|||
|
|||
SetContentView(View); |
|||
} |
|||
|
|||
public object Content |
|||
{ |
|||
get |
|||
{ |
|||
return ViewContent; |
|||
} |
|||
set |
|||
{ |
|||
ViewContent = value; |
|||
if (View != null) |
|||
View.Content = value; |
|||
} |
|||
} |
|||
|
|||
public override void OnConfigurationChanged(Configuration newConfig) |
|||
{ |
|||
base.OnConfigurationChanged(newConfig); |
|||
} |
|||
|
|||
protected override void OnDestroy() |
|||
{ |
|||
View.Content = null; |
|||
|
|||
base.OnDestroy(); |
|||
} |
|||
|
|||
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) |
|||
{ |
|||
base.OnActivityResult(requestCode, resultCode, data); |
|||
|
|||
ActivityResult?.Invoke(requestCode, resultCode, data); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
using Android.OS; |
|||
using AndroidX.AppCompat.App; |
|||
using AndroidX.Lifecycle; |
|||
|
|||
namespace Avalonia.Android |
|||
{ |
|||
public abstract class AvaloniaSplashActivity : AppCompatActivity |
|||
{ |
|||
protected abstract AppBuilder CreateAppBuilder(); |
|||
|
|||
protected override void OnCreate(Bundle? savedInstanceState) |
|||
{ |
|||
base.OnCreate(savedInstanceState); |
|||
|
|||
var builder = CreateAppBuilder(); |
|||
|
|||
var lifetime = new SingleViewLifetime(); |
|||
|
|||
builder.SetupWithLifetime(lifetime); |
|||
} |
|||
} |
|||
|
|||
public abstract class AvaloniaSplashActivity<TApp> : AvaloniaSplashActivity where TApp : Application, new() |
|||
{ |
|||
protected virtual AppBuilder CustomizeAppBuilder(AppBuilder builder) => builder.UseAndroid(); |
|||
|
|||
protected override AppBuilder CreateAppBuilder() |
|||
{ |
|||
var builder = AppBuilder.Configure<TApp>(); |
|||
|
|||
return CustomizeAppBuilder(builder); |
|||
} |
|||
} |
|||
} |
|||
@ -1,11 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Avalonia.Android |
|||
{ |
|||
internal class AvaloniaViewModel : AndroidX.Lifecycle.ViewModel |
|||
{ |
|||
public object Content { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using Android.App; |
|||
using Android.Content; |
|||
|
|||
namespace Avalonia.Android |
|||
{ |
|||
public interface IActivityResultHandler |
|||
{ |
|||
public Action<int, Result, Intent> ActivityResult { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using Avalonia.Controls; |
|||
using Avalonia.Controls.ApplicationLifetimes; |
|||
|
|||
namespace Avalonia.Android |
|||
{ |
|||
internal class SingleViewLifetime : ISingleViewApplicationLifetime |
|||
{ |
|||
private AvaloniaView _view; |
|||
|
|||
public AvaloniaView View |
|||
{ |
|||
get => _view; internal set |
|||
{ |
|||
if (_view != null) |
|||
{ |
|||
_view.Content = null; |
|||
_view.Dispose(); |
|||
} |
|||
_view = value; |
|||
_view.Content = MainView; |
|||
} |
|||
} |
|||
|
|||
public Control MainView { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System.Runtime.CompilerServices; |
|||
|
|||
namespace System; |
|||
|
|||
#if !NET6_0_OR_GREATER
|
|||
public static class StringCompatibilityExtensions |
|||
{ |
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public static bool Contains(this string str, char search) => |
|||
str.Contains(search.ToString()); |
|||
} |
|||
#endif
|
|||
@ -0,0 +1,58 @@ |
|||
namespace Avalonia.Media |
|||
{ |
|||
/// <summary>
|
|||
/// The font metrics is holding information about a font's ascent, descent, etc. in design em units.
|
|||
/// </summary>
|
|||
public readonly struct FontMetrics |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the font design units per em.
|
|||
/// </summary>
|
|||
public short DesignEmHeight { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// A <see cref="bool"/> value indicating whether all glyphs in the font have the same advancement.
|
|||
/// </summary>
|
|||
public bool IsFixedPitch { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended distance above the baseline in design em size.
|
|||
/// </summary>
|
|||
public int Ascent { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended distance under the baseline in design em size.
|
|||
/// </summary>
|
|||
public int Descent { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended additional space between two lines of text in design em size.
|
|||
/// </summary>
|
|||
public int LineGap { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended line spacing of a formed text line.
|
|||
/// </summary>
|
|||
public int LineSpacing => Descent - Ascent + LineGap; |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the distance of the underline from the baseline in design em size.
|
|||
/// </summary>
|
|||
public int UnderlinePosition { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the thickness of the underline in design em size.
|
|||
/// </summary>
|
|||
public int UnderlineThickness { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the distance of the strikethrough from the baseline in design em size.
|
|||
/// </summary>
|
|||
public int StrikethroughPosition { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the thickness of the underline in design em size.
|
|||
/// </summary>
|
|||
public int StrikethroughThickness { get; init; } |
|||
} |
|||
} |
|||
@ -1,125 +0,0 @@ |
|||
using System; |
|||
using Avalonia.Platform; |
|||
|
|||
namespace Avalonia.Media |
|||
{ |
|||
public sealed class GlyphTypeface : IDisposable |
|||
{ |
|||
public GlyphTypeface(Typeface typeface) |
|||
: this(FontManager.Current.PlatformImpl.CreateGlyphTypeface(typeface)) |
|||
{ |
|||
} |
|||
|
|||
public GlyphTypeface(IGlyphTypefaceImpl platformImpl) |
|||
{ |
|||
PlatformImpl = platformImpl; |
|||
} |
|||
|
|||
public IGlyphTypefaceImpl PlatformImpl { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the font design units per em.
|
|||
/// </summary>
|
|||
public short DesignEmHeight => PlatformImpl.DesignEmHeight; |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended distance above the baseline in design em size.
|
|||
/// </summary>
|
|||
public int Ascent => PlatformImpl.Ascent; |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended distance under the baseline in design em size.
|
|||
/// </summary>
|
|||
public int Descent => PlatformImpl.Descent; |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended additional space between two lines of text in design em size.
|
|||
/// </summary>
|
|||
public int LineGap => PlatformImpl.LineGap; |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended line height.
|
|||
/// </summary>
|
|||
public int LineHeight => Descent - Ascent + LineGap; |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the distance of the underline from the baseline in design em size.
|
|||
/// </summary>
|
|||
public int UnderlinePosition => PlatformImpl.UnderlinePosition; |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the thickness of the underline in design em size.
|
|||
/// </summary>
|
|||
public int UnderlineThickness => PlatformImpl.UnderlineThickness; |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the distance of the strikethrough from the baseline in design em size.
|
|||
/// </summary>
|
|||
public int StrikethroughPosition => PlatformImpl.StrikethroughPosition; |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the thickness of the underline in design em size.
|
|||
/// </summary>
|
|||
public int StrikethroughThickness => PlatformImpl.StrikethroughThickness; |
|||
|
|||
/// <summary>
|
|||
/// A <see cref="bool"/> value indicating whether all glyphs in the font have the same advancement.
|
|||
/// </summary>
|
|||
public bool IsFixedPitch => PlatformImpl.IsFixedPitch; |
|||
|
|||
/// <summary>
|
|||
/// Returns an glyph index for the specified codepoint.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Returns a replacement glyph if a glyph isn't found.
|
|||
/// </remarks>
|
|||
/// <param name="codepoint">The codepoint.</param>
|
|||
/// <returns>
|
|||
/// A glyph index.
|
|||
/// </returns>
|
|||
public ushort GetGlyph(uint codepoint) => PlatformImpl.GetGlyph(codepoint); |
|||
|
|||
/// <summary>
|
|||
/// Tries to get an glyph index for specified codepoint.
|
|||
/// </summary>
|
|||
/// <param name="codepoint">The codepoint.</param>
|
|||
/// <param name="glyph">A glyph index.</param>
|
|||
/// <returns>
|
|||
/// <c>true</c> if an glyph index was found, <c>false</c> otherwise.
|
|||
/// </returns>
|
|||
public bool TryGetGlyph(uint codepoint, out ushort glyph) |
|||
{ |
|||
glyph = PlatformImpl.GetGlyph(codepoint); |
|||
|
|||
return glyph != 0; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns an array of glyph indices. Codepoints that are not represented by the font are returned as <code>0</code>.
|
|||
/// </summary>
|
|||
/// <param name="codepoints">The codepoints to map.</param>
|
|||
/// <returns></returns>
|
|||
public ushort[] GetGlyphs(ReadOnlySpan<uint> codepoints) => PlatformImpl.GetGlyphs(codepoints); |
|||
|
|||
/// <summary>
|
|||
/// Returns the glyph advance for the specified glyph.
|
|||
/// </summary>
|
|||
/// <param name="glyph">The glyph.</param>
|
|||
/// <returns>
|
|||
/// The advance.
|
|||
/// </returns>
|
|||
public int GetGlyphAdvance(ushort glyph) => PlatformImpl.GetGlyphAdvance(glyph); |
|||
|
|||
/// <summary>
|
|||
/// Returns an array of glyph advances in design em size.
|
|||
/// </summary>
|
|||
/// <param name="glyphs">The glyph indices.</param>
|
|||
/// <returns></returns>
|
|||
public int[] GetGlyphAdvances(ReadOnlySpan<ushort> glyphs) => PlatformImpl.GetGlyphAdvances(glyphs); |
|||
|
|||
void IDisposable.Dispose() |
|||
{ |
|||
PlatformImpl?.Dispose(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,33 +1,33 @@ |
|||
namespace Avalonia.Media.TextFormatting |
|||
{ |
|||
/// <summary>
|
|||
/// A metric that holds information about font specific measurements.
|
|||
/// A metric that holds information about text specific measurements.
|
|||
/// </summary>
|
|||
public readonly struct FontMetrics |
|||
public readonly struct TextMetrics |
|||
{ |
|||
public FontMetrics(Typeface typeface, double fontRenderingEmSize) |
|||
public TextMetrics(Typeface typeface, double fontRenderingEmSize) |
|||
{ |
|||
var glyphTypeface = typeface.GlyphTypeface; |
|||
var fontMetrics = typeface.GlyphTypeface.Metrics; |
|||
|
|||
var scale = fontRenderingEmSize / glyphTypeface.DesignEmHeight; |
|||
var scale = fontRenderingEmSize / fontMetrics.DesignEmHeight; |
|||
|
|||
FontRenderingEmSize = fontRenderingEmSize; |
|||
|
|||
Ascent = glyphTypeface.Ascent * scale; |
|||
Ascent = fontMetrics.Ascent * scale; |
|||
|
|||
Descent = glyphTypeface.Descent * scale; |
|||
Descent = fontMetrics.Descent * scale; |
|||
|
|||
LineGap = glyphTypeface.LineGap * scale; |
|||
LineGap = fontMetrics.LineGap * scale; |
|||
|
|||
LineHeight = Descent - Ascent + LineGap; |
|||
|
|||
UnderlineThickness = glyphTypeface.UnderlineThickness * scale; |
|||
UnderlineThickness = fontMetrics.UnderlineThickness * scale; |
|||
|
|||
UnderlinePosition = glyphTypeface.UnderlinePosition * scale; |
|||
UnderlinePosition = fontMetrics.UnderlinePosition * scale; |
|||
|
|||
StrikethroughThickness = glyphTypeface.StrikethroughThickness * scale; |
|||
StrikethroughThickness = fontMetrics.StrikethroughThickness * scale; |
|||
|
|||
StrikethroughPosition = glyphTypeface.StrikethroughPosition * scale; |
|||
StrikethroughPosition = fontMetrics.StrikethroughPosition * scale; |
|||
} |
|||
|
|||
/// <summary>
|
|||
@ -0,0 +1,22 @@ |
|||
using System; |
|||
using System.Drawing; |
|||
|
|||
namespace Avalonia.Platform |
|||
{ |
|||
public interface IGlyphRunBuffer |
|||
{ |
|||
Span<ushort> GlyphIndices { get; } |
|||
|
|||
IGlyphRunImpl Build(); |
|||
} |
|||
|
|||
public interface IHorizontalGlyphRunBuffer : IGlyphRunBuffer |
|||
{ |
|||
Span<float> GlyphPositions { get; } |
|||
} |
|||
|
|||
public interface IPositionedGlyphRunBuffer : IGlyphRunBuffer |
|||
{ |
|||
Span<PointF> GlyphPositions { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,150 @@ |
|||
using Avalonia.Media; |
|||
using Avalonia.Utilities; |
|||
using FlatColor = Avalonia.Controls.FlatColorPalette.FlatColor; |
|||
|
|||
namespace Avalonia.Controls |
|||
{ |
|||
/// <summary>
|
|||
/// Implements half of the <see cref="FlatColorPalette"/> for improved usability.
|
|||
/// </summary>
|
|||
/// <inheritdoc cref="FlatColorPalette"/>
|
|||
public class FlatHalfColorPalette : IColorPalette |
|||
{ |
|||
protected static Color[,]? _colorChart = null; |
|||
protected static object _colorChartMutex = new object(); |
|||
|
|||
/// <summary>
|
|||
/// Initializes all color chart colors.
|
|||
/// </summary>
|
|||
protected void InitColorChart() |
|||
{ |
|||
lock (_colorChartMutex) |
|||
{ |
|||
if (_colorChart != null) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
_colorChart = new Color[,] |
|||
{ |
|||
// Pomegranate
|
|||
{ |
|||
Color.FromUInt32((uint)FlatColor.Pomegranate1), |
|||
Color.FromUInt32((uint)FlatColor.Pomegranate3), |
|||
Color.FromUInt32((uint)FlatColor.Pomegranate5), |
|||
Color.FromUInt32((uint)FlatColor.Pomegranate7), |
|||
Color.FromUInt32((uint)FlatColor.Pomegranate9), |
|||
}, |
|||
|
|||
// Amethyst
|
|||
{ |
|||
Color.FromUInt32((uint)FlatColor.Amethyst1), |
|||
Color.FromUInt32((uint)FlatColor.Amethyst3), |
|||
Color.FromUInt32((uint)FlatColor.Amethyst5), |
|||
Color.FromUInt32((uint)FlatColor.Amethyst7), |
|||
Color.FromUInt32((uint)FlatColor.Amethyst9), |
|||
}, |
|||
|
|||
// Belize Hole
|
|||
{ |
|||
Color.FromUInt32((uint)FlatColor.BelizeHole1), |
|||
Color.FromUInt32((uint)FlatColor.BelizeHole3), |
|||
Color.FromUInt32((uint)FlatColor.BelizeHole5), |
|||
Color.FromUInt32((uint)FlatColor.BelizeHole7), |
|||
Color.FromUInt32((uint)FlatColor.BelizeHole9), |
|||
}, |
|||
|
|||
// Turquoise
|
|||
{ |
|||
Color.FromUInt32((uint)FlatColor.Turquoise1), |
|||
Color.FromUInt32((uint)FlatColor.Turquoise3), |
|||
Color.FromUInt32((uint)FlatColor.Turquoise5), |
|||
Color.FromUInt32((uint)FlatColor.Turquoise7), |
|||
Color.FromUInt32((uint)FlatColor.Turquoise9), |
|||
}, |
|||
|
|||
// Nephritis
|
|||
{ |
|||
Color.FromUInt32((uint)FlatColor.Nephritis1), |
|||
Color.FromUInt32((uint)FlatColor.Nephritis3), |
|||
Color.FromUInt32((uint)FlatColor.Nephritis5), |
|||
Color.FromUInt32((uint)FlatColor.Nephritis7), |
|||
Color.FromUInt32((uint)FlatColor.Nephritis9), |
|||
}, |
|||
|
|||
// Sunflower
|
|||
{ |
|||
Color.FromUInt32((uint)FlatColor.Sunflower1), |
|||
Color.FromUInt32((uint)FlatColor.Sunflower3), |
|||
Color.FromUInt32((uint)FlatColor.Sunflower5), |
|||
Color.FromUInt32((uint)FlatColor.Sunflower7), |
|||
Color.FromUInt32((uint)FlatColor.Sunflower9), |
|||
}, |
|||
|
|||
// Carrot
|
|||
{ |
|||
Color.FromUInt32((uint)FlatColor.Carrot1), |
|||
Color.FromUInt32((uint)FlatColor.Carrot3), |
|||
Color.FromUInt32((uint)FlatColor.Carrot5), |
|||
Color.FromUInt32((uint)FlatColor.Carrot7), |
|||
Color.FromUInt32((uint)FlatColor.Carrot9), |
|||
}, |
|||
|
|||
// Clouds
|
|||
{ |
|||
Color.FromUInt32((uint)FlatColor.Clouds1), |
|||
Color.FromUInt32((uint)FlatColor.Clouds3), |
|||
Color.FromUInt32((uint)FlatColor.Clouds5), |
|||
Color.FromUInt32((uint)FlatColor.Clouds7), |
|||
Color.FromUInt32((uint)FlatColor.Clouds9), |
|||
}, |
|||
|
|||
// Concrete
|
|||
{ |
|||
Color.FromUInt32((uint)FlatColor.Concrete1), |
|||
Color.FromUInt32((uint)FlatColor.Concrete3), |
|||
Color.FromUInt32((uint)FlatColor.Concrete5), |
|||
Color.FromUInt32((uint)FlatColor.Concrete7), |
|||
Color.FromUInt32((uint)FlatColor.Concrete9), |
|||
}, |
|||
|
|||
// Wet Asphalt
|
|||
{ |
|||
Color.FromUInt32((uint)FlatColor.WetAsphalt1), |
|||
Color.FromUInt32((uint)FlatColor.WetAsphalt3), |
|||
Color.FromUInt32((uint)FlatColor.WetAsphalt5), |
|||
Color.FromUInt32((uint)FlatColor.WetAsphalt7), |
|||
Color.FromUInt32((uint)FlatColor.WetAsphalt9), |
|||
}, |
|||
}; |
|||
} |
|||
|
|||
return; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public int ColorCount |
|||
{ |
|||
get => 10; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public int ShadeCount |
|||
{ |
|||
get => 5; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public Color GetColor(int colorIndex, int shadeIndex) |
|||
{ |
|||
if (_colorChart == null) |
|||
{ |
|||
InitColorChart(); |
|||
} |
|||
|
|||
return _colorChart![ |
|||
MathUtilities.Clamp(colorIndex, 0, ColorCount - 1), |
|||
MathUtilities.Clamp(shadeIndex, 0, ShadeCount - 1)]; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,577 @@ |
|||
using Avalonia.Media; |
|||
using Avalonia.Utilities; |
|||
|
|||
namespace Avalonia.Controls |
|||
{ |
|||
/// <summary>
|
|||
/// Implements a reduced version of the 2014 Material Design color palette.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// This palette is based on the one outlined here:
|
|||
///
|
|||
/// https://material.io/design/color/the-color-system.html#tools-for-picking-colors
|
|||
///
|
|||
/// In order to make the palette uniform and rectangular the following
|
|||
/// alterations were made:
|
|||
///
|
|||
/// 1. The A100-A700 shades of each color are excluded.
|
|||
/// These shades do not exist for all colors (brown/gray).
|
|||
/// 2. Black/White are stand-alone and are also excluded.
|
|||
///
|
|||
/// </remarks>
|
|||
public class MaterialColorPalette : IColorPalette |
|||
{ |
|||
/// <summary>
|
|||
/// Defines all colors in the <see cref="MaterialColorPalette"/>.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// This is done in an enum to ensure it is compiled into the assembly improving
|
|||
/// startup performance.
|
|||
/// </remarks>
|
|||
public enum MaterialColor : uint |
|||
{ |
|||
// Red
|
|||
Red50 = 0xFFFFEBEE, |
|||
Red100 = 0xFFFFCDD2, |
|||
Red200 = 0xFFEF9A9A, |
|||
Red300 = 0xFFE57373, |
|||
Red400 = 0xFFEF5350, |
|||
Red500 = 0xFFF44336, |
|||
Red600 = 0xFFE53935, |
|||
Red700 = 0xFFD32F2F, |
|||
Red800 = 0xFFC62828, |
|||
Red900 = 0xFFB71C1C, |
|||
|
|||
// Pink
|
|||
Pink50 = 0xFFFCE4EC, |
|||
Pink100 = 0xFFF8BBD0, |
|||
Pink200 = 0xFFF48FB1, |
|||
Pink300 = 0xFFF06292, |
|||
Pink400 = 0xFFEC407A, |
|||
Pink500 = 0xFFE91E63, |
|||
Pink600 = 0xFFD81B60, |
|||
Pink700 = 0xFFC2185B, |
|||
Pink800 = 0xFFAD1457, |
|||
Pink900 = 0xFF880E4F, |
|||
|
|||
// Purple
|
|||
Purple50 = 0xFFF3E5F5, |
|||
Purple100 = 0xFFE1BEE7, |
|||
Purple200 = 0xFFCE93D8, |
|||
Purple300 = 0xFFBA68C8, |
|||
Purple400 = 0xFFAB47BC, |
|||
Purple500 = 0xFF9C27B0, |
|||
Purple600 = 0xFF8E24AA, |
|||
Purple700 = 0xFF7B1FA2, |
|||
Purple800 = 0xFF6A1B9A, |
|||
Purple900 = 0xFF4A148C, |
|||
|
|||
// Deep Purple
|
|||
DeepPurple50 = 0xFFEDE7F6, |
|||
DeepPurple100 = 0xFFD1C4E9, |
|||
DeepPurple200 = 0xFFB39DDB, |
|||
DeepPurple300 = 0xFF9575CD, |
|||
DeepPurple400 = 0xFF7E57C2, |
|||
DeepPurple500 = 0xFF673AB7, |
|||
DeepPurple600 = 0xFF5E35B1, |
|||
DeepPurple700 = 0xFF512DA8, |
|||
DeepPurple800 = 0xFF4527A0, |
|||
DeepPurple900 = 0xFF311B92, |
|||
|
|||
// Indigo
|
|||
Indigo50 = 0xFFE8EAF6, |
|||
Indigo100 = 0xFFC5CAE9, |
|||
Indigo200 = 0xFF9FA8DA, |
|||
Indigo300 = 0xFF7986CB, |
|||
Indigo400 = 0xFF5C6BC0, |
|||
Indigo500 = 0xFF3F51B5, |
|||
Indigo600 = 0xFF3949AB, |
|||
Indigo700 = 0xFF303F9F, |
|||
Indigo800 = 0xFF283593, |
|||
Indigo900 = 0xFF1A237E, |
|||
|
|||
// Blue
|
|||
Blue50 = 0xFFE3F2FD, |
|||
Blue100 = 0xFFBBDEFB, |
|||
Blue200 = 0xFF90CAF9, |
|||
Blue300 = 0xFF64B5F6, |
|||
Blue400 = 0xFF42A5F5, |
|||
Blue500 = 0xFF2196F3, |
|||
Blue600 = 0xFF1E88E5, |
|||
Blue700 = 0xFF1976D2, |
|||
Blue800 = 0xFF1565C0, |
|||
Blue900 = 0xFF0D47A1, |
|||
|
|||
// Light Blue
|
|||
LightBlue50 = 0xFFE1F5FE, |
|||
LightBlue100 = 0xFFB3E5FC, |
|||
LightBlue200 = 0xFF81D4FA, |
|||
LightBlue300 = 0xFF4FC3F7, |
|||
LightBlue400 = 0xFF29B6F6, |
|||
LightBlue500 = 0xFF03A9F4, |
|||
LightBlue600 = 0xFF039BE5, |
|||
LightBlue700 = 0xFF0288D1, |
|||
LightBlue800 = 0xFF0277BD, |
|||
LightBlue900 = 0xFF01579B, |
|||
|
|||
// Cyan
|
|||
Cyan50 = 0xFFE0F7FA, |
|||
Cyan100 = 0xFFB2EBF2, |
|||
Cyan200 = 0xFF80DEEA, |
|||
Cyan300 = 0xFF4DD0E1, |
|||
Cyan400 = 0xFF26C6DA, |
|||
Cyan500 = 0xFF00BCD4, |
|||
Cyan600 = 0xFF00ACC1, |
|||
Cyan700 = 0xFF0097A7, |
|||
Cyan800 = 0xFF00838F, |
|||
Cyan900 = 0xFF006064, |
|||
|
|||
// Teal
|
|||
Teal50 = 0xFFE0F2F1, |
|||
Teal100 = 0xFFB2DFDB, |
|||
Teal200 = 0xFF80CBC4, |
|||
Teal300 = 0xFF4DB6AC, |
|||
Teal400 = 0xFF26A69A, |
|||
Teal500 = 0xFF009688, |
|||
Teal600 = 0xFF00897B, |
|||
Teal700 = 0xFF00796B, |
|||
Teal800 = 0xFF00695C, |
|||
Teal900 = 0xFF004D40, |
|||
|
|||
// Green
|
|||
Green50 = 0xFFE8F5E9, |
|||
Green100 = 0xFFC8E6C9, |
|||
Green200 = 0xFFA5D6A7, |
|||
Green300 = 0xFF81C784, |
|||
Green400 = 0xFF66BB6A, |
|||
Green500 = 0xFF4CAF50, |
|||
Green600 = 0xFF43A047, |
|||
Green700 = 0xFF388E3C, |
|||
Green800 = 0xFF2E7D32, |
|||
Green900 = 0xFF1B5E20, |
|||
|
|||
// Light Green
|
|||
LightGreen50 = 0xFFF1F8E9, |
|||
LightGreen100 = 0xFFDCEDC8, |
|||
LightGreen200 = 0xFFC5E1A5, |
|||
LightGreen300 = 0xFFAED581, |
|||
LightGreen400 = 0xFF9CCC65, |
|||
LightGreen500 = 0xFF8BC34A, |
|||
LightGreen600 = 0xFF7CB342, |
|||
LightGreen700 = 0xFF689F38, |
|||
LightGreen800 = 0xFF558B2F, |
|||
LightGreen900 = 0xFF33691E, |
|||
|
|||
// Lime
|
|||
Lime50 = 0xFFF9FBE7, |
|||
Lime100 = 0xFFF0F4C3, |
|||
Lime200 = 0xFFE6EE9C, |
|||
Lime300 = 0xFFDCE775, |
|||
Lime400 = 0xFFD4E157, |
|||
Lime500 = 0xFFCDDC39, |
|||
Lime600 = 0xFFC0CA33, |
|||
Lime700 = 0xFFAFB42B, |
|||
Lime800 = 0xFF9E9D24, |
|||
Lime900 = 0xFF827717, |
|||
|
|||
// Yellow
|
|||
Yellow50 = 0xFFFFFDE7, |
|||
Yellow100 = 0xFFFFF9C4, |
|||
Yellow200 = 0xFFFFF59D, |
|||
Yellow300 = 0xFFFFF176, |
|||
Yellow400 = 0xFFFFEE58, |
|||
Yellow500 = 0xFFFFEB3B, |
|||
Yellow600 = 0xFFFDD835, |
|||
Yellow700 = 0xFFFBC02D, |
|||
Yellow800 = 0xFFF9A825, |
|||
Yellow900 = 0xFFF57F17, |
|||
|
|||
// Amber
|
|||
Amber50 = 0xFFFFF8E1, |
|||
Amber100 = 0xFFFFECB3, |
|||
Amber200 = 0xFFFFE082, |
|||
Amber300 = 0xFFFFD54F, |
|||
Amber400 = 0xFFFFCA28, |
|||
Amber500 = 0xFFFFC107, |
|||
Amber600 = 0xFFFFB300, |
|||
Amber700 = 0xFFFFA000, |
|||
Amber800 = 0xFFFF8F00, |
|||
Amber900 = 0xFFFF6F00, |
|||
|
|||
// Orange
|
|||
Orange50 = 0xFFFFF3E0, |
|||
Orange100 = 0xFFFFE0B2, |
|||
Orange200 = 0xFFFFCC80, |
|||
Orange300 = 0xFFFFB74D, |
|||
Orange400 = 0xFFFFA726, |
|||
Orange500 = 0xFFFF9800, |
|||
Orange600 = 0xFFFB8C00, |
|||
Orange700 = 0xFFF57C00, |
|||
Orange800 = 0xFFEF6C00, |
|||
Orange900 = 0xFFE65100, |
|||
|
|||
// Deep Orange
|
|||
DeepOrange50 = 0xFFFBE9E7, |
|||
DeepOrange100 = 0xFFFFCCBC, |
|||
DeepOrange200 = 0xFFFFAB91, |
|||
DeepOrange300 = 0xFFFF8A65, |
|||
DeepOrange400 = 0xFFFF7043, |
|||
DeepOrange500 = 0xFFFF5722, |
|||
DeepOrange600 = 0xFFF4511E, |
|||
DeepOrange700 = 0xFFE64A19, |
|||
DeepOrange800 = 0xFFD84315, |
|||
DeepOrange900 = 0xFFBF360C, |
|||
|
|||
// Brown
|
|||
Brown50 = 0xFFEFEBE9, |
|||
Brown100 = 0xFFD7CCC8, |
|||
Brown200 = 0xFFBCAAA4, |
|||
Brown300 = 0xFFA1887F, |
|||
Brown400 = 0xFF8D6E63, |
|||
Brown500 = 0xFF795548, |
|||
Brown600 = 0xFF6D4C41, |
|||
Brown700 = 0xFF5D4037, |
|||
Brown800 = 0xFF4E342E, |
|||
Brown900 = 0xFF3E2723, |
|||
|
|||
// Gray
|
|||
Gray50 = 0xFFFAFAFA, |
|||
Gray100 = 0xFFF5F5F5, |
|||
Gray200 = 0xFFEEEEEE, |
|||
Gray300 = 0xFFE0E0E0, |
|||
Gray400 = 0xFFBDBDBD, |
|||
Gray500 = 0xFF9E9E9E, |
|||
Gray600 = 0xFF757575, |
|||
Gray700 = 0xFF616161, |
|||
Gray800 = 0xFF424242, |
|||
Gray900 = 0xFF212121, |
|||
|
|||
// Blue Gray
|
|||
BlueGray50 = 0xFFECEFF1, |
|||
BlueGray100 = 0xFFCFD8DC, |
|||
BlueGray200 = 0xFFB0BEC5, |
|||
BlueGray300 = 0xFF90A4AE, |
|||
BlueGray400 = 0xFF78909C, |
|||
BlueGray500 = 0xFF607D8B, |
|||
BlueGray600 = 0xFF546E7A, |
|||
BlueGray700 = 0xFF455A64, |
|||
BlueGray800 = 0xFF37474F, |
|||
BlueGray900 = 0xFF263238, |
|||
} |
|||
|
|||
// See: https://material.io/design/color/the-color-system.html#tools-for-picking-colors
|
|||
// This is a reduced palette for uniformity
|
|||
protected static Color[,]? _colorChart = null; |
|||
protected static object _colorChartMutex = new object(); |
|||
|
|||
/// <summary>
|
|||
/// Initializes all color chart colors.
|
|||
/// </summary>
|
|||
protected void InitColorChart() |
|||
{ |
|||
lock (_colorChartMutex) |
|||
{ |
|||
if (_colorChart != null) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
_colorChart = new Color[,] |
|||
{ |
|||
// Red
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Red50), |
|||
Color.FromUInt32((uint)MaterialColor.Red100), |
|||
Color.FromUInt32((uint)MaterialColor.Red200), |
|||
Color.FromUInt32((uint)MaterialColor.Red300), |
|||
Color.FromUInt32((uint)MaterialColor.Red400), |
|||
Color.FromUInt32((uint)MaterialColor.Red500), |
|||
Color.FromUInt32((uint)MaterialColor.Red600), |
|||
Color.FromUInt32((uint)MaterialColor.Red700), |
|||
Color.FromUInt32((uint)MaterialColor.Red800), |
|||
Color.FromUInt32((uint)MaterialColor.Red900), |
|||
}, |
|||
|
|||
// Pink
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Pink50), |
|||
Color.FromUInt32((uint)MaterialColor.Pink100), |
|||
Color.FromUInt32((uint)MaterialColor.Pink200), |
|||
Color.FromUInt32((uint)MaterialColor.Pink300), |
|||
Color.FromUInt32((uint)MaterialColor.Pink400), |
|||
Color.FromUInt32((uint)MaterialColor.Pink500), |
|||
Color.FromUInt32((uint)MaterialColor.Pink600), |
|||
Color.FromUInt32((uint)MaterialColor.Pink700), |
|||
Color.FromUInt32((uint)MaterialColor.Pink800), |
|||
Color.FromUInt32((uint)MaterialColor.Pink900), |
|||
}, |
|||
|
|||
// Purple
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Purple50), |
|||
Color.FromUInt32((uint)MaterialColor.Purple100), |
|||
Color.FromUInt32((uint)MaterialColor.Purple200), |
|||
Color.FromUInt32((uint)MaterialColor.Purple300), |
|||
Color.FromUInt32((uint)MaterialColor.Purple400), |
|||
Color.FromUInt32((uint)MaterialColor.Purple500), |
|||
Color.FromUInt32((uint)MaterialColor.Purple600), |
|||
Color.FromUInt32((uint)MaterialColor.Purple700), |
|||
Color.FromUInt32((uint)MaterialColor.Purple800), |
|||
Color.FromUInt32((uint)MaterialColor.Purple900), |
|||
}, |
|||
|
|||
// Deep Purple
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.DeepPurple50), |
|||
Color.FromUInt32((uint)MaterialColor.DeepPurple100), |
|||
Color.FromUInt32((uint)MaterialColor.DeepPurple200), |
|||
Color.FromUInt32((uint)MaterialColor.DeepPurple300), |
|||
Color.FromUInt32((uint)MaterialColor.DeepPurple400), |
|||
Color.FromUInt32((uint)MaterialColor.DeepPurple500), |
|||
Color.FromUInt32((uint)MaterialColor.DeepPurple600), |
|||
Color.FromUInt32((uint)MaterialColor.DeepPurple700), |
|||
Color.FromUInt32((uint)MaterialColor.DeepPurple800), |
|||
Color.FromUInt32((uint)MaterialColor.DeepPurple900), |
|||
}, |
|||
|
|||
// Indigo
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Indigo50), |
|||
Color.FromUInt32((uint)MaterialColor.Indigo100), |
|||
Color.FromUInt32((uint)MaterialColor.Indigo200), |
|||
Color.FromUInt32((uint)MaterialColor.Indigo300), |
|||
Color.FromUInt32((uint)MaterialColor.Indigo400), |
|||
Color.FromUInt32((uint)MaterialColor.Indigo500), |
|||
Color.FromUInt32((uint)MaterialColor.Indigo600), |
|||
Color.FromUInt32((uint)MaterialColor.Indigo700), |
|||
Color.FromUInt32((uint)MaterialColor.Indigo800), |
|||
Color.FromUInt32((uint)MaterialColor.Indigo900), |
|||
}, |
|||
|
|||
// Blue
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Blue50), |
|||
Color.FromUInt32((uint)MaterialColor.Blue100), |
|||
Color.FromUInt32((uint)MaterialColor.Blue200), |
|||
Color.FromUInt32((uint)MaterialColor.Blue300), |
|||
Color.FromUInt32((uint)MaterialColor.Blue400), |
|||
Color.FromUInt32((uint)MaterialColor.Blue500), |
|||
Color.FromUInt32((uint)MaterialColor.Blue600), |
|||
Color.FromUInt32((uint)MaterialColor.Blue700), |
|||
Color.FromUInt32((uint)MaterialColor.Blue800), |
|||
Color.FromUInt32((uint)MaterialColor.Blue900), |
|||
}, |
|||
|
|||
// Light Blue
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.LightBlue50), |
|||
Color.FromUInt32((uint)MaterialColor.LightBlue100), |
|||
Color.FromUInt32((uint)MaterialColor.LightBlue200), |
|||
Color.FromUInt32((uint)MaterialColor.LightBlue300), |
|||
Color.FromUInt32((uint)MaterialColor.LightBlue400), |
|||
Color.FromUInt32((uint)MaterialColor.LightBlue500), |
|||
Color.FromUInt32((uint)MaterialColor.LightBlue600), |
|||
Color.FromUInt32((uint)MaterialColor.LightBlue700), |
|||
Color.FromUInt32((uint)MaterialColor.LightBlue800), |
|||
Color.FromUInt32((uint)MaterialColor.LightBlue900), |
|||
}, |
|||
|
|||
// Cyan
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Cyan50), |
|||
Color.FromUInt32((uint)MaterialColor.Cyan100), |
|||
Color.FromUInt32((uint)MaterialColor.Cyan200), |
|||
Color.FromUInt32((uint)MaterialColor.Cyan300), |
|||
Color.FromUInt32((uint)MaterialColor.Cyan400), |
|||
Color.FromUInt32((uint)MaterialColor.Cyan500), |
|||
Color.FromUInt32((uint)MaterialColor.Cyan600), |
|||
Color.FromUInt32((uint)MaterialColor.Cyan700), |
|||
Color.FromUInt32((uint)MaterialColor.Cyan800), |
|||
Color.FromUInt32((uint)MaterialColor.Cyan900), |
|||
}, |
|||
|
|||
// Teal
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Teal50), |
|||
Color.FromUInt32((uint)MaterialColor.Teal100), |
|||
Color.FromUInt32((uint)MaterialColor.Teal200), |
|||
Color.FromUInt32((uint)MaterialColor.Teal300), |
|||
Color.FromUInt32((uint)MaterialColor.Teal400), |
|||
Color.FromUInt32((uint)MaterialColor.Teal500), |
|||
Color.FromUInt32((uint)MaterialColor.Teal600), |
|||
Color.FromUInt32((uint)MaterialColor.Teal700), |
|||
Color.FromUInt32((uint)MaterialColor.Teal800), |
|||
Color.FromUInt32((uint)MaterialColor.Teal900), |
|||
}, |
|||
|
|||
// Green
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Green50), |
|||
Color.FromUInt32((uint)MaterialColor.Green100), |
|||
Color.FromUInt32((uint)MaterialColor.Green200), |
|||
Color.FromUInt32((uint)MaterialColor.Green300), |
|||
Color.FromUInt32((uint)MaterialColor.Green400), |
|||
Color.FromUInt32((uint)MaterialColor.Green500), |
|||
Color.FromUInt32((uint)MaterialColor.Green600), |
|||
Color.FromUInt32((uint)MaterialColor.Green700), |
|||
Color.FromUInt32((uint)MaterialColor.Green800), |
|||
Color.FromUInt32((uint)MaterialColor.Green900), |
|||
}, |
|||
|
|||
// Light Green
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.LightGreen50), |
|||
Color.FromUInt32((uint)MaterialColor.LightGreen100), |
|||
Color.FromUInt32((uint)MaterialColor.LightGreen200), |
|||
Color.FromUInt32((uint)MaterialColor.LightGreen300), |
|||
Color.FromUInt32((uint)MaterialColor.LightGreen400), |
|||
Color.FromUInt32((uint)MaterialColor.LightGreen500), |
|||
Color.FromUInt32((uint)MaterialColor.LightGreen600), |
|||
Color.FromUInt32((uint)MaterialColor.LightGreen700), |
|||
Color.FromUInt32((uint)MaterialColor.LightGreen800), |
|||
Color.FromUInt32((uint)MaterialColor.LightGreen900), |
|||
}, |
|||
|
|||
// Lime
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Lime50), |
|||
Color.FromUInt32((uint)MaterialColor.Lime100), |
|||
Color.FromUInt32((uint)MaterialColor.Lime200), |
|||
Color.FromUInt32((uint)MaterialColor.Lime300), |
|||
Color.FromUInt32((uint)MaterialColor.Lime400), |
|||
Color.FromUInt32((uint)MaterialColor.Lime500), |
|||
Color.FromUInt32((uint)MaterialColor.Lime600), |
|||
Color.FromUInt32((uint)MaterialColor.Lime700), |
|||
Color.FromUInt32((uint)MaterialColor.Lime800), |
|||
Color.FromUInt32((uint)MaterialColor.Lime900), |
|||
}, |
|||
|
|||
// Yellow
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Yellow50), |
|||
Color.FromUInt32((uint)MaterialColor.Yellow100), |
|||
Color.FromUInt32((uint)MaterialColor.Yellow200), |
|||
Color.FromUInt32((uint)MaterialColor.Yellow300), |
|||
Color.FromUInt32((uint)MaterialColor.Yellow400), |
|||
Color.FromUInt32((uint)MaterialColor.Yellow500), |
|||
Color.FromUInt32((uint)MaterialColor.Yellow600), |
|||
Color.FromUInt32((uint)MaterialColor.Yellow700), |
|||
Color.FromUInt32((uint)MaterialColor.Yellow800), |
|||
Color.FromUInt32((uint)MaterialColor.Yellow900), |
|||
}, |
|||
|
|||
// Amber
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Amber50), |
|||
Color.FromUInt32((uint)MaterialColor.Amber100), |
|||
Color.FromUInt32((uint)MaterialColor.Amber200), |
|||
Color.FromUInt32((uint)MaterialColor.Amber300), |
|||
Color.FromUInt32((uint)MaterialColor.Amber400), |
|||
Color.FromUInt32((uint)MaterialColor.Amber500), |
|||
Color.FromUInt32((uint)MaterialColor.Amber600), |
|||
Color.FromUInt32((uint)MaterialColor.Amber700), |
|||
Color.FromUInt32((uint)MaterialColor.Amber800), |
|||
Color.FromUInt32((uint)MaterialColor.Amber900), |
|||
}, |
|||
|
|||
// Orange
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Orange50), |
|||
Color.FromUInt32((uint)MaterialColor.Orange100), |
|||
Color.FromUInt32((uint)MaterialColor.Orange200), |
|||
Color.FromUInt32((uint)MaterialColor.Orange300), |
|||
Color.FromUInt32((uint)MaterialColor.Orange400), |
|||
Color.FromUInt32((uint)MaterialColor.Orange500), |
|||
Color.FromUInt32((uint)MaterialColor.Orange600), |
|||
Color.FromUInt32((uint)MaterialColor.Orange700), |
|||
Color.FromUInt32((uint)MaterialColor.Orange800), |
|||
Color.FromUInt32((uint)MaterialColor.Orange900), |
|||
}, |
|||
|
|||
// Deep Orange
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.DeepOrange50), |
|||
Color.FromUInt32((uint)MaterialColor.DeepOrange100), |
|||
Color.FromUInt32((uint)MaterialColor.DeepOrange200), |
|||
Color.FromUInt32((uint)MaterialColor.DeepOrange300), |
|||
Color.FromUInt32((uint)MaterialColor.DeepOrange400), |
|||
Color.FromUInt32((uint)MaterialColor.DeepOrange500), |
|||
Color.FromUInt32((uint)MaterialColor.DeepOrange600), |
|||
Color.FromUInt32((uint)MaterialColor.DeepOrange700), |
|||
Color.FromUInt32((uint)MaterialColor.DeepOrange800), |
|||
Color.FromUInt32((uint)MaterialColor.DeepOrange900), |
|||
}, |
|||
|
|||
// Brown
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Brown50), |
|||
Color.FromUInt32((uint)MaterialColor.Brown100), |
|||
Color.FromUInt32((uint)MaterialColor.Brown200), |
|||
Color.FromUInt32((uint)MaterialColor.Brown300), |
|||
Color.FromUInt32((uint)MaterialColor.Brown400), |
|||
Color.FromUInt32((uint)MaterialColor.Brown500), |
|||
Color.FromUInt32((uint)MaterialColor.Brown600), |
|||
Color.FromUInt32((uint)MaterialColor.Brown700), |
|||
Color.FromUInt32((uint)MaterialColor.Brown800), |
|||
Color.FromUInt32((uint)MaterialColor.Brown900), |
|||
}, |
|||
|
|||
// Gray
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Gray50), |
|||
Color.FromUInt32((uint)MaterialColor.Gray100), |
|||
Color.FromUInt32((uint)MaterialColor.Gray200), |
|||
Color.FromUInt32((uint)MaterialColor.Gray300), |
|||
Color.FromUInt32((uint)MaterialColor.Gray400), |
|||
Color.FromUInt32((uint)MaterialColor.Gray500), |
|||
Color.FromUInt32((uint)MaterialColor.Gray600), |
|||
Color.FromUInt32((uint)MaterialColor.Gray700), |
|||
Color.FromUInt32((uint)MaterialColor.Gray800), |
|||
Color.FromUInt32((uint)MaterialColor.Gray900), |
|||
}, |
|||
|
|||
// Blue Gray
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.BlueGray50), |
|||
Color.FromUInt32((uint)MaterialColor.BlueGray100), |
|||
Color.FromUInt32((uint)MaterialColor.BlueGray200), |
|||
Color.FromUInt32((uint)MaterialColor.BlueGray300), |
|||
Color.FromUInt32((uint)MaterialColor.BlueGray400), |
|||
Color.FromUInt32((uint)MaterialColor.BlueGray500), |
|||
Color.FromUInt32((uint)MaterialColor.BlueGray600), |
|||
Color.FromUInt32((uint)MaterialColor.BlueGray700), |
|||
Color.FromUInt32((uint)MaterialColor.BlueGray800), |
|||
Color.FromUInt32((uint)MaterialColor.BlueGray900), |
|||
}, |
|||
}; |
|||
} |
|||
|
|||
return; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public int ColorCount |
|||
{ |
|||
get => 19; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public int ShadeCount |
|||
{ |
|||
get => 10; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public Color GetColor(int colorIndex, int shadeIndex) |
|||
{ |
|||
if (_colorChart == null) |
|||
{ |
|||
InitColorChart(); |
|||
} |
|||
|
|||
return _colorChart![ |
|||
MathUtilities.Clamp(colorIndex, 0, ColorCount - 1), |
|||
MathUtilities.Clamp(shadeIndex, 0, ShadeCount - 1)]; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,150 @@ |
|||
using Avalonia.Media; |
|||
using Avalonia.Utilities; |
|||
using MaterialColor = Avalonia.Controls.MaterialColorPalette.MaterialColor; |
|||
|
|||
namespace Avalonia.Controls |
|||
{ |
|||
/// <summary>
|
|||
/// Implements half of the <see cref="MaterialColorPalette"/> for improved usability.
|
|||
/// </summary>
|
|||
/// <inheritdoc cref="MaterialColorPalette"/>
|
|||
public class MaterialHalfColorPalette : IColorPalette |
|||
{ |
|||
protected static Color[,]? _colorChart = null; |
|||
protected static object _colorChartMutex = new object(); |
|||
|
|||
/// <summary>
|
|||
/// Initializes all color chart colors.
|
|||
/// </summary>
|
|||
protected void InitColorChart() |
|||
{ |
|||
lock (_colorChartMutex) |
|||
{ |
|||
if (_colorChart != null) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
_colorChart = new Color[,] |
|||
{ |
|||
// Red
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Red50), |
|||
Color.FromUInt32((uint)MaterialColor.Red200), |
|||
Color.FromUInt32((uint)MaterialColor.Red400), |
|||
Color.FromUInt32((uint)MaterialColor.Red600), |
|||
Color.FromUInt32((uint)MaterialColor.Red800), |
|||
}, |
|||
|
|||
// Purple
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Purple50), |
|||
Color.FromUInt32((uint)MaterialColor.Purple200), |
|||
Color.FromUInt32((uint)MaterialColor.Purple400), |
|||
Color.FromUInt32((uint)MaterialColor.Purple600), |
|||
Color.FromUInt32((uint)MaterialColor.Purple800), |
|||
}, |
|||
|
|||
// Indigo
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Indigo50), |
|||
Color.FromUInt32((uint)MaterialColor.Indigo200), |
|||
Color.FromUInt32((uint)MaterialColor.Indigo400), |
|||
Color.FromUInt32((uint)MaterialColor.Indigo600), |
|||
Color.FromUInt32((uint)MaterialColor.Indigo800), |
|||
}, |
|||
|
|||
// Light Blue
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.LightBlue50), |
|||
Color.FromUInt32((uint)MaterialColor.LightBlue200), |
|||
Color.FromUInt32((uint)MaterialColor.LightBlue400), |
|||
Color.FromUInt32((uint)MaterialColor.LightBlue600), |
|||
Color.FromUInt32((uint)MaterialColor.LightBlue800), |
|||
}, |
|||
|
|||
// Teal
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Teal50), |
|||
Color.FromUInt32((uint)MaterialColor.Teal200), |
|||
Color.FromUInt32((uint)MaterialColor.Teal400), |
|||
Color.FromUInt32((uint)MaterialColor.Teal600), |
|||
Color.FromUInt32((uint)MaterialColor.Teal800), |
|||
}, |
|||
|
|||
// Light Green
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.LightGreen50), |
|||
Color.FromUInt32((uint)MaterialColor.LightGreen200), |
|||
Color.FromUInt32((uint)MaterialColor.LightGreen400), |
|||
Color.FromUInt32((uint)MaterialColor.LightGreen600), |
|||
Color.FromUInt32((uint)MaterialColor.LightGreen800), |
|||
}, |
|||
|
|||
// Yellow
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Yellow50), |
|||
Color.FromUInt32((uint)MaterialColor.Yellow200), |
|||
Color.FromUInt32((uint)MaterialColor.Yellow400), |
|||
Color.FromUInt32((uint)MaterialColor.Yellow600), |
|||
Color.FromUInt32((uint)MaterialColor.Yellow800), |
|||
}, |
|||
|
|||
// Orange
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Orange50), |
|||
Color.FromUInt32((uint)MaterialColor.Orange200), |
|||
Color.FromUInt32((uint)MaterialColor.Orange400), |
|||
Color.FromUInt32((uint)MaterialColor.Orange600), |
|||
Color.FromUInt32((uint)MaterialColor.Orange800), |
|||
}, |
|||
|
|||
// Brown
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.Brown50), |
|||
Color.FromUInt32((uint)MaterialColor.Brown200), |
|||
Color.FromUInt32((uint)MaterialColor.Brown400), |
|||
Color.FromUInt32((uint)MaterialColor.Brown600), |
|||
Color.FromUInt32((uint)MaterialColor.Brown800), |
|||
}, |
|||
|
|||
// Blue Gray
|
|||
{ |
|||
Color.FromUInt32((uint)MaterialColor.BlueGray50), |
|||
Color.FromUInt32((uint)MaterialColor.BlueGray200), |
|||
Color.FromUInt32((uint)MaterialColor.BlueGray400), |
|||
Color.FromUInt32((uint)MaterialColor.BlueGray600), |
|||
Color.FromUInt32((uint)MaterialColor.BlueGray800), |
|||
}, |
|||
}; |
|||
} |
|||
|
|||
return; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public int ColorCount |
|||
{ |
|||
get => 10; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public int ShadeCount |
|||
{ |
|||
get => 5; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public Color GetColor(int colorIndex, int shadeIndex) |
|||
{ |
|||
if (_colorChart == null) |
|||
{ |
|||
InitColorChart(); |
|||
} |
|||
|
|||
return _colorChart![ |
|||
MathUtilities.Clamp(colorIndex, 0, ColorCount - 1), |
|||
MathUtilities.Clamp(shadeIndex, 0, ShadeCount - 1)]; |
|||
} |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue