Question by
Braveheart · Aug 24, 2015 at 12:59 AM ·
c#guiprogrammingtooltipguiwindow
Stop tooltip disappearing off screen
How can I have my tooltip popup adjust its position if it's drawning off screen?
Coding in C#.
if (hoveringOverPlace == true) { //Vector3 pos = hoveringPlace.transform.position;
Rect windowRect = new Rect(Input.mousePosition.x+20,
Screen.height-Input.mousePosition.y - 60, (Screen.width / 2) - 500, (Screen.height / 2) - 300);
windowRect = GUI.Window(0, windowRect, PlaceInfo, hoveringPlace.name);
}
}
void PlaceInfo(int windowID) {
GUI.Label(new Rect(10, 20, (Screen.width / 2) - 500, (Screen.height / 2) - 300), wrapString(labelText, 300));
}
Comment
You have to check if your rects for the tool tip is inside screen and how much to the rect is outside the screen adjust the rect values according to that.
Answer by Umresh · Aug 24, 2015 at 06:35 AM
Try this works only if tooltip disappears offscreen in horizontal outside screen is a bool
if (Input.mousePosition.x < Screen.width && Input.mousePosition.x > 0) {
windowRect = new Rect (Input.mousePosition.x,
Screen.height - Input.mousePosition.y - 60, (Screen.width / 2) - 500, (Screen.height / 2) - 300);
outsideScreen = false;
}
else if(Input.mousePosition.x >= Screen.width && !outsideScreen)
{
windowRect = new Rect(windowRect.x,
Screen.height-Input.mousePosition.y - 60, (Screen.width / 2) - 500, (Screen.height / 2) - 300);
outsideScreen = true;
}
else if(Input.mousePosition.x <= 0 && !outsideScreen)
{
windowRect = new Rect(windowRect.x - (windowRect.width),
Screen.height-Input.mousePosition.y - 60, (Screen.width / 2) - 500, (Screen.height / 2) - 300);
outsideScreen = true;
}
windowRect = GUI.Window (0, windowRect, PlaceInfo, "ToolTip");
}
Your answer
Follow this Question
Related Questions
C# Newbie Programming Questions 0 Answers
How to make a restart button pop up after character has died? 2 Answers
Unity Parsing Error CS8025 on Last Line? 2 Answers
Why does this C# doesnt Work? it seems to be right. 0 Answers
Camera Follow Problem 0 Answers