Class Canvas
Optimized DrawnView having only one child inside Content property. Can autosize to to children size. For all drawn app put this directly inside the ContentPage as root view. If you put this inside some Maui control like Grid whatever expect more GC collections during animations making them somewhat less fluid.
[ContentProperty("Content")]
public class Canvas : DrawnView, INotifyPropertyChanged, IEffectControlProvider, IToolTipElement, IContextFlyoutElement, IAnimatable, IViewController, IVisualElementController, IElementController, IGestureController, IGestureRecognizers, IPropertyMapperView, IHotReloadableView, IReplaceableView, ILayout, ILayoutController, IContentView, IView, IElement, ITransform, IPadding, ICrossPlatformLayout, IDrawnBase, IDisposable, ICanBeUpdatedWithContext, ICanBeUpdated, IAnimatorsManager, IVisualTreeElement, IDisposeManager, IContainer, IList<IView>, ICollection<IView>, IEnumerable<IView>, IEnumerable, IGestureListener
- Inheritance
-
Canvas
- Implements
-
IGestureListener
- Inherited Members
- Extension Methods
Constructors
Canvas()
public Canvas()
Fields
ContentProperty
public static readonly BindableProperty ContentProperty
Field Value
Context
protected DrawingContext Context
Field Value
GesturesDebugColorProperty
public static readonly BindableProperty GesturesDebugColorProperty
Field Value
GesturesProperty
public static readonly BindableProperty GesturesProperty
Field Value
LineBreaks
protected List<int> LineBreaks
Field Value
ReserveSpaceAroundProperty
public static readonly BindableProperty ReserveSpaceAroundProperty
Field Value
Properties
AttachedTouchEffect
protected TouchEffect AttachedTouchEffect { get; set; }
Property Value
- TouchEffect
Content
public ISkiaControl Content { get; set; }
Property Value
ContentSize
public ScaledSize ContentSize { get; protected set; }
Property Value
DebugPointer
protected SkiaSvg DebugPointer { get; set; }
Property Value
DelayNanosBetweenGC
public static long DelayNanosBetweenGC { get; set; }
Property Value
Gestures
public GesturesMode Gestures { get; set; }
Property Value
GesturesDebugColor
public Color GesturesDebugColor { get; set; }
Property Value
HadInput
Have consumed input in previous or current pass. To notify them about UP (release) even if they don't get it via touch.
public Dictionary<Guid, ISkiaGestureListener> HadInput { get; }
Property Value
HasHover
Exchange point to set itsself or read who has hover
public SkiaControl HasHover { get; set; }
Property Value
ReceivedInput
Got input during current pass
public HashSet<ISkiaGestureListener> ReceivedInput { get; }
Property Value
ReserveSpaceAround
public Thickness ReserveSpaceAround { get; set; }
Property Value
TimeLastGC
public static long TimeLastGC { get; set; }
Property Value
Methods
AdaptHeightContraintToContentRequest(float, ScaledSize, double)
public float AdaptHeightContraintToContentRequest(float heightConstraintUnits, ScaledSize measuredContent, double sideConstraintsUnits)
Parameters
heightConstraintUnitsfloatmeasuredContentScaledSizesideConstraintsUnitsdouble
Returns
AdaptHeightContraintToRequest(double)
public float AdaptHeightContraintToRequest(double heightConstraint)
Parameters
heightConstraintdouble
Returns
AdaptSizeRequestToContent(double, double)
In UNITS
protected Size AdaptSizeRequestToContent(double widthRequest, double heightRequest)
Parameters
Returns
AdaptSizeToContentIfNeeded(double, double, bool)
protected Size AdaptSizeToContentIfNeeded(double widthConstraint, double heightConstraint, bool force = false)
Parameters
Returns
AdaptWidthContraintToContentRequest(float, ScaledSize, double)
public float AdaptWidthContraintToContentRequest(float widthConstraintUnits, ScaledSize measuredContent, double sideConstraintsUnits)
Parameters
widthConstraintUnitsfloatmeasuredContentScaledSizesideConstraintsUnitsdouble
Returns
AdaptWidthContraintToRequest(double)
public float AdaptWidthContraintToRequest(double widthConstraint)
Parameters
widthConstraintdouble
Returns
ArrangeOverride(Rect)
We need this mainly to autosize inside grid cells This is also called when parent visibilty changes
protected override Size ArrangeOverride(Rect bounds)
Parameters
boundsRect
Returns
BreakLine()
public void BreakLine()
CollectGarbage(long)
public static void CollectGarbage(long timeNanos)
Parameters
timeNanoslong
CreateDebugPointer()
protected virtual SkiaSvg CreateDebugPointer()
Returns
DetachGestures()
protected virtual void DetachGestures()
DisableUpdates()
Disable invalidating and drawing on the canvas
public virtual void DisableUpdates()
Draw(DrawingContext)
protected override void Draw(DrawingContext context)
Parameters
contextDrawingContext
DumpDebug()
public void DumpDebug()
EnableUpdates()
Enable canvas rendering itsself
public virtual void EnableUpdates()
FindViewCoordinatesRecursive(SkiaControl, SkiaControl, SKPoint)
protected virtual SKPoint? FindViewCoordinatesRecursive(SkiaControl current, SkiaControl target, SKPoint pointInCurrent)
Parameters
currentSkiaControltargetSkiaControlpointInCurrentSKPoint
Returns
GetGesturePositionInsideControl(SkiaControl, SKPoint)
Returns the point in the local coordinate system of the view (relative to its Top/Left). This works for any view on the canvas, even if it is not a direct child of this control. It recursively traverses the visual tree to find the view and calculates the coordinates taking into account all transforms and scroll offsets along the path. Returns points (DIPs).
public virtual SKPoint GetGesturePositionInsideControl(SkiaControl view, SKPoint screenPointPixels)
Parameters
viewSkiaControlscreenPointPixelsSKPoint
Returns
GetMeasuringRectForChildren(float, float, float)
All in in UNITS, OUT in PIXELS
public SKRect GetMeasuringRectForChildren(float widthConstraint, float heightConstraint, float scale)
Parameters
Returns
Invalidate()
Makes the control dirty, in need to be remeasured and rendered but this doesn't call Update, it's up yo you
public override void Invalidate()
InvalidateMeasure()
Marks the current measure of an element as invalidated.
protected override void InvalidateMeasure()
IsSavedGesture(TouchActionResult)
Define if consuming this gesture will register child inside HadInput
protected bool IsSavedGesture(TouchActionResult type)
Parameters
typeTouchActionResult
Returns
LayoutVisibilityChanged()
public virtual void LayoutVisibilityChanged()
Measure(float, float)
public override ScaledSize Measure(float widthConstraintPts, float heightConstraintPts)
Parameters
Returns
MeasureChild(SkiaControl, double, double, double)
PIXELS
protected ScaledSize MeasureChild(SkiaControl child, double availableWidth, double availableHeight, double scale)
Parameters
childSkiaControlavailableWidthdoubleavailableHeightdoublescaledouble
Returns
MeasureOverride(double, double)
Allows subclasses to implement custom Measure logic during a controls measure pass.
protected override Size MeasureOverride(double widthConstraint, double heightConstraint)
Parameters
widthConstraintdoubleThe width constraint to request.
heightConstraintdoubleThe height constraint to request.
Returns
- Size
The requested size that an element wants in order to be displayed on the device.
OnChildAdded(SkiaControl)
protected override void OnChildAdded(SkiaControl child)
Parameters
childSkiaControl
OnDestroyingVew()
protected override void OnDestroyingVew()
OnDisposing()
public override void OnDisposing()
OnGestureEvent(TouchActionType, TouchActionEventArgs, TouchActionResult)
IGestureListener implementation
public virtual void OnGestureEvent(TouchActionType type, TouchActionEventArgs args1, TouchActionResult touchAction)
Parameters
typeTouchActionTypeargs1TouchActionEventArgstouchActionTouchActionResult
OnGesturesAttachChanged()
protected virtual void OnGesturesAttachChanged()
OnHandlerChanged()
When overridden in a derived class, should raise the HandlerChanged event.
protected override void OnHandlerChanged()
Remarks
It is the implementor's responsibility to raise the HandlerChanged event.
OnHandlerChanging(HandlerChangingEventArgs)
When overridden in a derived class, should raise the HandlerChanging event.
protected override void OnHandlerChanging(HandlerChangingEventArgs args)
Parameters
argsHandlerChangingEventArgsProvides data for the HandlerChanging event.
Remarks
It is the implementor's responsibility to raise the HandlerChanging event.
OnParentChanged()
When overridden in a derived class, should raise the ParentChanged event.
protected override void OnParentChanged()
Remarks
It is the implementor's responsibility to raise the ParentChanged event.
OnPropertyChanged(string)
Method that is called when a bound property is changed.
protected override void OnPropertyChanged(string propertyName = null)
Parameters
propertyNamestringThe name of the bound property that changed.
OnSizeChanged()
protected override void OnSizeChanged()
PlayRippleAnimation(Color, double, double, bool)
public void PlayRippleAnimation(Color color, double x, double y, bool removePrevious = true)
Parameters
PlayShimmerAnimation(Color, float, float, int, bool)
public void PlayShimmerAnimation(Color color, float shimmerWidth, float shimmerAngle, int speedMs = 1000, bool removePrevious = false)
Parameters
ProcessGestures(SkiaGesturesParameters)
protected virtual void ProcessGestures(SkiaGesturesParameters args)
Parameters
SetChildren(IEnumerable<SkiaControl>)
public override void SetChildren(IEnumerable<SkiaControl> views)
Parameters
viewsIEnumerable<SkiaControl>
SetContent(SkiaControl)
Use Content property for direct access
protected virtual void SetContent(SkiaControl view)
Parameters
viewSkiaControl
SignalInput(ISkiaGestureListener, TouchActionResult)
Gets signal from a listener that in has processed gestures. Return false if should not process gestures.
public bool SignalInput(ISkiaGestureListener listener, TouchActionResult gestureType)
Parameters
listenerISkiaGestureListenergestureTypeTouchActionResult
Returns
Events
Tapped
public event EventHandler Tapped