72 private bool _disposed;
73 private float _transitionDurationSec = 0.3f;
74 private float? _holdDurationSec = 3f;
75 private float _phaseElapsedSec;
76 private long _lastAnimationTick;
77 private Vector2 _phaseStartPosition;
78 private Vector2 _phaseEndPosition;
79 private float _phaseStartOpacity;
80 private float _phaseEndOpacity;
98 Rectangle targetBounds,
100 string? nickname =
null)
104 targetBounds.Location,
107 ValidateBounds(targetBounds);
120 $
"{Nickname}.background")
138 .
SetFont(SKTypeface.Default, 17f, minSize: 11f)
139 .
SetColors(SKColors.White, SKColors.Transparent)
143 Label.HorizontalPadding = 12f;
144 Label.VerticalPadding = 8f;
148 keepCurrentOffset:
false,
149 explicitLocalOffsetPx: Vector2.Zero);
153 keepCurrentOffset:
false,
154 explicitLocalOffsetPx: Vector2.Zero);
177 string? nickname =
null)
232 get => _transitionDurationSec;
233 set => _transitionDurationSec = value >= 0f
235 :
throw new ArgumentOutOfRangeException(nameof(value));
244 get => _holdDurationSec;
245 set => _holdDurationSec = value is
null or >= 0f
247 :
throw new ArgumentOutOfRangeException(nameof(value));
309 ? GetSourcePosition()
322 ValidateBounds(targetBounds);
325 Background.ScreenBounds = targetBounds;
326 Label.ScreenBounds = targetBounds;
350 Background.ZOrder = zOrder;
351 Label.ZOrder = zOrder + 1;
358 if (_disposed || tick <= _lastAnimationTick)
361 float elapsedSec = HighResTimer.GetDuration(_lastAnimationTick, tick);
362 _lastAnimationTick = tick;
369 AdvanceTransition(elapsedSec, entering:
true);
373 _phaseElapsedSec += elapsedSec;
376 _phaseElapsedSec >= holdSec)
384 AdvanceTransition(elapsedSec, entering:
false);
406 _lastAnimationTick = HighResTimer.GetCurrentTick();
411 ? GetSourcePosition()
429 base.ProcessHidden();
435 base.OnPointerClick(args);
444 private void BeginPhase(
445 Vector2 startPosition,
450 _phaseElapsedSec = 0f;
451 _phaseStartPosition = startPosition;
452 _phaseEndPosition = endPosition;
453 _phaseStartOpacity = startOpacity;
454 _phaseEndOpacity = endOpacity;
460 private void AdvanceTransition(
float elapsedSec,
bool entering)
462 _phaseElapsedSec += elapsedSec;
468 Func<float, float> easing = EasingFunctions.From(
471 float eased = Math.Clamp(easing(progress), 0f, 1f);
481 + (_phaseEndOpacity - _phaseStartOpacity) * eased);
492 private void CompleteEntrance()
497 _phaseElapsedSec = 0f;
503 private void CompleteDismissal()
512 private Vector2 GetSourcePosition()
515 return new Vector2(explicitSource.X, explicitSource.Y);
521 ToastSlideOrigin.Top =>
new Vector2(
525 ToastSlideOrigin.Right =>
new Vector2(
529 ToastSlideOrigin.Bottom =>
new Vector2(
533 ToastSlideOrigin.Left =>
new Vector2(
537 _ =>
throw new ArgumentOutOfRangeException()
541 private float GetCurrentOpacity()
543 return Children.Count == 0
545 :
Children[0] is DirectDrawingBase drawing
550 private static Rectangle GetAnchoredBounds(
556 ArgumentNullException.ThrowIfNull(view);
558 if (size.Width <= 0 || size.Height <= 0)
559 throw new ArgumentOutOfRangeException(nameof(size));
562 throw new ArgumentOutOfRangeException(nameof(marginPx));
566 int x = anchor
switch
568 WidgetAnchor.TopLeft or WidgetAnchor.CenterLeft or WidgetAnchor.BottomLeft => viewport.Left + marginPx,
569 WidgetAnchor.TopCenter or WidgetAnchor.Center or WidgetAnchor.BottomCenter => viewport.Left +
570 (viewport.Width - size.Width) / 2,
572 size.Width - marginPx,
573 _ =>
throw new ArgumentOutOfRangeException(nameof(anchor), anchor,
null)
576 int y = anchor
switch
578 WidgetAnchor.TopLeft or WidgetAnchor.TopCenter or WidgetAnchor.TopRight => viewport.Top + marginPx,
579 WidgetAnchor.CenterLeft or WidgetAnchor.Center or WidgetAnchor.CenterRight => viewport.Top +
580 (viewport.Height - size.Height) / 2,
582 size.Height - marginPx,
583 _ =>
throw new ArgumentOutOfRangeException(nameof(anchor), anchor,
null)
593 private static void ValidateBounds(Rectangle bounds)
595 if (bounds.Width <= 0 || bounds.Height <= 0)
596 throw new ArgumentOutOfRangeException(
598 "Toast bounds must have a positive width and height.");
ReadOnlyCollection< IDirectCompositeChild > Children
Gets the children owned by the composite.
DirectComposite SetOpacity(float opacity)
Applies one opacity to every descendant.
DirectComposite SetIsVisible(bool visible)
Applies one visibility value to every descendant.
View? View
Gets the view shared by all children in view mode.
MovementController Movement
Gets the movement controller used to move the composite anchor.
Vector2 GetPosition()
Gets the current composite anchor.
virtual DirectComposite Add(IDirectCompositeChild child, bool keepCurrentOffset=true, Vector2? explicitLocalOffsetPx=null)
Adds a composite-compatible direct drawable as a child.
void SetPosition(Vector2 position)
Sets the composite anchor and repositions all children from their stored offsets.
Renders a configurable rectangle with support for fill, border, rounded corners, dash patterns,...
DirectRectangle SetFilled(bool isFilled)
Sets whether the rectangle interior is filled with the base color (or pattern).
DirectRectangle SetBorderColor(Color color)
Sets a distinct border (stroke) color, independent of the fill color.
StrokeAlign
Defines how the stroke (outline) is positioned relative to the rectangle's boundary.
DirectRectangle SetStrokeWidth(float width)
Sets the width (thickness) of the rectangle's stroke (outline) in pixels.
DirectRectangle SetCornerRadius(float radius)
Sets the radius for rounded corners in pixels.
DirectRectangle SetStrokeAlign(StrokeAlign align)
Sets how the rectangle's stroke is positioned relative to its bounds.
A retained-mode text drawable with wrapping, multi-line ( ) support, horizontal/vertical alignment,...
TextBlock SetFont(SKTypeface typeface, float size, float? minSize=null)
Sets the font face and size (and optional minimum size for auto-shrink).
TextBlock EnableWrapping(bool enable=true)
Enables or disables word wrapping when laying out paragraphs.
TextBlock SetAlignment(SKTextAlign h, VerticalAlign v)
Sets the horizontal and vertical alignment used when drawing the laid-out lines within the bounds.
VerticalAlign
Vertical alignment options for multi-line text within the control's bounds.
TextBlock SetColors(SKColor fg, SKColor bg)
Sets the foreground (text) and background colors using Skia colors.
TextBlock SetText(string text)
Sets the current text content and rebuilds layout as needed. If no reveal animation is active,...
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
Viewport Viewport
Gets the viewport that defines the screen-space rectangle, zoom level, and other rendering parameters...
Rectangle TargetRectPx
Screen-space rectangle (in SCREEN / RenderSurface pixels) where this view is drawn....
@ Rectangle
Particles are spawned uniformly within a rectangular area. This is the default distribution.
DirectDrawingMode
Specifies where direct drawing operations are applied within the rendering pipeline.
EasingKind
Enumeration of all supported easing functions for animation and movement interpolation....