forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
LayoutCanvas.cs
47 lines (40 loc) · 1.29 KB
/
LayoutCanvas.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using ElmSharp;
using Tizen.UIExtensions.Common;
using Tizen.UIExtensions.ElmSharp;
using Rectangle = Microsoft.Maui.Graphics.Rectangle;
using Size = Microsoft.Maui.Graphics.Size;
using TSize = Tizen.UIExtensions.Common.Size;
namespace Microsoft.Maui
{
public class LayoutCanvas : Canvas, IMeasurable
{
Rectangle _arrangeCache;
IView _virtualView;
public LayoutCanvas(EvasObject parent, IView view) : base(parent)
{
_arrangeCache = default(Rectangle);
_virtualView = view;
LayoutUpdated += OnLayoutUpdated;
}
public TSize Measure(double availableWidth, double availableHeight)
{
return CrossPlatformMeasure?.Invoke(availableWidth.ToScaledDP(), availableHeight.ToScaledDP()).ToPixel() ?? new TSize(0, 0);
}
internal Func<double, double, Size>? CrossPlatformMeasure { get; set; }
internal Func<Rectangle, Size>? CrossPlatformArrange { get; set; }
protected void OnLayoutUpdated(object? sender, LayoutEventArgs e)
{
var nativeGeometry = Geometry.ToDP();
if (_arrangeCache == nativeGeometry)
return;
if (nativeGeometry.Width > 0 && nativeGeometry.Height > 0)
{
nativeGeometry.X = 0;
nativeGeometry.Y = 0;
CrossPlatformMeasure!(nativeGeometry.Width, nativeGeometry.Height);
CrossPlatformArrange!(nativeGeometry);
}
}
}
}