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

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

Issue 9465042: views: Add option in BoxLayout to spread blank space among the child views. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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
« no previous file with comments | « ui/views/layout/box_layout.h ('k') | ui/views/layout/box_layout_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/layout/box_layout.cc
diff --git a/ui/views/layout/box_layout.cc b/ui/views/layout/box_layout.cc
index 7282431685715c1efd8f510b1dd057821b73b590..4db0677141d08e66ecee35386c7b6b8aebbcf65f 100644
--- a/ui/views/layout/box_layout.cc
+++ b/ui/views/layout/box_layout.cc
@@ -17,7 +17,8 @@ BoxLayout::BoxLayout(BoxLayout::Orientation orientation,
: orientation_(orientation),
inside_border_horizontal_spacing_(inside_border_horizontal_spacing),
inside_border_vertical_spacing_(inside_border_vertical_spacing),
- between_child_spacing_(between_child_spacing) {
+ between_child_spacing_(between_child_spacing),
+ spread_blank_space_(false) {
}
BoxLayout::~BoxLayout() {
@@ -30,17 +31,45 @@ void BoxLayout::Layout(View* host) {
inside_border_vertical_spacing_);
int x = child_area.x();
int y = child_area.y();
+
+ int padding = 0;
+ if (spread_blank_space_) {
+ int total = 0;
+ int visible = 0;
+ for (int i = 0; i < host->child_count(); ++i) {
+ View* child = host->child_at(i);
+ if (!child->visible())
+ continue;
+ if (orientation_ == kHorizontal)
+ total += child->GetPreferredSize().width() + between_child_spacing_;
+ else
+ total += child->GetPreferredSize().height() + between_child_spacing_;
+ ++visible;
+ }
+
+ 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;
+ }
+ }
+
for (int i = 0; i < host->child_count(); ++i) {
View* child = host->child_at(i);
if (child->visible()) {
gfx::Rect bounds(x, y, child_area.width(), child_area.height());
gfx::Size size(child->GetPreferredSize());
if (orientation_ == kHorizontal) {
- bounds.set_width(size.width());
- x += size.width() + between_child_spacing_;
+ bounds.set_width(size.width() + padding);
+ x += size.width() + between_child_spacing_ + padding;
} else {
- bounds.set_height(size.height());
- y += size.height() + between_child_spacing_;
+ bounds.set_height(size.height() + padding);
+ y += size.height() + between_child_spacing_ + padding;
}
// Clamp child view bounds to |child_area|.
child->SetBoundsRect(bounds.Intersect(child_area));
« no previous file with comments | « ui/views/layout/box_layout.h ('k') | ui/views/layout/box_layout_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698