Browse Source

Adjust command button width based on name length

master
chrisgregan 11 years ago
parent
commit
4edcf396a4
  1. 74
      Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs
  2. 12
      Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs

74
Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs

@ -36,80 +36,6 @@ namespace Fungus.Script
return null;
}
public virtual void DrawCommandRowGUI()
{
FungusCommand t = target as FungusCommand;
if (t == null)
{
return;
}
FungusScript fungusScript = t.GetFungusScript();
GUILayout.BeginHorizontal();
bool error = false;
string summary = t.GetSummary().Replace("\n", "").Replace("\r", "");
if (summary.Length > 80)
{
summary = summary.Substring(0, 80) + "...";
}
if (summary.StartsWith("Error:"))
{
error = true;
}
if (!t.enabled)
{
GUI.backgroundColor = Color.grey;
}
else if (error)
{
GUI.backgroundColor = Color.red;
}
else if (fungusScript.selectedCommand == t)
{
GUI.backgroundColor = Color.yellow;
}
CommandInfoAttribute commandInfoAttr = FungusCommandEditor.GetCommandInfo(t.GetType());
if (commandInfoAttr == null)
{
return;
}
string commandName = commandInfoAttr.CommandName;
if (GUILayout.Button(commandName, EditorStyles.miniButton, GUILayout.MinWidth(80)))
{
fungusScript.selectedCommand = t;
GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus)
}
GUI.backgroundColor = Color.white;
GUIStyle labelStyle = new GUIStyle(EditorStyles.whiteMiniLabel);
labelStyle.wordWrap = true;
if (!t.enabled)
{
labelStyle.normal.textColor = Color.grey;
}
else if (error)
{
labelStyle.normal.textColor = Color.red;
}
GUILayout.Label(summary, labelStyle);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
if (Event.current.type == EventType.Repaint &&
t.IsExecuting())
{
Rect rect = GUILayoutUtility.GetLastRect();
GLDraw.DrawBox(rect, Color.green, 1.5f);
}
}
public virtual void DrawCommandInspectorGUI()
{
FungusCommand t = target as FungusCommand;

12
Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs

@ -121,17 +121,19 @@ namespace Fungus.Script
GUI.backgroundColor = commandInfoAttr.ButtonColor;
}
string commandName = commandInfoAttr.CommandName;
GUIStyle commandStyle = new GUIStyle(GUI.skin.box);
float buttonWidth = Mathf.Max(commandStyle.CalcSize(new GUIContent(commandName)).x, 80f);
Rect buttonRect = position;
buttonRect.width = 80;
buttonRect.width = buttonWidth;
buttonRect.y -= 2;
buttonRect.height += 5;
Rect summaryRect = position;
summaryRect.x += 85;
summaryRect.width -= 85;
summaryRect.x += buttonWidth + 5;
summaryRect.width -= (buttonWidth + 5);
string commandName = commandInfoAttr.CommandName;
GUIStyle commandStyle = new GUIStyle(GUI.skin.box);
if (GUI.Button(buttonRect, commandName, commandStyle))
{
fungusScript.selectedCommand = command;

Loading…
Cancel
Save