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 given |view|. 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 void SetFlexForView(const View* view, int flex); |
| 88 |
| 89 // Clears the flex for the given |view|, causing it to use the default |
| 90 // flex. |
| 91 void ClearFlexForView(const View* view); |
| 92 |
| 93 // Sets the flex for views to use when none is specified. |
| 94 void SetDefaultFlex(int default_flex); |
| 95 |
83 // Overridden from views::LayoutManager: | 96 // Overridden from views::LayoutManager: |
| 97 virtual void Installed(View* host) OVERRIDE; |
| 98 virtual void Uninstalled(View* host) OVERRIDE; |
| 99 virtual void ViewRemoved(View* host, View* view) OVERRIDE; |
84 virtual void Layout(View* host) OVERRIDE; | 100 virtual void Layout(View* host) OVERRIDE; |
85 virtual gfx::Size GetPreferredSize(const View* host) const OVERRIDE; | 101 virtual gfx::Size GetPreferredSize(const View* host) const OVERRIDE; |
86 virtual int GetPreferredHeightForWidth(const View* host, | 102 virtual int GetPreferredHeightForWidth(const View* host, |
87 int width) const OVERRIDE; | 103 int width) const OVERRIDE; |
88 | 104 |
89 private: | 105 private: |
| 106 // Returns the flex for the specified |view|. |
| 107 int GetFlexForView(const View* view) const; |
| 108 |
90 // Returns the size and position along the main axis of |rect|. | 109 // Returns the size and position along the main axis of |rect|. |
91 int MainAxisSize(const gfx::Rect& rect) const; | 110 int MainAxisSize(const gfx::Rect& rect) const; |
92 int MainAxisPosition(const gfx::Rect& rect) const; | 111 int MainAxisPosition(const gfx::Rect& rect) const; |
93 | 112 |
94 // Sets the size and position along the main axis of |rect|. | 113 // Sets the size and position along the main axis of |rect|. |
95 void SetMainAxisSize(int size, gfx::Rect* rect) const; | 114 void SetMainAxisSize(int size, gfx::Rect* rect) const; |
96 void SetMainAxisPosition(int position, gfx::Rect* rect) const; | 115 void SetMainAxisPosition(int position, gfx::Rect* rect) const; |
97 | 116 |
98 // Returns the size and position along the cross axis of |rect|. | 117 // Returns the size and position along the cross axis of |rect|. |
99 int CrossAxisSize(const gfx::Rect& rect) const; | 118 int CrossAxisSize(const gfx::Rect& rect) const; |
(...skipping 27 matching lines...) Expand all Loading... |
127 const int between_child_spacing_; | 146 const int between_child_spacing_; |
128 | 147 |
129 // The alignment of children in the main axis. This is | 148 // The alignment of children in the main axis. This is |
130 // MAIN_AXIS_ALIGNMENT_START by default. | 149 // MAIN_AXIS_ALIGNMENT_START by default. |
131 MainAxisAlignment main_axis_alignment_; | 150 MainAxisAlignment main_axis_alignment_; |
132 | 151 |
133 // The alignment of children in the cross axis. This is | 152 // The alignment of children in the cross axis. This is |
134 // CROSS_AXIS_ALIGNMENT_STRETCH by default. | 153 // CROSS_AXIS_ALIGNMENT_STRETCH by default. |
135 CrossAxisAlignment cross_axis_alignment_; | 154 CrossAxisAlignment cross_axis_alignment_; |
136 | 155 |
| 156 // A map of views to their flex weights. |
| 157 std::map<const View*, int> flex_map_; |
| 158 |
| 159 // The flex weight for views if none is set. Defaults to 0. |
| 160 int default_flex_; |
| 161 |
| 162 // The view that this BoxLayout is managing the layout for. |
| 163 views::View* host_; |
| 164 |
137 DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout); | 165 DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout); |
138 }; | 166 }; |
139 | 167 |
140 } // namespace views | 168 } // namespace views |
141 | 169 |
142 #endif // UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ | 170 #endif // UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ |
OLD | NEW |