using UnityEngine.UI;
namespace UnityEngine.Rendering.UI
{
///
/// Base class for handling UI actions for widgets.
///
/// Base type for the field
public abstract class DebugUIHandlerField : DebugUIHandlerWidget
where T : DebugUI.Widget
{
/// Text displayed for the "next" button.
public Text nextButtonText;
/// Text displayed for the "previous" button.
public Text previousButtonText;
/// Name of the enum field.
public Text nameLabel;
/// Value of the enum field.
public Text valueLabel;
///
/// The field
///
internal protected T m_Field;
///
/// Sets the widget and updates the label
///
/// The
internal override void SetWidget(DebugUI.Widget widget)
{
base.SetWidget(widget);
m_Field = CastWidget();
nameLabel.text = m_Field.displayName;
UpdateValueLabel();
}
///
/// OnSelection implementation.
///
/// True if the selection wrapped around.
/// Previous widget.
/// State of the widget.
public override bool OnSelection(bool fromNext, DebugUIHandlerWidget previous)
{
if (nextButtonText != null)
nextButtonText.color = colorSelected;
if (previousButtonText != null)
previousButtonText.color = colorSelected;
nameLabel.color = colorSelected;
valueLabel.color = colorSelected;
return true;
}
///
/// OnDeselection implementation.
///
public override void OnDeselection()
{
if (nextButtonText != null)
nextButtonText.color = colorDefault;
if (previousButtonText != null)
previousButtonText.color = colorDefault;
nameLabel.color = colorDefault;
valueLabel.color = colorDefault;
}
///
/// OnAction implementation.
///
public override void OnAction()
{
OnIncrement(false);
}
///
/// Update the label of the widget.
///
public abstract void UpdateValueLabel();
///
/// Sets the label text
///
/// The text to set to the label
protected void SetLabelText(string text)
{
// The UI implementation is tight with space, so let's just truncate the string here if too long.
const int maxLength = 26;
if (text.Length > maxLength)
{
text = text.Substring(0, maxLength - 3) + "...";
}
valueLabel.text = text;
}
}
}