Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Side by Side Diff: ui/views/layout/box_layout.h

Issue 284753002: Add main axis alignment for BoxLayout. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add TODOs Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/views/layout/box_layout.cc » ('j') | ui/views/layout/box_layout.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "ui/gfx/insets.h" 10 #include "ui/gfx/insets.h"
11 #include "ui/views/layout/layout_manager.h" 11 #include "ui/views/layout/layout_manager.h"
12 12
13 namespace gfx { 13 namespace gfx {
14 class Rect;
14 class Size; 15 class Size;
15 } 16 }
16 17
17 namespace views { 18 namespace views {
18 19
19 class View; 20 class View;
20 21
21 // A Layout manager that arranges child views vertically or horizontally in a 22 // A Layout manager that arranges child views vertically or horizontally in a
22 // side-by-side fashion with spacing around and between the child views. The 23 // side-by-side fashion with spacing around and between the child views. The
23 // child views are always sized according to their preferred size. If the 24 // child views are always sized according to their preferred size. If the
24 // host's bounds provide insufficient space, child views will be clamped. 25 // host's bounds provide insufficient space, child views will be clamped.
25 // Excess space will not be distributed. 26 // Excess space will not be distributed.
26 class VIEWS_EXPORT BoxLayout : public LayoutManager { 27 class VIEWS_EXPORT BoxLayout : public LayoutManager {
27 public: 28 public:
28 enum Orientation { 29 enum Orientation {
29 kHorizontal, 30 kHorizontal,
30 kVertical, 31 kVertical,
31 }; 32 };
32 33
34 enum BoxPack {
35 BOX_PACK_START,
36 BOX_PACK_CENTER,
37 BOX_PACK_END,
38 // TODO(calamity): Add BOX_PACK_JUSTIFY which spreads blank space in-
39 // between the child views.
40 };
41
42 // TODO(calamity): Add BoxAlign property to allow cross axis alignment.
43
33 // Use |inside_border_horizontal_spacing| and 44 // Use |inside_border_horizontal_spacing| and
34 // |inside_border_vertical_spacing| to add additional space between the child 45 // |inside_border_vertical_spacing| to add additional space between the child
35 // view area and the host view border. |between_child_spacing| controls the 46 // view area and the host view border. |between_child_spacing| controls the
36 // space in between child views. 47 // space in between child views.
37 BoxLayout(Orientation orientation, 48 BoxLayout(Orientation orientation,
38 int inside_border_horizontal_spacing, 49 int inside_border_horizontal_spacing,
39 int inside_border_vertical_spacing, 50 int inside_border_vertical_spacing,
40 int between_child_spacing); 51 int between_child_spacing);
41 virtual ~BoxLayout(); 52 virtual ~BoxLayout();
42 53
43 void set_spread_blank_space(bool spread) { 54 void set_spread_blank_space(bool spread) {
44 spread_blank_space_ = spread; 55 spread_blank_space_ = spread;
45 } 56 }
46 57
58 void set_box_pack(BoxPack box_pack) { box_pack_ = box_pack; }
59
47 // Overridden from views::LayoutManager: 60 // Overridden from views::LayoutManager:
48 virtual void Layout(View* host) OVERRIDE; 61 virtual void Layout(View* host) OVERRIDE;
49 virtual gfx::Size GetPreferredSize(View* host) OVERRIDE; 62 virtual gfx::Size GetPreferredSize(View* host) OVERRIDE;
50 virtual int GetPreferredHeightForWidth(View* host, int width) OVERRIDE; 63 virtual int GetPreferredHeightForWidth(View* host, int width) OVERRIDE;
51 64
52 private: 65 private:
66 int MainAxisSize(const gfx::Rect& child_area);
67 int MainAxisPosition(const gfx::Rect& child_area);
68 void SetMainAxisSize(gfx::Rect* child_area, int size);
69 void SetMainAxisPosition(gfx::Rect* child_area, int position);
70
53 // The preferred size for the dialog given the width of the child area. 71 // The preferred size for the dialog given the width of the child area.
54 gfx::Size GetPreferredSizeForChildWidth(View* host, int child_area_width); 72 gfx::Size GetPreferredSizeForChildWidth(View* host, int child_area_width);
55 73
56 // The amount of space the layout requires in addition to any space for the 74 // The amount of space the layout requires in addition to any space for the
57 // child views. 75 // child views.
58 gfx::Size NonChildSize(View* host); 76 gfx::Size NonChildSize(View* host);
59 77
60 const Orientation orientation_; 78 const Orientation orientation_;
61 79
62 // Spacing between child views and host view border. 80 // Spacing between child views and host view border.
63 gfx::Insets inside_border_insets_; 81 gfx::Insets inside_border_insets_;
64 82
65 // Spacing to put in between child views. 83 // Spacing to put in between child views.
66 const int between_child_spacing_; 84 const int between_child_spacing_;
67 85
68 // Whether the available extra space should be distributed among the child 86 // Whether the available extra space should be distributed among the child
69 // views. 87 // views. This increases the size of child views rather than the space
88 // between them.
70 bool spread_blank_space_; 89 bool spread_blank_space_;
71 90
91 // The alignment of children in the main axis. This is BOX_PACK_START by
92 // default.
93 BoxPack box_pack_;
94
72 DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout); 95 DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout);
73 }; 96 };
74 97
75 } // namespace views 98 } // namespace views
76 99
77 #endif // UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ 100 #endif // UI_VIEWS_LAYOUT_BOX_LAYOUT_H_
OLDNEW
« no previous file with comments | « no previous file | ui/views/layout/box_layout.cc » ('j') | ui/views/layout/box_layout.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698