using Xui.Core.Canvas; using Xui.Core.Math2D; using Xui.Core.UI; using Xui.Core.UI.Input; using NFloat = System.Runtime.InteropServices.NFloat; public sealed class ClippedCard : TransformView { public ClippedCard() { Content = new Card(); Transform = AffineTransform.Translate((24, 32)) * AffineTransform.Scale(((NFloat)0.82, (NFloat)0.82)); } protected override void RenderTransformedContent(IContext context) { context.BeginPath(); context.RoundRect(Frame, 32); context.Clip(); base.RenderTransformedContent(context); } // Clip the interaction region too; a Canvas clip only changes pixels. public override bool HitTest(Point point) { if (!Frame.Contains(point)) return false; NFloat radius = NFloat.Min(32, NFloat.Min(Frame.Width, Frame.Height) / 2); NFloat x = NFloat.Clamp(point.X, Frame.X + radius, Frame.Right - radius); NFloat y = NFloat.Clamp(point.Y, Frame.Y + radius, Frame.Bottom - radius); var dx = point.X - x; var dy = point.Y - y; return dx * dx + dy * dy <= radius * radius; } private sealed class Card : View { private bool alternate; public override void OnPointerEvent(ref PointerEventRef e, EventPhase phase) { if (phase == EventPhase.Bubble && e.Type == PointerEventType.Down) { alternate = !alternate; InvalidateRender(); } } protected override void RenderCore(IContext context) { context.SetFill(new Color(alternate ? 0xD957A8FFu : 0x8538CEFFu)); context.FillRect(Frame); context.SetFill(Colors.White); context.SetFont(new Font(22, "Inter")); context.TextAlign = TextAlign.Center; context.TextBaseline = TextBaseline.Middle; context.FillText("Tap the transformed card", Frame.Center); } } }