@@ -25,8 +25,19 @@ namespace CSharpMath.Avalonia {
2525using TextPainter = CSharpMath . SkiaSharp . TextPainter ;
2626namespace CSharpMath . Forms {
2727 [ Xamarin . Forms . ContentProperty ( nameof ( LaTeX ) ) ]
28+ #elif HAS_UNO || WINDOWS_UWP
29+ using XCanvas = SkiaSharp . SKCanvas ;
30+ using XCanvasColor = SkiaSharp . SKColor ;
31+ using XColor = Windows . UI . Color ;
32+ using XControl = Windows . UI . Xaml . Controls . Control ;
33+ using XInheritControl = SkiaSharp . Views . UWP . SKXamlCanvas ;
34+ using XProperty = Windows . UI . Xaml . DependencyProperty ;
35+ using MathPainter = CSharpMath . SkiaSharp . MathPainter ;
36+ using TextPainter = CSharpMath . SkiaSharp . TextPainter ;
37+ namespace CSharpMath . Uno {
38+ [ global ::Windows . UI . Xaml . Markup . ContentProperty ( Name = nameof ( LaTeX ) ) ]
2839#endif
29- public class BaseView < TPainter , TContent > : XInheritControl , ICSharpMathAPI < TContent , XColor >
40+ public partial class BaseView < TPainter , TContent > : XInheritControl , ICSharpMathAPI < TContent , XColor >
3041 where TPainter : Painter < XCanvas , TContent , XCanvasColor > , new ( ) where TContent : class {
3142 public TPainter Painter { get ; } = new TPainter ( ) ;
3243
@@ -158,9 +169,61 @@ protected sealed override void OnPaintSurface(global::SkiaSharp.Views.Forms.SKPa
158169 base . OnPaintSurface ( e ) ;
159170 e . Surface . Canvas . Clear ( ) ;
160171 var canvas = e . Surface . Canvas ;
172+ #elif HAS_UNO || WINDOWS_UWP
173+ @this. Invalidate ( ) ;
174+ }
175+ return XProperty . Register ( propertyName , typeof ( TValue ) , typeof ( TThis ) ,
176+ new Windows . UI . Xaml . PropertyMetadata ( defaultValue , ( d , e ) => PropertyChanged( ( TThis ) d, e . NewValue) ) ) ;
177+ }
178+ protected override global ::Windows . Foundation . Size MeasureOverride ( global ::Windows . Foundation . Size availableSize ) =>
179+ Painter . Measure ( ( float ) availableSize . Width ) is { } rect
180+ ? new global ::Windows . Foundation . Size ( rect . Width , rect . Height )
181+ : base . MeasureOverride ( availableSize ) ;
182+ struct ReadOnlyProperty < TThis , TValue > where TThis : BaseView < TPainter , TContent > {
183+ public ReadOnlyProperty ( string propertyName ,
184+ Func < TPainter , TValue > getter ) {
185+ Property = XProperty . Register ( propertyName , typeof ( TValue ) , typeof ( TThis ) , new Windows . UI . Xaml . PropertyMetadata ( getter ( staticPainter ) ) ) ;
186+ }
187+ public XProperty Property { get ; }
188+ public void SetValue ( TThis @this , TValue value ) => @this . SetValue ( Property , value ) ;
189+ }
190+ private protected static XCanvasColor XColorToXCanvasColor ( XColor color ) => new XCanvasColor ( color . R , color . G , color . B , color . A ) ;
191+ private protected static XColor XCanvasColorToXColor ( XCanvasColor color ) => XColor . FromArgb ( color . Alpha , color . Red , color . Green , color . Blue ) ;
192+ global ::SkiaSharp . SKPoint _origin ;
193+ //protected override void OnTouch(global::SkiaSharp.Views.Forms.SKTouchEventArgs e) {
194+ // if (e.InContact && EnablePanning) {
195+ // switch (e.ActionType) {
196+ // case global::SkiaSharp.Views.Forms.SKTouchAction.Pressed:
197+ // _origin = e.Location;
198+ // e.Handled = true;
199+ // break;
200+ // case global::SkiaSharp.Views.Forms.SKTouchAction.Moved:
201+ // var displacement = e.Location - _origin;
202+ // _origin = e.Location;
203+ // DisplacementX += displacement.X;
204+ // DisplacementY += displacement.Y;
205+ // e.Handled = true;
206+ // break;
207+ // case global::SkiaSharp.Views.Forms.SKTouchAction.Released:
208+ // _origin = e.Location;
209+ // e.Handled = true;
210+ // break;
211+ // case global::SkiaSharp.Views.Forms.SKTouchAction.Entered:
212+ // case global::SkiaSharp.Views.Forms.SKTouchAction.Cancelled:
213+ // case global::SkiaSharp.Views.Forms.SKTouchAction.Exited:
214+ // default:
215+ // break;
216+ // }
217+ // }
218+ // base.OnTouch(e);
219+ //}
220+ protected sealed override void OnPaintSurface ( global ::SkiaSharp . Views . UWP . SKPaintSurfaceEventArgs e ) {
221+ base . OnPaintSurface ( e ) ;
222+ e . Surface . Canvas . Clear ( ) ;
223+ var canvas = e . Surface . Canvas ;
161224#endif
162225 Painter . Draw ( canvas , TextAlignment , Padding , DisplacementX , DisplacementY ) ;
163- }
226+ }
164227 /// <summary>Requires touch events to be enabled in SkiaSharp/Xamarin.Forms</summary>
165228 public bool EnablePanning { get => ( bool ) GetValue ( DisablePanningProperty ) ; set => SetValue ( DisablePanningProperty , value ) ; }
166229 public static readonly XProperty DisablePanningProperty = CreateProperty < BaseView < TPainter , TContent > , bool > ( nameof ( EnablePanning ) , false , _ => false , ( _ , __ ) => { } ) ;
@@ -214,6 +277,6 @@ protected sealed override void OnPaintSurface(global::SkiaSharp.Views.Forms.SKPa
214277 private static readonly ReadOnlyProperty < BaseView < TPainter , TContent > , string ? > ErrorMessagePropertyKey = new ReadOnlyProperty < BaseView < TPainter , TContent > , string ? > ( nameof ( ErrorMessage ) , p => p . ErrorMessage ) ;
215278 public static readonly XProperty ErrorMessageProperty = ErrorMessagePropertyKey . Property ;
216279 }
217- public class MathView : BaseView < MathPainter , MathList > { }
218- public class TextView : BaseView < TextPainter , Rendering . Text . TextAtom > { }
280+ public partial class MathView : BaseView < MathPainter , MathList > { }
281+ public partial class TextView : BaseView < TextPainter , Rendering . Text . TextAtom > { }
219282}
0 commit comments