- Home /
How to enable/disable individual toolbar items?
Normally I can set the GUI.enabled state to cause the controls to be drawn in a disabled state if needed.
But GUI.enabled = false will cause the entire GUILayout.Toolbar to show as disabled. How can I disable and enable individual items?
Cheers
Answer by yoyo · May 31, 2011 at 05:30 AM
GUILayout.Toolbar doesn't have an option to enable/disable individual items. If you're using images instead of text you could pass in a different image when a particular button is disabled.
But probably better to use GUILayout.BeginHorizontal instead, then insert buttons one by one with GUILayout.Button. Use the style parameter to control how they look, and ignore clicks on buttons you want disabled.
Thanks for your answer. That's what I thought, bummer. Cheers.
Used toolbar at first but with a little styling you can achieve a much better 'custom' look and improved functionality.
Example of my usage:
//Before with no custom functionality
//tabIndex = GUILayout.Toolbar(tabIndex, m_TabNames);
//After with total control
GUILayout.BeginHorizontal(GUILayout.$$anonymous$$inHeight(21));
{
GUI.enabled = ValidWaypoints.Length >= 2 && tabIndex != 0;
if(GUILayout.Button(TabSettings.tabNames[0], EditorStyles.$$anonymous$$iButtonLeft, GUILayout.ExpandHeight(true)))
{
tabIndex = 0;
}
GUI.enabled = ValidWaypoints.Length >= 2 && tabIndex != 1;
if(GUILayout.Button(TabSettings.tabNames[1], EditorStyles.$$anonymous$$iButton$$anonymous$$id, GUILayout.ExpandHeight(true)))
{
tabIndex = 1;
}
GUI.enabled = ValidWaypoints.Length >= 3 && tabIndex != 2;
if(GUILayout.Button(TabSettings.tabNames[2], EditorStyles.$$anonymous$$iButtonRight, GUILayout.ExpandHeight(true)))
{
tabIndex = 2;
}
GUI.enabled = enabled;
}
GUILayout.EndHorizontal();
Thanks yoyo!
Your answer
Follow this Question
Related Questions
Unselecting a toolbar 1 Answer
GUI Texture in toolbar (C#) 1 Answer
I dont see EasyRoads menu 1 Answer
Activating another scene's script? 1 Answer
Editor: Drawing outside the own window 0 Answers