Skip to content

Commit b21c91c

Browse files
committed
Fix issues in Uno specific code
1 parent 4f971bb commit b21c91c

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

CSharpMath.Xaml/Views.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using CSharpMath.Rendering.FrontEnd;
55
using CSharpMath.Structures;
66
using Typography.OpenFont;
7+
using CSharpMathTextAlignment = CSharpMath.Rendering.FrontEnd.TextAlignment;
8+
using CSharpMathThickness = CSharpMath.Structures.Thickness;
79

810
// X stands for Xaml
911
#if Avalonia
@@ -198,18 +200,16 @@ protected override Windows.Foundation.Size MeasureOverride(Windows.Foundation.Si
198200
struct ReadOnlyProperty<TThis, TValue> where TThis : BaseView<TPainter, TContent> {
199201
public ReadOnlyProperty(string propertyName,
200202
Func<TPainter, TValue> getter) {
201-
Property = XProperty.RegisterDirect<TThis, TValue>(propertyName, b => getter(b.Painter), null, getter(staticPainter));
202-
_value = getter(staticPainter);
203+
Property = XProperty.Register(propertyName, typeof(TValue), typeof(TThis), new Windows.UI.Xaml.PropertyMetadata(getter(staticPainter)));
203204
}
204-
TValue _value;
205-
public global::Avalonia.DirectProperty<TThis, TValue> Property;
206-
public void SetValue(TThis @this, TValue value) => @this.SetAndRaise(Property, ref _value, value);
205+
public XProperty Property;
206+
public void SetValue(TThis @this, TValue value) => @this.SetValue(Property, value);
207207
}
208208
static XCanvasColor XColorToXCanvasColor(XColor color) => new XCanvasColor(color.R, color.G, color.B, color.A);
209209
static XColor XCanvasColorToXColor(XCanvasColor color) => XColor.FromArgb(color.Alpha, color.Red, color.Green, color.Blue);
210210
static CSharpMathThickness XThicknessToCSharpMathThickness(XThickness thickness) => new CSharpMathThickness((float)thickness.Left, (float)thickness.Top, (float)thickness.Right, (float)thickness.Bottom);
211211
static XThickness CSharpMathThicknessToXThickness(CSharpMathThickness thickness) => new XThickness(thickness.Left, thickness.Top, thickness.Right, thickness.Bottom);
212-
global::Avalonia.Point _origin;
212+
global::Windows.Foundation.Point _origin;
213213
private void OnPointerPressed(object sender, PointerRoutedEventArgs e) {
214214
var point = e.GetCurrentPoint(this);
215215
if (point.Properties.IsLeftButtonPressed && EnablePanning) {
@@ -219,7 +219,7 @@ private void OnPointerPressed(object sender, PointerRoutedEventArgs e) {
219219
private void OnPointerMoved(object sender, PointerRoutedEventArgs e) {
220220
var point = e.GetCurrentPoint(this);
221221
if (point.Properties.IsLeftButtonPressed && EnablePanning) {
222-
var displacement = point.Position - _origin;
222+
var displacement = new Windows.Foundation.Point(point.Position.X - _origin.X, point.Position.Y - _origin.Y);
223223
_origin = point.Position;
224224
DisplacementX += (float)displacement.X;
225225
DisplacementY += (float)displacement.Y;
@@ -247,7 +247,7 @@ protected override void OnPaintSurface(global::SkiaSharp.Views.UWP.SKPaintSurfac
247247

248248
static readonly System.Reflection.ParameterInfo[] drawMethodParams = typeof(TPainter)
249249
.GetMethod(nameof(Painter<XCanvas, TContent, XColor>.Draw),
250-
new[] { typeof(XCanvas), typeof(TextAlignment), typeof(Thickness), typeof(double), typeof(double) }).GetParameters();
250+
new[] { typeof(XCanvas), typeof(CSharpMathTextAlignment), typeof(CSharpMathThickness), typeof(float), typeof(float) }).GetParameters();
251251
static T? Nullable<T>(T value) where T : struct => new T?(value);
252252
public (XColor glyph, XColor textRun)? GlyphBoxColor { get => ((XColor glyph, XColor textRun)?)GetValue(GlyphBoxColorProperty); set => SetValue(GlyphBoxColorProperty, value); }
253253
public static readonly XProperty GlyphBoxColorProperty = CreateProperty<BaseView<TPainter, TContent>, (XColor glyph, XColor textRun)?>(nameof(GlyphBoxColor), false,
@@ -276,14 +276,14 @@ protected override void OnPaintSurface(global::SkiaSharp.Views.UWP.SKPaintSurfac
276276
public static readonly XProperty HighlightColorProperty = CreateProperty<BaseView<TPainter, TContent>, XColor>(nameof(HighlightColor), false, p => XCanvasColorToXColor(p.HighlightColor), (p, v) => p.HighlightColor = XColorToXCanvasColor(v));
277277
public XColor ErrorColor { get => (XColor)GetValue(ErrorColorProperty); set => SetValue(ErrorColorProperty, value); }
278278
public static readonly XProperty ErrorColorProperty = CreateProperty<BaseView<TPainter, TContent>, XColor>(nameof(ErrorColor), false, p => XCanvasColorToXColor(p.ErrorColor), (p, v) => p.ErrorColor = XColorToXCanvasColor(v));
279-
public TextAlignment TextAlignment { get => (TextAlignment)GetValue(TextAlignmentProperty); set => SetValue(TextAlignmentProperty, value); }
280-
public static readonly XProperty TextAlignmentProperty = CreateProperty<BaseView<TPainter, TContent>, TextAlignment>(nameof(Rendering.FrontEnd.TextAlignment), false, p => (TextAlignment)drawMethodParams[1].DefaultValue, (p, v) => { });
281-
public Thickness Padding { get => (Thickness)GetValue(PaddingProperty); set => SetValue(PaddingProperty, value); }
282-
public static readonly XProperty PaddingProperty = CreateProperty<BaseView<TPainter, TContent>, Thickness>(nameof(Padding), false, p => (Thickness)(drawMethodParams[2].DefaultValue ?? new Thickness()), (p, v) => { });
279+
public CSharpMathTextAlignment TextAlignment { get => (CSharpMathTextAlignment)GetValue(TextAlignmentProperty); set => SetValue(TextAlignmentProperty, value); }
280+
public static readonly XProperty TextAlignmentProperty = CreateProperty<BaseView<TPainter, TContent>, CSharpMathTextAlignment>(nameof(Rendering.FrontEnd.TextAlignment), false, p => (CSharpMathTextAlignment)drawMethodParams[1].DefaultValue, (p, v) => { });
281+
public CSharpMathThickness Padding { get => (CSharpMathThickness)GetValue(PaddingProperty); set => SetValue(PaddingProperty, value); }
282+
public static readonly XProperty PaddingProperty = CreateProperty<BaseView<TPainter, TContent>, CSharpMathThickness>(nameof(Padding), false, p => (CSharpMathThickness)(drawMethodParams[2].DefaultValue ?? new CSharpMathThickness()), (p, v) => { });
283283
public double DisplacementX { get => (float)GetValue(DisplacementXProperty); set => SetValue(DisplacementXProperty, value); }
284-
public static readonly XProperty DisplacementXProperty = CreateProperty<BaseView<TPainter, TContent>, double>(nameof(DisplacementX), false, p => (double)drawMethodParams[3].DefaultValue, (p, v) => { });
284+
public static readonly XProperty DisplacementXProperty = CreateProperty<BaseView<TPainter, TContent>, double>(nameof(DisplacementX), false, p => Convert.ToDouble(drawMethodParams[3].DefaultValue), (p, v) => { });
285285
public double DisplacementY { get => (float)GetValue(DisplacementYProperty); set => SetValue(DisplacementYProperty, value); }
286-
public static readonly XProperty DisplacementYProperty = CreateProperty<BaseView<TPainter, TContent>, double>(nameof(DisplacementY), false, p => (double)drawMethodParams[4].DefaultValue, (p, v) => { });
286+
public static readonly XProperty DisplacementYProperty = CreateProperty<BaseView<TPainter, TContent>, double>(nameof(DisplacementY), false, p => Convert.ToDouble(drawMethodParams[4].DefaultValue), (p, v) => { });
287287
public double Magnification { get => (float)GetValue(MagnificationProperty); set => SetValue(MagnificationProperty, value); }
288288
public static readonly XProperty MagnificationProperty = CreateProperty<BaseView<TPainter, TContent>, double>(nameof(Magnification), false, p => p.Magnification, (p, v) => p.Magnification = (float)v);
289289
public PaintStyle PaintStyle { get => (PaintStyle)GetValue(PaintStyleProperty); set => SetValue(PaintStyleProperty, value); }
@@ -294,6 +294,6 @@ protected override void OnPaintSurface(global::SkiaSharp.Views.UWP.SKPaintSurfac
294294
private static readonly ReadOnlyProperty<BaseView<TPainter, TContent>, string?> ErrorMessagePropertyKey = new ReadOnlyProperty<BaseView<TPainter, TContent>, string?>(nameof(ErrorMessage), p => p.ErrorMessage);
295295
public static readonly XProperty ErrorMessageProperty = ErrorMessagePropertyKey.Property;
296296
}
297-
public class MathView : BaseView<MathPainter, MathList> { }
298-
public class TextView : BaseView<TextPainter, Rendering.Text.TextAtom> { }
297+
public partial class MathView : BaseView<MathPainter, MathList> { }
298+
public partial class TextView : BaseView<TextPainter, Rendering.Text.TextAtom> { }
299299
}

0 commit comments

Comments
 (0)