Skip to content

Commit

Permalink
让渲染层分开,因为看起来实现代码很多
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Oct 13, 2024
1 parent 842c358 commit 5067d3e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public TextEditor()
HorizontalAlignment = HorizontalAlignment.Stretch;
VerticalAlignment = VerticalAlignment.Stretch;

// 调试代码
TextEditorCore.AppendText("123");
}

Expand All @@ -35,11 +36,13 @@ public TextEditor()
protected override Size MeasureOverride(Size availableSize)
{
var result = base.MeasureOverride(availableSize);
// 文本库,有多少就要多少
return availableSize;
}

protected override Size ArrangeOverride(Size finalSize)
{
// 实际布局多大就使用多大
TextEditorCore.DocumentManager.DocumentWidth = finalSize.Width;
TextEditorCore.DocumentManager.DocumentHeight = finalSize.Height;

Expand Down Expand Up @@ -86,6 +89,10 @@ public void Render(ImmediateDrawingContext context)
using ISkiaSharpApiLease skiaSharpApiLease = skiaSharpApiLeaseFeature.Lease();
_render.Render(skiaSharpApiLease.SkCanvas);
}
else
{
// 不支持 Skia 绘制
}
}

public Rect Bounds { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using SkiaSharp;

namespace LightTextEditorPlus;

/// <summary>
/// 文本的 Skia 渲染器
/// </summary>
public interface ITextEditorSkiaRender
{
void Render(SKCanvas canvas);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=api_005F/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace LightTextEditorPlus.Rendering;

class RenderManager: IRenderManager
class RenderManager: IRenderManager, ITextEditorSkiaRender
{
record SkiaTextRenderInfo();

Expand Down
18 changes: 2 additions & 16 deletions LightTextEditorPlus/LightTextEditorPlus.Skia/SkiaTextEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
using LightTextEditorPlus.Core.Platform;
using LightTextEditorPlus.Core.Rendering;
using LightTextEditorPlus.Rendering;
using SkiaSharp;

namespace LightTextEditorPlus;

public partial class SkiaTextEditor : IRenderManager, ITextEditorSkiaRender
public partial class SkiaTextEditor : IRenderManager
{
public SkiaTextEditor(PlatformProvider? platformProvider = null)
{
Expand All @@ -39,23 +38,10 @@ void IRenderManager.Render(RenderInfoProvider renderInfoProvider)

public ITextEditorSkiaRender GetCurrentRender()
{
return this;
return RenderManager;
}

public event EventHandler? RenderRequested;

public void Render(SKCanvas canvas)
{
RenderManager.Render(canvas);
}
}

/// <summary>
/// 文本的 Skia 渲染器
/// </summary>
public interface ITextEditorSkiaRender
{
void Render(SKCanvas canvas);
}

public class SkiaTextEditorPlatformProvider : PlatformProvider
Expand Down

0 comments on commit 5067d3e

Please sign in to comment.