using System; 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 PaintView : View { private bool translucent = true; protected override void RenderCore(IContext context) { context.SetFill(new Color(0xFAF7FFFF)); context.FillRect(Frame); NFloat side = NFloat.Max(0, NFloat.Min(Frame.Width - 48, 320)); var area = new Rect(Frame.Center.X - side / 2, Frame.Center.Y - side / 2, side, side); context.Save(); try { context.BeginPath(); context.RoundRect(area, 28); context.Clip(); ReadOnlySpan stops = [new(0, 0x8538CEFF), new(1, 0xD957A8FF)]; context.SetFill(new LinearGradient(area.TopLeft, area.BottomRight, stops)); context.FillRect(area); context.GlobalAlpha = translucent ? (NFloat)0.35 : 1; context.SetFill(Colors.White); context.BeginPath(); context.Arc(area.Center, side / 3, 0, NFloat.Pi * 2); context.Fill(); } finally { context.Restore(); } context.SetFill(new Color(0x492571FF)); context.SetFont(new Font(18, "Inter")); context.TextAlign = TextAlign.Center; context.FillText("Tap to compare opacity", (Frame.Center.X, Frame.Y + 56)); } public override void OnPointerEvent(ref PointerEventRef e, EventPhase phase) { if (phase == EventPhase.Bubble && e.Type == PointerEventType.Down) { translucent = !translucent; InvalidateRender(); } } }