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. |
sashab
2014/07/01 06:52:04
Is this TODO still needed? This can be emulated wi
calamity
2014/07/01 08:19:44
This TODO outlines spreading the blank space to th
| |
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, |
56 CROSS_AXIS_ALIGNMENT_START, | 53 CROSS_AXIS_ALIGNMENT_START, |
57 CROSS_AXIS_ALIGNMENT_CENTER, | 54 CROSS_AXIS_ALIGNMENT_CENTER, |
(...skipping 15 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 void set_default_flex(int flex) { default_flex_ = flex; } | |
sashab
2014/07/01 06:52:04
Is there a reason these methods use underscores an
calamity
2014/07/01 08:19:44
Setting a property verbatim can be inlined and uni
| |
81 | |
82 // Sets the flex weight for the view at |index|. This uses the preferred main | |
83 // axis size as a basis and then distributes any free space along the main | |
84 // axis to the views in the ratio of the flex weights. If the views will | |
85 // overflow the parent in the main axis, this subtracts space from the views | |
86 // in the ratio of the flex weights. | |
87 void SetFlexForViewAt(int index, int flex); | |
sashab
2014/07/01 06:52:04
Can flex be negative? Maybe add 'The flex cannot b
calamity
2014/07/01 08:19:44
Done.
| |
88 | |
89 // Clears the flex for the view at |index|, causing it to use the default | |
90 // flex. | |
91 void ClearFlexForViewAt(int index); | |
92 | |
83 // Overridden from views::LayoutManager: | 93 // Overridden from views::LayoutManager: |
84 virtual void Layout(View* host) OVERRIDE; | 94 virtual void Layout(View* host) OVERRIDE; |
85 virtual gfx::Size GetPreferredSize(const View* host) const OVERRIDE; | 95 virtual gfx::Size GetPreferredSize(const View* host) const OVERRIDE; |
86 virtual int GetPreferredHeightForWidth(const View* host, | 96 virtual int GetPreferredHeightForWidth(const View* host, |
87 int width) const OVERRIDE; | 97 int width) const OVERRIDE; |
88 | 98 |
89 private: | 99 private: |
100 // Returns the flex for the specified index. | |
sashab
2014/07/01 06:52:04
Nit: 'Returns the flex *for the view*...'
calamity
2014/07/01 08:19:44
I think this is disingenuous as it implies the fle
| |
101 int GetFlexForViewAt(int index); | |
102 | |
90 // Returns the size and position along the main axis of |rect|. | 103 // Returns the size and position along the main axis of |rect|. |
91 int MainAxisSize(const gfx::Rect& rect) const; | 104 int MainAxisSize(const gfx::Rect& rect) const; |
92 int MainAxisPosition(const gfx::Rect& rect) const; | 105 int MainAxisPosition(const gfx::Rect& rect) const; |
93 | 106 |
94 // Sets the size and position along the main axis of |rect|. | 107 // Sets the size and position along the main axis of |rect|. |
95 void SetMainAxisSize(int size, gfx::Rect* rect) const; | 108 void SetMainAxisSize(int size, gfx::Rect* rect) const; |
96 void SetMainAxisPosition(int position, gfx::Rect* rect) const; | 109 void SetMainAxisPosition(int position, gfx::Rect* rect) const; |
97 | 110 |
98 // Returns the size and position along the cross axis of |rect|. | 111 // Returns the size and position along the cross axis of |rect|. |
99 int CrossAxisSize(const gfx::Rect& rect) const; | 112 int CrossAxisSize(const gfx::Rect& rect) const; |
(...skipping 27 matching lines...) Expand all Loading... | |
127 const int between_child_spacing_; | 140 const int between_child_spacing_; |
128 | 141 |
129 // The alignment of children in the main axis. This is | 142 // The alignment of children in the main axis. This is |
130 // MAIN_AXIS_ALIGNMENT_START by default. | 143 // MAIN_AXIS_ALIGNMENT_START by default. |
131 MainAxisAlignment main_axis_alignment_; | 144 MainAxisAlignment main_axis_alignment_; |
132 | 145 |
133 // The alignment of children in the cross axis. This is | 146 // The alignment of children in the cross axis. This is |
134 // CROSS_AXIS_ALIGNMENT_STRETCH by default. | 147 // CROSS_AXIS_ALIGNMENT_STRETCH by default. |
135 CrossAxisAlignment cross_axis_alignment_; | 148 CrossAxisAlignment cross_axis_alignment_; |
136 | 149 |
150 // A map of view indexes to flex weights. | |
151 std::map<int, int> flex_map_; | |
152 | |
153 // The flex weight for views if none is set. | |
sashab
2014/07/01 06:52:04
Add to this comment 'Defaults to 0.'
calamity
2014/07/01 08:19:44
Done.
| |
154 int default_flex_; | |
155 | |
137 DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout); | 156 DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout); |
138 }; | 157 }; |
139 | 158 |
140 } // namespace views | 159 } // namespace views |
141 | 160 |
142 #endif // UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ | 161 #endif // UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ |
OLD | NEW |