Commit d1b26261 authored by calamity's avatar calamity Committed by Commit bot

Add a minimum cross axis size to BoxLayout.

This CL allows clients to specify a minimum cross axis size when using
a BoxLayout.

BUG=406983

Review URL: https://codereview.chromium.org/494273003

Cr-Commit-Position: refs/heads/master@{#292299}
parent a8107cd6
...@@ -22,6 +22,7 @@ BoxLayout::BoxLayout(BoxLayout::Orientation orientation, ...@@ -22,6 +22,7 @@ BoxLayout::BoxLayout(BoxLayout::Orientation orientation,
main_axis_alignment_(MAIN_AXIS_ALIGNMENT_START), main_axis_alignment_(MAIN_AXIS_ALIGNMENT_START),
cross_axis_alignment_(CROSS_AXIS_ALIGNMENT_STRETCH), cross_axis_alignment_(CROSS_AXIS_ALIGNMENT_STRETCH),
default_flex_(0), default_flex_(0),
minimum_cross_axis_size_(0),
host_(NULL) { host_(NULL) {
} }
...@@ -162,6 +163,7 @@ gfx::Size BoxLayout::GetPreferredSize(const View* host) const { ...@@ -162,6 +163,7 @@ gfx::Size BoxLayout::GetPreferredSize(const View* host) const {
width = std::max(width, child->GetPreferredSize().width()); width = std::max(width, child->GetPreferredSize().width());
} }
width = std::max(width, minimum_cross_axis_size_);
} }
return GetPreferredSizeForChildWidth(host, width); return GetPreferredSizeForChildWidth(host, width);
...@@ -278,6 +280,8 @@ gfx::Size BoxLayout::GetPreferredSizeForChildWidth(const View* host, ...@@ -278,6 +280,8 @@ gfx::Size BoxLayout::GetPreferredSizeForChildWidth(const View* host,
child_area_bounds.Union(child_bounds); child_area_bounds.Union(child_bounds);
position += size.width() + between_child_spacing_; position += size.width() + between_child_spacing_;
} }
child_area_bounds.set_height(
std::max(child_area_bounds.height(), minimum_cross_axis_size_));
} else { } else {
int height = 0; int height = 0;
for (int i = 0; i < host->child_count(); ++i) { for (int i = 0; i < host->child_count(); ++i) {
......
...@@ -77,6 +77,10 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager { ...@@ -77,6 +77,10 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager {
inside_border_insets_ = insets; inside_border_insets_ = insets;
} }
void set_minimum_cross_axis_size(int size) {
minimum_cross_axis_size_ = size;
}
// Sets the flex weight for the given |view|. Using the preferred size as // Sets the flex weight for the given |view|. Using the preferred size as
// the basis, free space along the main axis is distributed to views in the // the basis, free space along the main axis is distributed to views in the
// ratio of their flex weights. Similarly, if the views will overflow the // ratio of their flex weights. Similarly, if the views will overflow the
...@@ -159,6 +163,9 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager { ...@@ -159,6 +163,9 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager {
// The flex weight for views if none is set. Defaults to 0. // The flex weight for views if none is set. Defaults to 0.
int default_flex_; int default_flex_;
// The minimum cross axis size for the layout.
int minimum_cross_axis_size_;
// The view that this BoxLayout is managing the layout for. // The view that this BoxLayout is managing the layout for.
views::View* host_; views::View* host_;
......
...@@ -590,4 +590,24 @@ TEST_F(BoxLayoutTest, FlexShrinkVerticalWithRemainder) { ...@@ -590,4 +590,24 @@ TEST_F(BoxLayoutTest, FlexShrinkVerticalWithRemainder) {
} }
} }
TEST_F(BoxLayoutTest, MinimumCrossAxisVertical) {
BoxLayout* layout = new BoxLayout(BoxLayout::kVertical, 0, 0, 0);
host_->SetLayoutManager(layout);
View* v1 = new StaticSizedView(gfx::Size(20, 10));
host_->AddChildView(v1);
layout->set_minimum_cross_axis_size(30);
EXPECT_EQ(gfx::Size(30, 10), layout->GetPreferredSize(host_.get()));
}
TEST_F(BoxLayoutTest, MinimumCrossAxisHorizontal) {
BoxLayout* layout = new BoxLayout(BoxLayout::kHorizontal, 0, 0, 0);
host_->SetLayoutManager(layout);
View* v1 = new StaticSizedView(gfx::Size(20, 10));
host_->AddChildView(v1);
layout->set_minimum_cross_axis_size(30);
EXPECT_EQ(gfx::Size(20, 30), layout->GetPreferredSize(host_.get()));
}
} // namespace views } // namespace views
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment