As per title or do you need to do a mouse contains and display your own label?
Does anyone think it isn’t possible?
Its possible.
Instead of firing in strings / images to gadgets, you use a GUIContent - the gui content objects transfer the tooltip along the title of button or its image for you (I guess you might always have asked yourself why GUIContent is there if you can use string and image directly)
guicontent is capable of a few other things too
If you dont like GUIContent’s tooltip, you could always make a class inherit from GUITexture and in the OnMouseEnter function, make a custom tooltip pop up yourself
This worked nicely until I realised I can’t move the tooltip.
for example
if (GUI.Button (Rect (5,5,100, 100), GUIContent (“ButtonA”, “Button A tip”),myStyle))
{
//code here
}
GUI.Label (Rect (5,5,100, 100), GUI.tooltip,tooltipStyle);
if (GUI.Button (Rect (50,5,100, 100), GUIContent (“ButtonB”, “Button B tip”),myStyle))
{
//code here
}
GUI.Label (Rect (50,5,100, 100), GUI.tooltip,tooltipStyle);
Now tooltip B is fine but tooltip A shows in both places. How do I get around this? I want a number of tooltips and for them to move.
edit:
I ended up using the inputposition of the mouse for x and y. I wonder if there is a better way?
If you don’t like the built in tooltip behavior, you could roll something custom like this (untested):
string tooltip = "";
void Tooltip (Rect rect, string lastTooltip)
{
if (rect.Contains (Event.current.mousePosition))
{
tooltip = lastTooltip;
}
}
void TooltipLastLayout (string lastTooltip)
{
Tooltip (GUILayoutUtility.GetLastRect (), lastTooltip);
}
void OnGUI ()
{
tooltip = "Hover a label to see its tooltip";
GUILayout.BeginHorizontal ();
GUILayout.BeginVertical ();
GUILayout.Label ("Label 1");
TooltipLastLayout ("Label 1 tooltip");
GUILayout.Label ("Label 2");
TooltipLastLayout ("Label 2 tooltip");
GUILayout.Label ("Label 3");
TooltipLastLayout ("Label 3 tooltip");
GUILayout.EndVertical ();
GUILayout.Label (tooltip);
GUILayout.EndHorizontal ();
}