namespace Terminal.Gui.Views; /// /// Displays text that describes the View next in the . When /// the user presses a hotkey that matches the of the Label, the next in /// will be activated. /// /// /// /// Title and Text are the same property. When Title is set Text s also set. When Text is set Title is also set. /// /// /// If is and the use clicks on the Label, /// the will be invoked on the next in /// . /// /// public class Label : View, IDesignable { /// public Label () { Height = Dim.Auto (DimAutoStyle.Text); Width = Dim.Auto (DimAutoStyle.Text); // On HoKey, pass it to the next view AddCommand (Command.HotKey, InvokeHotKeyOnNextPeer!); TitleChanged += Label_TitleChanged; } private void Label_TitleChanged (object? sender, EventArgs e) { base.Text = e.Value; TextFormatter.HotKeySpecifier = HotKeySpecifier; } /// public override string Text { get => Title; set => base.Text = Title = value; } /// public override Rune HotKeySpecifier { get => base.HotKeySpecifier; set => TextFormatter.HotKeySpecifier = base.HotKeySpecifier = value; } private bool? InvokeHotKeyOnNextPeer (ICommandContext commandContext) { if (RaiseHandlingHotKey (commandContext) == true) { return true; } if (CanFocus) { SetFocus (); // Always return true on hotkey, even if SetFocus fails because // hotkeys are always handled by the View (unless RaiseHandlingHotKey cancels). // This is the same behavior as the base (View). return true; } if (HotKey.IsValid) { // If the Label has a hotkey, we need to find the next view in the subview list int me = SuperView?.SubViews.IndexOf (this) ?? -1; if (me != -1 && me < SuperView?.SubViews.Count - 1) { return SuperView?.SubViews.ElementAt (me + 1).InvokeCommand (Command.HotKey) == true; } } return false; } /// protected override bool OnSelecting (CommandEventArgs args) { // If Label can't focus and is clicked, invoke HotKey on next peer if (!CanFocus) { return InvokeCommand (Command.HotKey, args.Context) == true; } return base.OnSelecting (args); } /// bool IDesignable.EnableForDesign () { Text = "_Label"; return true; } }