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 Example1 : View { private bool alternate; protected override void RenderCore(IContext context) { context.Save(); try { // Frame is in the parent's coordinate space. Draw from our own origin. context.Translate((Frame.X, Frame.Y)); NFloat width = Frame.Width; NFloat height = Frame.Height; context.SetFill(new Color(0xFAF7FFFF)); context.FillRect(new Rect(0, 0, width, height)); context.SetFill(new Color(0x292535FF)); context.SetFont(new Font(24, "Inter")); context.TextAlign = TextAlign.Center; context.TextBaseline = TextBaseline.Middle; context.FillText("Hello, Canvas!", (width / 2, height / 6)); // Fill a rectangle, then outline it with a different paint. context.SetFill(new Color(alternate ? 0xD957A8FFu : 0x8538CEFFu)); var rectangle = new Rect(width / 5, height / 3, width * 3 / 5, height / 5); context.FillRect(rectangle); context.SetStroke(new Color(0x492571FF)); context.LineWidth = 3; context.StrokeRect(rectangle); // A circle is a path. BeginPath keeps it separate from earlier paths. context.BeginPath(); context.Arc((width / 2, height * 2 / 3), 38, 0, NFloat.Pi * 2); context.SetFill(new Color(0xD9B6F4FF)); context.Fill(); context.SetFill(new Color(0x655572FF)); context.SetFont(new Font(14, "Inter")); context.FillText("Click or touch to change the color", (width / 2, height * 5 / 6)); } finally { context.Restore(); } } public override void OnPointerEvent(ref PointerEventRef e, EventPhase phase) { // A small interaction to distinguish the live view from its SVG preview. if (phase == EventPhase.Bubble && e.Type == PointerEventType.Down) { alternate = !alternate; InvalidateRender(); } } }