1 | classdef HBox < uiextras.Box |
---|
2 | %HBox Arrange elements in a single horizontal row |
---|
3 | % |
---|
4 | % obj = uiextras.HBox() creates a new horizontal box layout with |
---|
5 | % all parameters set to defaults. The output is a new layout object |
---|
6 | % that can be used as the parent for other user-interface components. |
---|
7 | % |
---|
8 | % obj = uiextras.HBox(param,value,...) also sets one or more |
---|
9 | % parameter values. |
---|
10 | % |
---|
11 | % See the <a href="matlab:doc uiextras.HBox">documentation</a> for more detail and the list of properties. |
---|
12 | % |
---|
13 | % Examples: |
---|
14 | % >> f = figure(); |
---|
15 | % >> b = uiextras.HBox( 'Parent', f ); |
---|
16 | % >> uicontrol( 'Parent', b, 'Background', 'r' ) |
---|
17 | % >> uicontrol( 'Parent', b, 'Background', 'b' ) |
---|
18 | % >> uicontrol( 'Parent', b, 'Background', 'g' ) |
---|
19 | % >> set( b, 'Sizes', [-1 100 -2], 'Spacing', 5 ); |
---|
20 | % |
---|
21 | % >> f = figure(); |
---|
22 | % >> b1 = uiextras.VBox( 'Parent', f ); |
---|
23 | % >> b2 = uiextras.HBox( 'Parent', b1, 'Padding', 5, 'Spacing', 5 ); |
---|
24 | % >> uicontrol( 'Style', 'frame', 'Parent', b1, 'Background', 'r' ) |
---|
25 | % >> uicontrol( 'Parent', b2, 'String', 'Button1' ) |
---|
26 | % >> uicontrol( 'Parent', b2, 'String', 'Button2' ) |
---|
27 | % >> set( b1, 'Sizes', [30 -1] ); |
---|
28 | % |
---|
29 | % See also: uiextras.VBox |
---|
30 | % uiextras.HBoxFlex |
---|
31 | % uiextras.Grid |
---|
32 | |
---|
33 | % Copyright 2009-2010 The MathWorks, Inc. |
---|
34 | % 1.1 |
---|
35 | % 2012/05/08 08:02:58 |
---|
36 | |
---|
37 | methods |
---|
38 | |
---|
39 | function obj = HBox( varargin ) |
---|
40 | %HBox Container with contents in a single horizontal row |
---|
41 | |
---|
42 | % First step is to create the parent class. We pass the |
---|
43 | % arguments (if any) just incase the parent needs setting |
---|
44 | obj@uiextras.Box( varargin{:} ); |
---|
45 | |
---|
46 | % Set user-supplied property values |
---|
47 | if nargin > 0 |
---|
48 | set( obj, varargin{:} ); |
---|
49 | end |
---|
50 | end % constructor |
---|
51 | |
---|
52 | end % public methods |
---|
53 | |
---|
54 | methods( Access = protected ) |
---|
55 | |
---|
56 | function [widths,heights] = redraw( obj ) |
---|
57 | %REDRAW Redraw container contents. |
---|
58 | |
---|
59 | % Get container width and height |
---|
60 | totalPosition = ceil( getpixelposition( obj.UIContainer ) ); |
---|
61 | totalWidth = totalPosition(3); |
---|
62 | totalHeight = totalPosition(4); |
---|
63 | |
---|
64 | % Get children |
---|
65 | children = obj.getValidChildren(); |
---|
66 | nChildren = numel( children ); |
---|
67 | |
---|
68 | % Get padding, spacing and sizes |
---|
69 | padding = obj.Padding; |
---|
70 | spacing = obj.Spacing; |
---|
71 | |
---|
72 | % Compute widths |
---|
73 | widths = uiextras.calculatePixelSizes( totalWidth, ... |
---|
74 | obj.Sizes, obj.MinimumSizes, padding, spacing ); |
---|
75 | |
---|
76 | % Compute heights |
---|
77 | heights = repmat( totalHeight - padding * 2, size( children ) ); |
---|
78 | heights = max( heights, 1 ); % minimum is 1 pixel |
---|
79 | |
---|
80 | % Compute and set new positions in pixels |
---|
81 | for ii = 1:nChildren |
---|
82 | child = children(ii); |
---|
83 | newPosition = [sum( widths(1:ii-1) ) + padding + spacing * (ii-1) + 1, ... |
---|
84 | padding + 1, ... |
---|
85 | widths(ii), ... |
---|
86 | heights(ii)]; |
---|
87 | obj.repositionChild( child, newPosition ) |
---|
88 | end |
---|
89 | end % redraw |
---|
90 | |
---|
91 | end % protected methods |
---|
92 | |
---|
93 | end % classdef |
---|