Skip to content

Commit

Permalink
1.2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
taublast committed Jun 26, 2024
1 parent c5eb9ef commit bd31b96
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 82 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ https://github.com/taublast/DrawnUi.Maui/assets/25801194/3b360229-ce3b-4d33-a85b
## What's new

* New: SvgSpan for SkiaLabel
* FIxes for: SkiaMarkdownLabel, gestures, subpixel scrolling, SkiaDrawer, SkiaLayout, Canvas and some more.
* Critical fix for release builds native crash while using ImageDoubleBuffered cache
* Fixes for: gestures, SkiaMarkdownLabel, SkiaDrawer, SkiaLayout, Canvas and more.

## Demo Apps

Expand Down
4 changes: 2 additions & 2 deletions dev/uploadnugets.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ REM Define the source directory for the packages
set "source_dir=E:\Nugets"

REM Define the file mask for the packages
set "file_mask=DrawnUi.Maui*.1.2.2.617*.nupkg"
REM set "file_mask=AppoMobi.Maui.DrawnUi.1.2.2.617*.*nupkg"
REM set "file_mask=DrawnUi.Maui*.1.2.2.626*.nupkg"
set "file_mask=AppoMobi.Maui.DrawnUi.1.2.2.626*.*nupkg"

REM Loop through each package file in the source directory
for %%f in ("%source_dir%\%file_mask%") do (
Expand Down
3 changes: 3 additions & 0 deletions src/Addons/DrawnUi.Maui.Camera/SkiaCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ public SkiaCamera()

public override ScaledSize Measure(float widthConstraint, float heightConstraint, float scale)
{
if (IsDisposed || IsDisposing)
return ScaledSize.Default;

if (Display == null)
{
//will serve as preview wrapper
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<PropertyGroup Condition="'$(UseSkiaSharp3)' != 'true'">
<PackageReleaseNotes>Using SkiaSharp 2.xx. Checkout the DrawnUi Sandbox project for usage example.</PackageReleaseNotes>
<Version>1.2.2.624</Version>
<Version>1.2.3.1</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(UseSkiaSharp3)' == 'true'">
Expand Down
16 changes: 16 additions & 0 deletions src/DrawnUi.Maui.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ VisualStudioVersion = 17.8.34330.188
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3EEA7F62-9878-451E-A506-28AB7C5DEEB8}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
..\README.md = ..\README.md
ToDo.txt = ToDo.txt
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrawnUi.Maui", "Engine\DrawnUi.Maui.csproj", "{D76B6239-94A0-482C-A0FF-A764017B7393}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{0DDE4AC1-3D8B-42C8-88F2-6F45B89F72F2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Engine", "Engine", "{22EE9E7A-55C6-4F9F-9878-9376F7BC1DCC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sandbox", "samples\Sandbox\Sandbox.csproj", "{B1AD715F-E8D9-4514-9D2C-D084E66566F7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Addons", "Addons", "{8B60E2B6-4347-450E-9999-319D8C7697D3}"
Expand All @@ -31,6 +36,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrawnUi.Maui.Rive", "Addons
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrawnUi.Maui.Camera", "Addons\DrawnUi.Maui.Camera\DrawnUi.Maui.Camera.csproj", "{D4FC0BDB-3FE8-49C9-8B76-53C83128B899}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SomeMauiApp", "..\..\AppoMobi.Maui.DrawnUi.Demo\src\Usual\SomeMauiApp.csproj", "{F71645D2-F7AF-4C1C-9509-D01692622110}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -75,18 +82,27 @@ Global
{D4FC0BDB-3FE8-49C9-8B76-53C83128B899}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4FC0BDB-3FE8-49C9-8B76-53C83128B899}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4FC0BDB-3FE8-49C9-8B76-53C83128B899}.Release|Any CPU.Build.0 = Release|Any CPU
{F71645D2-F7AF-4C1C-9509-D01692622110}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F71645D2-F7AF-4C1C-9509-D01692622110}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F71645D2-F7AF-4C1C-9509-D01692622110}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{F71645D2-F7AF-4C1C-9509-D01692622110}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F71645D2-F7AF-4C1C-9509-D01692622110}.Release|Any CPU.Build.0 = Release|Any CPU
{F71645D2-F7AF-4C1C-9509-D01692622110}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D76B6239-94A0-482C-A0FF-A764017B7393} = {22EE9E7A-55C6-4F9F-9878-9376F7BC1DCC}
{B1AD715F-E8D9-4514-9D2C-D084E66566F7} = {0DDE4AC1-3D8B-42C8-88F2-6F45B89F72F2}
{D5538622-9DC4-40CD-B3E8-07BF07C3C9A5} = {8B60E2B6-4347-450E-9999-319D8C7697D3}
{03A9CCB9-92B5-4A4A-8696-127603AE8816} = {507756AE-A224-4CDD-80C1-55F06502DE1B}
{C8BAD2E9-FDFA-404D-85AE-2F179CA78016} = {507756AE-A224-4CDD-80C1-55F06502DE1B}
{C9CABC24-B5D7-4824-BD1B-279BEF419348} = {8B60E2B6-4347-450E-9999-319D8C7697D3}
{FF6A6A51-01FC-4CEF-9386-D132AD9EBF18} = {8B60E2B6-4347-450E-9999-319D8C7697D3}
{1F524822-400E-4801-AE05-4B3A14B603AD} = {8B60E2B6-4347-450E-9999-319D8C7697D3}
{D4FC0BDB-3FE8-49C9-8B76-53C83128B899} = {8B60E2B6-4347-450E-9999-319D8C7697D3}
{F71645D2-F7AF-4C1C-9509-D01692622110} = {0DDE4AC1-3D8B-42C8-88F2-6F45B89F72F2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {08E673B7-06BF-468C-8D6C-2D1AA8E4A8CA}
Expand Down
3 changes: 3 additions & 0 deletions src/Engine/Controls/Button/SkiaButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public SkiaButton()

public override ScaledSize Measure(float widthConstraint, float heightConstraint, float scale)
{
if (IsDisposed || IsDisposing)
return ScaledSize.Default;

var measured = base.Measure(widthConstraint, heightConstraint, scale);
var test = this.WidthRequest;
return measured;
Expand Down
3 changes: 3 additions & 0 deletions src/Engine/Controls/EditText/SkiaMauiEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ public override void OnDisposing()

public override ScaledSize Measure(float widthConstraint, float heightConstraint, float scale)
{
if (IsDisposed || IsDisposing)
return ScaledSize.Default;

GetOrCreateControl();

return base.Measure(widthConstraint, heightConstraint, scale);
Expand Down
3 changes: 3 additions & 0 deletions src/Engine/Controls/EditText/SkiaMauiEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ public override void OnDisposing()

public override ScaledSize Measure(float widthConstraint, float heightConstraint, float scale)
{
if (IsDisposed || IsDisposing)
return ScaledSize.Default;

GetOrCreateControl();

return base.Measure(widthConstraint, heightConstraint, scale);
Expand Down
5 changes: 4 additions & 1 deletion src/Engine/Controls/Navigation/SkiaShell.NavigationLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ public async Task Close(T control, bool animated)

control.SetParent(null);

control.Dispose();
Tasks.StartDelayed(TimeSpan.FromSeconds(3.5), () =>
{
control?.Dispose();
});
}
catch (Exception e)
{
Expand Down
5 changes: 4 additions & 1 deletion src/Engine/Controls/Navigation/SkiaShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,10 @@ public virtual async Task UnfreezeRootLayout(SkiaControl control, bool animated)

RootLayout.RemoveSubView(screenshot);

screenshot?.Dispose();
Tasks.StartDelayed(TimeSpan.FromSeconds(3.5), () =>
{
screenshot?.Dispose();
});
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/Engine/Draw/Element/SkiaMauiElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public virtual Size MeasureAndArrangeMauiElement(double ptsWidth, double ptsHeig

public override ScaledSize Measure(float widthConstraint, float heightConstraint, float scale)
{
if (IsDisposed || IsDisposing)
return ScaledSize.Default;

//lock (lockLayout)
{
var bounds = base.Measure(widthConstraint, heightConstraint, scale);
Expand Down
18 changes: 14 additions & 4 deletions src/Engine/Draw/Layout/SkiaLayout.ViewsAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public void InitializeTemplates(Func<object> template, IList dataContexts, int p

async Task InitializeFull(bool measure)
{
//lock (_lockTemplates)
lock (_lockTemplates)
{
TemplesInvalidating = false;

Expand All @@ -370,7 +370,16 @@ async Task InitializeFull(bool measure)

FillPool(reserve, dataContexts);

kill?.Dispose();
if (kill != null)
{
//we need a delay here for several threads access, if previous cells are still being drawn. not elegant but.. remains in global todo to find a better way.
Tasks.StartDelayed(TimeSpan.FromSeconds(3.5), () =>
{
kill?.Dispose();
});
}

Monitor.PulseAll(_lockTemplates);
}

if (measure)
Expand All @@ -392,7 +401,7 @@ async Task InitializeFull(bool measure)
void InitializeSoft(bool layoutChanged)
{

//lock (_lockTemplates)
lock (_lockTemplates)
{
TemplesInvalidating = false;

Expand All @@ -405,6 +414,7 @@ void InitializeSoft(bool layoutChanged)
}
}
//MarkAllViewsAsHidden(); //todo think
Monitor.PulseAll(_lockTemplates);
}

TemplatesAvailable();
Expand Down Expand Up @@ -636,7 +646,7 @@ public void ReleaseView(SkiaControl viewModel, bool reset = false)

public SkiaControl GetTemplateInstance()
{
//lock (_lockTemplates)
lock (_lockTemplates)
{
if (_templatedViewsPool == null || _dataContexts == null)
{
Expand Down
5 changes: 0 additions & 5 deletions src/Engine/Draw/Layout/SkiaLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,6 @@ protected virtual int GetTemplatesPoolLimit()

public override void Invalidate()
{
if (Tag == "Posts")
{
Debug.WriteLine("Invalidate posts!!!");
}

base.Invalidate();

Update();
Expand Down
21 changes: 9 additions & 12 deletions src/Engine/Draw/SkiaControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3691,6 +3691,9 @@ public struct ParentMeasureRequest
/// <returns></returns>
public virtual ScaledSize Measure(float widthConstraint, float heightConstraint, float scale)
{
if (IsDisposed || IsDisposing)
return ScaledSize.Default;

if (IsMeasuring) //basically we need this for cache double buffering to avoid conflicts with background thread
{
NeedRemeasuring = true;
Expand Down Expand Up @@ -4753,13 +4756,13 @@ public CachedObject RenderObject
//lock both RenderObjectPrevious and RenderObject
lock (LockDraw)
{
if (_renderObject != null)
if (_renderObject != null) //if we already have something in actual cache then
{
if (UsingCacheType == SkiaCacheType.ImageDoubleBuffered
|| UsingCacheType == SkiaCacheType.Image
|| UsingCacheType == SkiaCacheType.Image //to just reuse same surface
|| UsingCacheType == SkiaCacheType.ImageComposite)
{
RenderObjectPrevious = _renderObject;
RenderObjectPrevious = _renderObject; //send it to back for special cases
}
else
{
Expand Down Expand Up @@ -5004,18 +5007,12 @@ protected virtual bool UseRenderingObject(SkiaDrawingContext context, SKRect rec
var cacheType = UsingCacheType;
var cacheOffscreen = RenderObjectPrevious;


if (RenderObjectPrevious != null && RenderObjectPreviousNeedsUpdate
||
cacheType != SkiaCacheType.ImageDoubleBuffered &&
cacheType != SkiaCacheType.ImageComposite)
if (RenderObjectPrevious != null && RenderObjectPreviousNeedsUpdate)
{
//this might happen only if we switch cache type at runtime
//while hotreloading etc.. rare case
RenderObjectPrevious?.Dispose();
DisposeObject(RenderObjectPrevious);
RenderObjectPrevious = null;
RenderObjectPreviousNeedsUpdate = false;
}
RenderObjectPreviousNeedsUpdate = false;

if (cache != null)
{
Expand Down
52 changes: 19 additions & 33 deletions src/Engine/Draw/Text/SkiaLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ protected virtual void DrawTextInternal(SKCanvas canvas, string text, float x, f

#region RASTERIZE - NOT USED

/*
public static void DrawRasterizedText(SKCanvas canvas, float x, float y, string text, SKPaint textPaint, SKColor colorOutline)
{
using (var imageText = RasterizeText(text, textPaint, colorOutline))
Expand Down Expand Up @@ -304,6 +306,7 @@ public static SKImage RasterizeText(string text, SKPaint paint, SKColor colorOut
}
*/

#endregion

Expand Down Expand Up @@ -448,6 +451,9 @@ public void MergeSpansForLines(

public override ScaledSize Measure(float widthConstraint, float heightConstraint, float scale)
{
if (IsDisposed || IsDisposing)
return ScaledSize.Default;

ReplaceFont();

//background measuring or invisible or self measure from draw because layout will never pass -1
Expand Down Expand Up @@ -920,6 +926,9 @@ public void DrawLines(SkiaDrawingContext ctx,
SKRect rectDraw,
double scale)
{
if (paintDefault == null)
return;

//apply dynamic properties that were not applied during measure
paintDefault.Color = TextColor.ToSKColor();
paintDefault.BlendMode = this.FillBlendMode;
Expand Down Expand Up @@ -1803,44 +1812,17 @@ public static SKShaper.Result GetShapedText(SKShaper shaper, string text, float
throw new ArgumentNullException(nameof(paint));

using var font = paint.ToFont();
font.Typeface = shaper.Typeface;

// shape the text
var result = shaper.Shape(text, x, y, paint);

return result;

/*
// create the text blob
using var builder = new SKTextBlobBuilder();
var run = builder.AllocatePositionedRun(font, result.Codepoints.Length);
// copy the glyphs
var g = run.GetGlyphSpan();
var p = run.GetPositionSpan();
for (var i = 0; i < result.Codepoints.Length; i++)
if (font != null && shaper.Typeface != null)
{
g[i] = (ushort)result.Codepoints[i];
p[i] = result.Points[i];
font.Typeface = shaper.Typeface;
// shape the text
var result = shaper.Shape(text, x, y, paint);
return result;
}

// build
using var textBlob = builder.Build();
return null;

// adjust alignment
var xOffset = 0f;
if (paint.TextAlign != SKTextAlign.Left) {
var width = result.Width;
if (paint.TextAlign == SKTextAlign.Center)
width *= 0.5f;
xOffset -= width;
}

*/


//canvas.DrawText(textBlob, xOffset, 0, paint);
}


Expand Down Expand Up @@ -1903,6 +1885,10 @@ public static bool IsGlyphAlwaysAvailable(string glyphText)
{
using var shaper = new SKShaper(paint.Typeface);
var result = GetShapedText(shaper, text, 0, 0, paint);
if (result == null)
{
return (0.0f, null);
}
var measured = GetResultSize(result);
return (measured.Width, null);
}
Expand Down
Loading

0 comments on commit bd31b96

Please sign in to comment.