using Xui.Core.Canvas; using Xui.Core.UI; using Xui.Core.UI.Input; public sealed class NameForm : VerticalStack { private readonly TextBox name; private readonly Label greeting; private readonly Label count; public NameForm() { Margin = 24; Add(new Label { Text = "What should we call you?", FontSize = 22, Margin = (0, 0, 0, 20) }); name = new TextBox { Text = "Gigi", FontSize = 20, MinimumHeight = 52, MaximumHeight = 52, InputOptions = new(ContentType: TextInputContentType.Name, ReturnAction: TextInputAction.Done), Margin = (0, 0, 0, 24) }; greeting = new Label { FontSize = 22, TextColor = new Color(0x8538CEFF), Margin = (0, 0, 0, 12) }; count = new Label { FontSize = 14, TextColor = new Color(0x655572FF) }; Add(name); Add(greeting); Add(count); UpdateGreeting(); } protected override void OnActivate() { base.OnActivate(); name.Editor.Changed += OnEdited; UpdateGreeting(); } protected override void OnDeactivate() { name.Editor.Changed -= OnEdited; base.OnDeactivate(); } private void OnEdited(TextEditingChange change) { if ((change & TextEditingChange.Text) != 0) UpdateGreeting(); } private void UpdateGreeting() { greeting.Text = string.IsNullOrWhiteSpace(name.Text) ? "A name makes this yours." : $"Hello, {name.Text}!"; count.Text = $"{name.Text.Length} UTF-16 code units"; } }