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
/// .
///
///
///
/// and are the same property. When is
/// set
/// is also set. When is set is also
/// set.
///
///
/// If is and the use clicks on the Label,
/// the will be invoked on the next in
/// ."
///
///
public class Label : View
{
///
public Label ()
{
Height = Dim.Auto (DimAutoStyle.Text);
Width = Dim.Auto (DimAutoStyle.Text);
// Things this view knows how to do
AddCommand (Command.HotKey, InvokeHotKeyOnNext);
TitleChanged += Label_TitleChanged;
MouseClick += Label_MouseClick;
}
private void Label_MouseClick (object sender, MouseEventEventArgs e)
{
if (!CanFocus)
{
e.Handled = InvokeCommand (Command.HotKey) == 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)
{
int me = SuperView?.Subviews.IndexOf (this) ?? -1;
if (me != -1 && me < SuperView?.Subviews.Count - 1)
{
SuperView?.Subviews [me + 1].InvokeCommand (Command.HotKey, context.Key, context.KeyBinding);
}
return true;
}
}