namespace Terminal.Gui;
///
/// The Label displays text that describes the View next in the . When
/// Label
/// recieves a command it will pass it to the next in
/// .
///
///
///
/// 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, InvokeHotKeyOnNext);
TitleChanged += Label_TitleChanged;
MouseClick += Label_MouseClick;
}
// TODO: base raises Select, but we want to raise HotKey. This can be simplified?
private void Label_MouseClick (object sender, MouseEventArgs e)
{
if (!CanFocus)
{
e.Handled = InvokeCommand (Command.HotKey, ctx: new (Command.HotKey, key: null, data: this)) == true;
}
}
private void Label_TitleChanged (object sender, EventArgs e)
{
base.Text = e.CurrentValue;
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? InvokeHotKeyOnNext (CommandContext context)
{
if (RaiseHandlingHotKey () == true)
{
return true;
}
if (CanFocus)
{
SetFocus ();
return true;
}
int me = SuperView?.Subviews.IndexOf (this) ?? -1;
if (me != -1 && me < SuperView?.Subviews.Count - 1)
{
return SuperView?.Subviews [me + 1].InvokeCommand (Command.HotKey, context.Key, context.KeyBinding) == true;
}
return false;
}
///
bool IDesignable.EnableForDesign ()
{
Text = "_Label";
return true;
}
}