OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ | 5 #ifndef UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ |
6 #define UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ | 6 #define UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ |
7 | 7 |
8 #include <map> | |
9 | |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
10 #include "ui/gfx/insets.h" | 12 #include "ui/gfx/insets.h" |
11 #include "ui/views/layout/layout_manager.h" | 13 #include "ui/views/layout/layout_manager.h" |
12 | 14 |
13 namespace gfx { | 15 namespace gfx { |
14 class Rect; | 16 class Rect; |
15 class Size; | 17 class Size; |
16 } | 18 } |
17 | 19 |
(...skipping 13 matching lines...) Expand all Loading... | |
31 kVertical, | 33 kVertical, |
32 }; | 34 }; |
33 | 35 |
34 // This specifies where along the main axis the children should be laid out. | 36 // This specifies where along the main axis the children should be laid out. |
35 // e.g. a horizontal layout of MAIN_AXIS_ALIGNMENT_END will result in the | 37 // e.g. a horizontal layout of MAIN_AXIS_ALIGNMENT_END will result in the |
36 // child views being right-aligned. | 38 // child views being right-aligned. |
37 enum MainAxisAlignment { | 39 enum MainAxisAlignment { |
38 MAIN_AXIS_ALIGNMENT_START, | 40 MAIN_AXIS_ALIGNMENT_START, |
39 MAIN_AXIS_ALIGNMENT_CENTER, | 41 MAIN_AXIS_ALIGNMENT_CENTER, |
40 MAIN_AXIS_ALIGNMENT_END, | 42 MAIN_AXIS_ALIGNMENT_END, |
41 | |
42 // This distributes extra space among the child views. This increases the | |
43 // size of child views along the main axis rather than the space between | |
44 // them. | |
45 MAIN_AXIS_ALIGNMENT_FILL, | |
46 // TODO(calamity): Add MAIN_AXIS_ALIGNMENT_JUSTIFY which spreads blank space | 43 // TODO(calamity): Add MAIN_AXIS_ALIGNMENT_JUSTIFY which spreads blank space |
47 // in-between the child views. | 44 // in-between the child views. |
48 }; | 45 }; |
49 | 46 |
50 // This specifies where along the cross axis the children should be laid out. | 47 // This specifies where along the cross axis the children should be laid out. |
51 // e.g. a horizontal layout of CROSS_AXIS_ALIGNMENT_END will result in the | 48 // e.g. a horizontal layout of CROSS_AXIS_ALIGNMENT_END will result in the |
52 // child views being bottom-aligned. | 49 // child views being bottom-aligned. |
53 enum CrossAxisAlignment { | 50 enum CrossAxisAlignment { |
54 // This causes the child view to stretch to fit the host in the cross axis. | 51 // This causes the child view to stretch to fit the host in the cross axis. |
55 CROSS_AXIS_ALIGNMENT_STRETCH, | 52 CROSS_AXIS_ALIGNMENT_STRETCH, |
(...skipping 17 matching lines...) Expand all Loading... | |
73 } | 70 } |
74 | 71 |
75 void set_cross_axis_alignment(CrossAxisAlignment cross_axis_alignment) { | 72 void set_cross_axis_alignment(CrossAxisAlignment cross_axis_alignment) { |
76 cross_axis_alignment_ = cross_axis_alignment; | 73 cross_axis_alignment_ = cross_axis_alignment; |
77 } | 74 } |
78 | 75 |
79 void set_inside_border_insets(const gfx::Insets& insets) { | 76 void set_inside_border_insets(const gfx::Insets& insets) { |
80 inside_border_insets_ = insets; | 77 inside_border_insets_ = insets; |
81 } | 78 } |
82 | 79 |
80 // Sets the flex weight for the view at |index|. Using the preferred size as | |
81 // the basis, free space along the main axis is distributed to views in the | |
82 // ratio of their flex weights. Similarly, if the views will overflow the | |
83 // parent, space is subtracted in these ratios. | |
84 // | |
85 // A flex of 0 means this view is not resized. Flex values must not be | |
86 // negative. | |
87 // Flex weights are set for the index and will not rearrange when the host's | |
88 // views do. | |
89 void SetFlexForViewAt(int index, int flex); | |
sky
2014/07/18 15:54:00
Using indices like this is fragile and I suspect p
calamity
2014/07/22 05:35:15
Done.
| |
90 | |
91 // Clears the flex for the view at |index|, causing it to use the default | |
92 // flex. | |
93 void ClearFlexForViewAt(int index); | |
94 | |
95 // Sets the flex for views to use when none is specified. | |
96 void SetDefaultFlex(int default_flex); | |
97 | |
83 // Overridden from views::LayoutManager: | 98 // Overridden from views::LayoutManager: |
84 virtual void Layout(View* host) OVERRIDE; | 99 virtual void Layout(View* host) OVERRIDE; |
85 virtual gfx::Size GetPreferredSize(const View* host) const OVERRIDE; | 100 virtual gfx::Size GetPreferredSize(const View* host) const OVERRIDE; |
86 virtual int GetPreferredHeightForWidth(const View* host, | 101 virtual int GetPreferredHeightForWidth(const View* host, |
87 int width) const OVERRIDE; | 102 int width) const OVERRIDE; |
88 | 103 |
89 private: | 104 private: |
105 // Returns the flex for the specified index. | |
106 int GetFlexForViewAt(int index); | |
sky
2014/07/18 15:54:00
const
calamity
2014/07/22 05:35:14
Done.
| |
107 | |
90 // Returns the size and position along the main axis of |rect|. | 108 // Returns the size and position along the main axis of |rect|. |
91 int MainAxisSize(const gfx::Rect& rect) const; | 109 int MainAxisSize(const gfx::Rect& rect) const; |
92 int MainAxisPosition(const gfx::Rect& rect) const; | 110 int MainAxisPosition(const gfx::Rect& rect) const; |
93 | 111 |
94 // Sets the size and position along the main axis of |rect|. | 112 // Sets the size and position along the main axis of |rect|. |
95 void SetMainAxisSize(int size, gfx::Rect* rect) const; | 113 void SetMainAxisSize(int size, gfx::Rect* rect) const; |
96 void SetMainAxisPosition(int position, gfx::Rect* rect) const; | 114 void SetMainAxisPosition(int position, gfx::Rect* rect) const; |
97 | 115 |
98 // Returns the size and position along the cross axis of |rect|. | 116 // Returns the size and position along the cross axis of |rect|. |
99 int CrossAxisSize(const gfx::Rect& rect) const; | 117 int CrossAxisSize(const gfx::Rect& rect) const; |
(...skipping 27 matching lines...) Expand all Loading... | |
127 const int between_child_spacing_; | 145 const int between_child_spacing_; |
128 | 146 |
129 // The alignment of children in the main axis. This is | 147 // The alignment of children in the main axis. This is |
130 // MAIN_AXIS_ALIGNMENT_START by default. | 148 // MAIN_AXIS_ALIGNMENT_START by default. |
131 MainAxisAlignment main_axis_alignment_; | 149 MainAxisAlignment main_axis_alignment_; |
132 | 150 |
133 // The alignment of children in the cross axis. This is | 151 // The alignment of children in the cross axis. This is |
134 // CROSS_AXIS_ALIGNMENT_STRETCH by default. | 152 // CROSS_AXIS_ALIGNMENT_STRETCH by default. |
135 CrossAxisAlignment cross_axis_alignment_; | 153 CrossAxisAlignment cross_axis_alignment_; |
136 | 154 |
155 // A map of view indexes to flex weights. | |
156 std::map<int, int> flex_map_; | |
157 | |
158 // The flex weight for views if none is set. Defaults to 0. | |
159 int default_flex_; | |
160 | |
137 DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout); | 161 DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout); |
138 }; | 162 }; |
139 | 163 |
140 } // namespace views | 164 } // namespace views |
141 | 165 |
142 #endif // UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ | 166 #endif // UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ |
OLD | NEW |