summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
Diffstat (limited to 'views')
-rw-r--r--views/box_layout.cc15
-rw-r--r--views/box_layout.h14
-rw-r--r--views/box_layout_unittest.cc17
-rw-r--r--views/examples/widget_example.h6
4 files changed, 31 insertions, 21 deletions
diff --git a/views/box_layout.cc b/views/box_layout.cc
index 84fb096..adb192f 100644
--- a/views/box_layout.cc
+++ b/views/box_layout.cc
@@ -7,17 +7,20 @@
namespace views {
BoxLayout::BoxLayout(BoxLayout::Orientation orientation,
- int inside_border_spacing,
+ int inside_border_horizontal_spacing,
+ int inside_border_vertical_spacing,
int between_child_spacing)
: orientation_(orientation),
- inside_border_spacing_(inside_border_spacing),
+ inside_border_horizontal_spacing_(inside_border_horizontal_spacing),
+ inside_border_vertical_spacing_(inside_border_vertical_spacing),
between_child_spacing_(between_child_spacing) {
}
void BoxLayout::Layout(View* host) {
gfx::Rect childArea(gfx::Rect(host->size()));
childArea.Inset(host->GetInsets());
- childArea.Inset(inside_border_spacing_, inside_border_spacing_);
+ childArea.Inset(inside_border_horizontal_spacing_,
+ inside_border_vertical_spacing_);
int x = childArea.x();
int y = childArea.y();
for (int i = 0; i < host->GetChildViewCount(); ++i) {
@@ -58,9 +61,9 @@ gfx::Size BoxLayout::GetPreferredSize(View* host) {
}
}
gfx::Insets insets(host->GetInsets());
- return
- gfx::Size(bounds.width() + insets.width() + 2 * inside_border_spacing_,
- bounds.height() + insets.height() + 2 * inside_border_spacing_);
+ return gfx::Size(
+ bounds.width() + insets.width() + 2 * inside_border_horizontal_spacing_,
+ bounds.height() + insets.height() + 2 * inside_border_vertical_spacing_);
}
} // namespace views
diff --git a/views/box_layout.h b/views/box_layout.h
index ffce6f8..2e86d9b 100644
--- a/views/box_layout.h
+++ b/views/box_layout.h
@@ -23,11 +23,13 @@ class BoxLayout : public LayoutManager {
kVertical,
};
- // Use |inside_border_spacing| to add additional space between the child view
- // area and the host view border. |between_child_spacing| controls the space
- // in between child views.
+ // Use |inside_border_horizontal_spacing| and
+ // |inside_border_vertical_spacing| to add additional space between the child
+ // view area and the host view border. |between_child_spacing| controls the
+ // space in between child views.
BoxLayout(Orientation orientation,
- int inside_border_spacing,
+ int inside_border_horizontal_spacing,
+ int inside_border_vertical_spacing,
int between_child_spacing);
virtual ~BoxLayout() {}
@@ -39,7 +41,9 @@ class BoxLayout : public LayoutManager {
const Orientation orientation_;
// Spacing between child views and host view border.
- const int inside_border_spacing_;
+ const int inside_border_horizontal_spacing_;
+ const int inside_border_vertical_spacing_;
+
// Spacing to put in between child views.
const int between_child_spacing_;
diff --git a/views/box_layout_unittest.cc b/views/box_layout_unittest.cc
index 712b2ef..d16d782 100644
--- a/views/box_layout_unittest.cc
+++ b/views/box_layout_unittest.cc
@@ -30,12 +30,13 @@ class BoxLayoutTest : public testing::Test {
};
TEST_F(BoxLayoutTest, Empty) {
- layout_.reset(new views::BoxLayout(views::BoxLayout::kHorizontal, 10, 20));
+ layout_.reset(
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 10, 10, 20));
EXPECT_EQ(gfx::Size(20, 20), layout_->GetPreferredSize(host_.get()));
}
TEST_F(BoxLayoutTest, AlignmentHorizontal) {
- layout_.reset(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0));
+ layout_.reset(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
views::View* v1 = new StaticSizedView(gfx::Size(10, 20));
host_->AddChildView(v1);
views::View* v2 = new StaticSizedView(gfx::Size(10, 10));
@@ -48,7 +49,7 @@ TEST_F(BoxLayoutTest, AlignmentHorizontal) {
}
TEST_F(BoxLayoutTest, AlignmentVertical) {
- layout_.reset(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0));
+ layout_.reset(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
views::View* v1 = new StaticSizedView(gfx::Size(20, 10));
host_->AddChildView(v1);
views::View* v2 = new StaticSizedView(gfx::Size(10, 10));
@@ -61,7 +62,7 @@ TEST_F(BoxLayoutTest, AlignmentVertical) {
}
TEST_F(BoxLayoutTest, Spacing) {
- layout_.reset(new views::BoxLayout(views::BoxLayout::kHorizontal, 7, 8));
+ layout_.reset(new views::BoxLayout(views::BoxLayout::kHorizontal, 7, 7, 8));
views::View* v1 = new StaticSizedView(gfx::Size(10, 20));
host_->AddChildView(v1);
views::View* v2 = new StaticSizedView(gfx::Size(10, 20));
@@ -74,7 +75,7 @@ TEST_F(BoxLayoutTest, Spacing) {
}
TEST_F(BoxLayoutTest, Overflow) {
- layout_.reset(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0));
+ layout_.reset(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
views::View* v1 = new StaticSizedView(gfx::Size(20, 20));
host_->AddChildView(v1);
views::View* v2 = new StaticSizedView(gfx::Size(10, 20));
@@ -86,7 +87,8 @@ TEST_F(BoxLayoutTest, Overflow) {
}
TEST_F(BoxLayoutTest, NoSpace) {
- layout_.reset(new views::BoxLayout(views::BoxLayout::kHorizontal, 10, 10));
+ layout_.reset(
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 10, 10, 10));
views::View* childView = new StaticSizedView(gfx::Size(20, 20));
host_->AddChildView(childView);
host_->SetBounds(0, 0, 10, 10);
@@ -95,7 +97,8 @@ TEST_F(BoxLayoutTest, NoSpace) {
}
TEST_F(BoxLayoutTest, InvisibleChild) {
- layout_.reset(new views::BoxLayout(views::BoxLayout::kHorizontal, 10, 10));
+ layout_.reset(
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 10, 10, 10));
views::View* v1 = new StaticSizedView(gfx::Size(20, 20));
v1->SetVisible(false);
host_->AddChildView(v1);
diff --git a/views/examples/widget_example.h b/views/examples/widget_example.h
index ef6107a..8932847 100644
--- a/views/examples/widget_example.h
+++ b/views/examples/widget_example.h
@@ -61,7 +61,7 @@ class WidgetExample : public ExampleBase, public views::ButtonListener {
virtual void CreateExampleView(views::View* container) {
container->SetLayoutManager(
- new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 2));
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 2));
BuildButton(container, L"Create a popup widget", POPUP);
BuildButton(container, L"Create a transparent popup widget",
TRANSPARENT_POPUP);
@@ -69,7 +69,7 @@ class WidgetExample : public ExampleBase, public views::ButtonListener {
views::View* vert_container = new views::View();
container->AddChildView(vert_container);
vert_container->SetLayoutManager(
- new views::BoxLayout(views::BoxLayout::kVertical, 0, 20));
+ new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 20));
BuildButton(vert_container, L"Create a child widget", CHILD);
BuildButton(vert_container, L"Create a transparent child widget",
TRANSPARENT_CHILD);
@@ -103,7 +103,7 @@ class WidgetExample : public ExampleBase, public views::ButtonListener {
views::View* button_container = new views::View();
button_container->SetLayoutManager(
- new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 1));
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 1));
button_container->AddChildView(close_button);
button_container->AddChildView(native_button);