setPositionXY.m 904 B

1234567891011121314151617181920212223242526272829303132
  1. function setPositionXY(h, x, y, padding, max_height, units)
  2. % SETPOSITIONXY Set graphical object position by x, y extents
  3. % Input:
  4. % h = graphical object handle
  5. % x, y = 1x2 or 2x1 float, outer extent of the widget
  6. % padding = 1x2 or 2x1 float, internal padding
  7. if nargin < 4
  8. % TODO
  9. return;
  10. end
  11. left = min(x) + padding(1);
  12. bottom = min(y) + padding(2);
  13. width = abs(x(1) - x(2)) - padding(1)*2;
  14. height = abs(y(1) - y(2)) - padding(2)*2;
  15. set(h, 'Position', [left bottom width height]);
  16. if nargin >= 6
  17. % save Units
  18. old_units = get(h, 'Units');
  19. % restrict height
  20. set(h, 'Units', units);
  21. old_position = get(h, 'Position');
  22. if old_position(4) > max_height
  23. new_y = old_position(2) + (old_position(4) - max_height)/2;
  24. set(h, 'Position', [old_position(1) new_y old_position(3) max_height]);
  25. end
  26. % restore Units
  27. set(h, 'Units', old_units);
  28. end