using Xui.Core.Abstract.Events; using Xui.Core.Canvas; using Xui.Core.UI; using Xui.Core.UI.Input; public sealed class KeyboardPad : View { private int count; public override bool Focusable => true; public override void OnPointerEvent(ref PointerEventRef e, EventPhase phase) { if (phase == EventPhase.Bubble && e.Type == PointerEventType.Down) Focus(); } public override void OnKeyDown(ref KeyEventRef e) { if (e.Key == VirtualKey.Right) count++; else if (e.Key == VirtualKey.Left) count--; else if (e.Key == VirtualKey.Escape) { Blur(); e.Handled = true; return; } else return; e.Handled = true; InvalidateRender(); } protected override void OnFocus() => InvalidateRender(); protected override void OnBlur() => InvalidateRender(); protected override void OnDeactivate() { Blur(); base.OnDeactivate(); } protected override void RenderCore(IContext context) { context.Save(); try { context.SetFill(new Color(IsFocused ? 0xEEE2FAFFu : 0xFAF7FFFFu)); context.FillRect(Frame); if (IsFocused) { context.SetStroke(new Color(0x8538CEFF)); context.LineWidth = 4; context.StrokeRect(new(Frame.X + 4, Frame.Y + 4, Frame.Width - 8, Frame.Height - 8)); } context.SetFill(new Color(0x492571FF)); context.SetFont(new Font(48, "Inter")); context.TextAlign = TextAlign.Center; context.TextBaseline = TextBaseline.Middle; context.FillText(count.ToString(), (Frame.X + Frame.Width / 2, Frame.Y + Frame.Height / 2)); context.SetFont(new Font(15, "Inter")); context.FillText(IsFocused ? "Left / Right to change; Esc to leave" : "Click here or press Tab to focus", (Frame.X + Frame.Width / 2, Frame.Y + Frame.Height / 2 + 72)); } finally { context.Restore(); } } }