tooltips.m 989 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <lib/std.mi>
  2. Global Group tipGroup;
  3. Global Text tipText;
  4. System.onScriptLoaded() {
  5. tipGroup = getScriptGroup();
  6. tipText = tipGroup.getObject("tooltip.text");
  7. }
  8. // When text is changed, resize the group accordingly and make sure it's fully visible
  9. tipText.onTextChanged(String newtext) {
  10. int x = getMousePosX();
  11. int y = getMousePosY()-tipGroup.getHeight(); // move above mouse by default
  12. int vpleft = getViewportLeftFromPoint(x, y);
  13. int vptop = getViewportTopFromPoint(x, y);
  14. int vpright = vpleft+getViewportWidthFromPoint(x, y);
  15. int vpbottom = vptop+getViewportHeightFromPoint(x, y);
  16. int w = getAutoWidth()+20;
  17. int h = tipGroup.getHeight();
  18. if (x + w > vpright) x = vpright - w;
  19. if (x < vpleft) x = vpleft;
  20. if (x + w > vpright) { w = vpright-vpleft-64; x = 32; }
  21. if (y + h > vpbottom) y = vpbottom - h;
  22. if (y < vptop) y = vptop + 32; // avoid mouse
  23. if (y + h > vpbottom) { h = vpbottom-vptop-64; y = 32; }
  24. tipGroup.resize(x, y, w, h);
  25. }