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

Unified Diff: ui/views/layout/box_layout.cc

Issue 284753002: Add main axis alignment for BoxLayout. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/layout/box_layout.cc
diff --git a/ui/views/layout/box_layout.cc b/ui/views/layout/box_layout.cc
index c11479678a998fe492103648b145b3e4911d81d2..3e6d3bea81e7f33c833feae31de8197d30c042a2 100644
--- a/ui/views/layout/box_layout.cc
+++ b/ui/views/layout/box_layout.cc
@@ -19,7 +19,8 @@ BoxLayout::BoxLayout(BoxLayout::Orientation orientation,
inside_border_vertical_spacing,
inside_border_horizontal_spacing),
between_child_spacing_(between_child_spacing),
- spread_blank_space_(false) {
+ spread_blank_space_(false),
+ box_pack_(BOX_PACK_START) {
}
BoxLayout::~BoxLayout() {
@@ -29,11 +30,9 @@ void BoxLayout::Layout(View* host) {
gfx::Rect child_area(host->GetLocalBounds());
child_area.Inset(host->GetInsets());
child_area.Inset(inside_border_insets_);
- int x = child_area.x();
- int y = child_area.y();
int padding = 0;
- if (spread_blank_space_) {
+ if (box_pack_ != BOX_PACK_START || spread_blank_space_) {
int total = 0;
int visible = 0;
for (int i = 0; i < host->child_count(); ++i) {
@@ -51,16 +50,39 @@ void BoxLayout::Layout(View* host) {
if (visible) {
total -= between_child_spacing_;
- if (orientation_ == kHorizontal)
- padding = (child_area.width() - total) / visible;
- else
- padding = (child_area.height() - total) / visible;
-
- if (padding < 0)
- padding = 0;
+ if (spread_blank_space_) {
+ if (orientation_ == kHorizontal)
+ padding = (child_area.width() - total) / visible;
benwells 2014/05/13 02:48:05 I think this code would be easier to follow at a g
calamity 2014/05/13 04:29:29 Done.
+ else
+ padding = (child_area.height() - total) / visible;
+
+ if (padding < 0)
+ padding = 0;
+ } else {
+ if (box_pack_ == BOX_PACK_CENTER) {
+ if (orientation_ == kHorizontal) {
+ child_area.set_x(child_area.x() + (child_area.width() - total) / 2);
+ child_area.set_width(total);
+ } else {
+ child_area.set_y(child_area.y() +
+ (child_area.height() - total) / 2);
+ child_area.set_height(total);
+ }
+ } else if (box_pack_ == BOX_PACK_END) {
+ if (orientation_ == kHorizontal) {
+ child_area.set_x(child_area.x() + child_area.width() - total);
+ child_area.set_width(total);
+ } else {
+ child_area.set_y(child_area.y() + child_area.height() - total);
+ child_area.set_height(total);
+ }
+ }
+ }
}
}
+ int x = child_area.x();
+ int y = child_area.y();
for (int i = 0; i < host->child_count(); ++i) {
View* child = host->child_at(i);
if (child->visible()) {

Powered by Google App Engine
This is Rietveld 408576698