Download this file

96 lines (83 with data), 3.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
classdef HButtonBox < uix.ButtonBox
%uix.HButtonBox Horizontal button box
%
% b = uix.HButtonBox(p1,v1,p2,v2,...) constructs a horizontal button
% box and sets parameter p1 to value v1, etc.
%
% A horizontal button box lays out equally sized buttons from left to
% right.
%
% See also: uix.VButtonBox
% Copyright 2009-2016 The MathWorks, Inc.
% $Revision: 1480 $ $Date: 2017-02-15 16:56:13 +0100 (Wed, 15 Feb 2017) $
methods
function obj = HButtonBox( varargin )
%uix.HButtonBox Horizontal button box constructor
%
% b = uix.HButtonBox() constructs a horizontal button box.
%
% b = uix.HButtonBox(p1,v1,p2,v2,...) sets parameter p1 to
% value v1, etc.
% Set properties
try
uix.set( obj, varargin{:} )
catch e
delete( obj )
e.throwAsCaller()
end
end % constructor
end % structors
methods( Access = protected )
function redraw( obj )
% Compute positions
bounds = hgconvertunits( ancestor( obj, 'figure' ), ...
[0 0 1 1], 'normalized', 'pixels', obj );
buttonSize = obj.ButtonSize_;
padding = obj.Padding_;
spacing = obj.Spacing_;
c = numel( obj.Contents_ );
if 2 * padding + (c-1) * spacing + c * buttonSize(1) > bounds(3)
xSizes = uix.calcPixelSizes( bounds(3), -ones( [c 1] ), ...
ones( [c 1] ), padding, spacing ); % shrink to fit
else
xSizes = repmat( buttonSize(1), [c 1] );
end
switch obj.HorizontalAlignment
case 'left'
xPositions = [cumsum( [0; xSizes(1:c-1,:)] ) + ...
padding + spacing * transpose( 0:c-1 ) + 1, xSizes];
case 'center'
xPositions = [cumsum( [0; xSizes(1:c-1,:)] ) + ...
spacing * transpose( 0:c-1 ) + bounds(3) / 2 - ...
sum( xSizes ) / 2 - spacing * (c-1) / 2 + 1, ...
xSizes];
case 'right'
xPositions = [cumsum( [0; xSizes(1:c-1,:)] ) + ...
spacing * transpose( 0:c-1 ) + bounds(3) - ...
sum( xSizes ) - spacing * (c-1) - padding + 1, ...
xSizes];
end
if 2 * padding + buttonSize(2) > bounds(4)
ySizes = repmat( uix.calcPixelSizes( bounds(4), -1, 1, ...
padding, spacing ), [c 1] ); % shrink to fit
else
ySizes = repmat( buttonSize(2), [c 1] );
end
switch obj.VerticalAlignment
case 'top'
yPositions = [bounds(4) - ySizes - padding + 1, ySizes];
case 'middle'
yPositions = [(bounds(4) - ySizes) / 2 + 1, ySizes];
case 'bottom'
yPositions = [repmat( padding, [c 1] ) + 1, ySizes];
end
positions = [xPositions(:,1), yPositions(:,1), ...
xPositions(:,2), yPositions(:,2)];
% Set positions
children = obj.Contents_;
for ii = 1:numel( children )
uix.setPosition( children(ii), positions(ii,:), 'pixels' )
end
end % redraw
end % template methods
end % classdef