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 MeterView : View { private NFloat value = (NFloat)0.6; public NFloat Value { get => value; set => SetViewRenderProperty(ref this.value, NFloat.Clamp(value, 0, 1)); } protected override Size MeasureCore(Size available, IMeasureContext context) => new(NFloat.Min(280, available.Width), NFloat.Min(120, available.Height)); protected override void RenderCore(IContext context) { context.SetFill(new Color(0xFAF7FFFF)); context.FillRect(Frame); NFloat width = NFloat.Max(0, Frame.Width - 48); var track = new Rect(Frame.X + 24, Frame.Center.Y, width, 16); context.SetFill(new Color(0xEADCF5FF)); context.FillRect(track); context.SetFill(new Color(0x8538CEFF)); context.FillRect(new Rect(track.X, track.Y, width * Value, track.Height)); context.SetFont(new Font(20, "Inter")); context.TextAlign = TextAlign.Center; context.TextBaseline = TextBaseline.Middle; context.FillText("Tap to add one tenth", (Frame.Center.X, Frame.Center.Y - 36)); } public override void OnPointerEvent(ref PointerEventRef e, EventPhase phase) { if (phase == EventPhase.Bubble && e.Type == PointerEventType.Down && e.State.Button == PointerButton.Left) Value = Value >= (NFloat)0.99 ? 0 : Value + (NFloat)0.1; } }