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);
112 Color.FromArgb(232, 35, 38, 45),
116 $
"{Nickname}.background")
129 .
SetFont(SKTypeface.Default, 17f, minSize: 11f)
130 .
SetColors(SKColors.White, SKColors.Transparent)
134 Label.HorizontalPadding = 12f;
135 Label.VerticalPadding = 8f;
139 keepCurrentOffset:
false,
140 explicitLocalOffsetPx: Vector2.Zero);
144 keepCurrentOffset:
false,
145 explicitLocalOffsetPx: Vector2.Zero);
168 string? nickname =
null)
172 GetAnchoredBounds(view, size, targetAnchor, marginPx),
219 get => _transitionDurationSec;
220 set => _transitionDurationSec = value >= 0f
222 :
throw new ArgumentOutOfRangeException(nameof(value));
231 get => _holdDurationSec;
232 set => _holdDurationSec = value is
null or >= 0f
234 :
throw new ArgumentOutOfRangeException(nameof(value));
295 ? GetSourcePosition()
308 ValidateBounds(targetBounds);
311 Background.ScreenBounds = targetBounds;
312 Label.ScreenBounds = targetBounds;
336 Background.ZOrder = zOrder;
337 Label.ZOrder = zOrder + 1;
344 if (_disposed || tick <= _lastAnimationTick)
347 float elapsedSec = HighResTimer.GetDuration(_lastAnimationTick, tick);
348 _lastAnimationTick = tick;
355 AdvanceTransition(elapsedSec, entering:
true);
359 _phaseElapsedSec += elapsedSec;
362 _phaseElapsedSec >= holdSec)
369 AdvanceTransition(elapsedSec, entering:
false);
391 _lastAnimationTick = HighResTimer.GetCurrentTick();
395 ? GetSourcePosition()
413 base.ProcessHidden();
419 base.OnPointerClick(args);
428 private void BeginPhase(
429 Vector2 startPosition,
434 _phaseElapsedSec = 0f;
435 _phaseStartPosition = startPosition;
436 _phaseEndPosition = endPosition;
437 _phaseStartOpacity = startOpacity;
438 _phaseEndOpacity = endOpacity;
444 private void AdvanceTransition(
float elapsedSec,
bool entering)
446 _phaseElapsedSec += elapsedSec;
452 Func<float, float> easing = EasingFunctions.From(
455 float eased = Math.Clamp(easing(progress), 0f, 1f);
464 + (_phaseEndOpacity - _phaseStartOpacity) * eased);
475 private void CompleteEntrance()
480 _phaseElapsedSec = 0f;
486 private void CompleteDismissal()
495 private Vector2 GetSourcePosition()
498 return new Vector2(explicitSource.X, explicitSource.Y);
504 ToastSlideOrigin.Top =>
new Vector2(
508 ToastSlideOrigin.Right =>
new Vector2(
512 ToastSlideOrigin.Bottom =>
new Vector2(
516 ToastSlideOrigin.Left =>
new Vector2(
520 _ =>
throw new ArgumentOutOfRangeException()
524 private float GetCurrentOpacity()
526 return Children.Count == 0
528 :
Children[0] is DirectDrawingBase drawing
533 private static Rectangle GetAnchoredBounds(
539 ArgumentNullException.ThrowIfNull(view);
541 if (size.Width <= 0 || size.Height <= 0)
542 throw new ArgumentOutOfRangeException(nameof(size));
545 throw new ArgumentOutOfRangeException(nameof(marginPx));
549 int x = anchor
switch
551 WidgetAnchor.TopLeft or WidgetAnchor.CenterLeft or WidgetAnchor.BottomLeft => viewport.Left + marginPx,
552 WidgetAnchor.TopCenter or WidgetAnchor.Center or WidgetAnchor.BottomCenter => viewport.Left + (viewport.Width - size.Width) / 2,
554 _ =>
throw new ArgumentOutOfRangeException(nameof(anchor), anchor,
null)
557 int y = anchor
switch
559 WidgetAnchor.TopLeft or WidgetAnchor.TopCenter or WidgetAnchor.TopRight => viewport.Top + marginPx,
560 WidgetAnchor.CenterLeft or WidgetAnchor.Center or WidgetAnchor.CenterRight => viewport.Top + (viewport.Height - size.Height) / 2,
562 _ =>
throw new ArgumentOutOfRangeException(nameof(anchor), anchor,
null)
565 return new Rectangle(x, y, size.Width, size.Height);
568 private static void ValidateBounds(Rectangle bounds)
570 if (bounds.Width <= 0 || bounds.Height <= 0)
571 throw new ArgumentOutOfRangeException(nameof(bounds),
"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....