Adjust Programmatic UI Layouts Interactively
You can obtain the new property value using dot notation and the property name. For
example, this command gets the BackgroundColor property value of object_handle
and stores it in the variable, bc.
bc = object_handle.BackgroundColor;
Sketch a Position Vector
rbbox is a useful function for setting positions. When you call it, you drag out a rubber
band box anywhere in the figure. You receive a position vector for that box when you
release the mouse button. Be aware that when rbbox executes,
- A figure window must have focus.
- The mouse cursor must be within the figure window.
- Your left mouse button must down.
Because of this behavior, you must call rbbox from a function or a script that waits for
you to press the mouse button. The returned position vector specifies the rectangle you
draw in figure units. The following function, called setpos, calls rbbox to specify a
position for a component. It returns the position vector you drag out and also places it on
the system clipboard:
function rect = setpos(object_handle)
% Use RBBOX to establish a position for a UI component.
% object_handle is a handle to a uicomponent that uses
% any Units. Internally, figure Units are used.
disp(['=== Drag out a Position for object ' inputname(1)])
waitforbuttonpress % So that rbbox does not return immediately
rect = rbbox; % User drags out a rectangle, releases button
% Pressing a key aborts rbbox, so check for null width & height
if rect(3) ~= 0 && rect(4) ~= 0
% Save and restore original units for object
myunits = object_handle.Units;
object_handle.Units = get(gcf,'Units');
object_handle.Position = rect;
object_handle.Units = myunits;
else
rect = [];
end
clipboard('copy', rect) % Place set string on system
% clipboard as well as returning it