Use layout manager for FullPanel in views example
FullPanel has two child views which takes up 75% and 25% of the
total width. This can be done by box layout manager instead of
manually override Layout(). This CL refactors it into using
a layout manager.
BUG=1005568
Change-Id: Iaf01ebc6be64f449f793e60913bb1bf1ddca629f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1848473
Commit-Queue: Wei Li <weili@chromium.org>
Reviewed-by: Robert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704007}
diff --git a/ui/views/examples/layout_example_base.cc b/ui/views/examples/layout_example_base.cc
index eb25142..2ecac39 100644
--- a/ui/views/examples/layout_example_base.cc
+++ b/ui/views/examples/layout_example_base.cc
@@ -16,6 +16,7 @@
#include "ui/views/controls/combobox/combobox.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/examples/example_combobox_model.h"
+#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/view_class_properties.h"
@@ -39,24 +40,10 @@
FullPanel() = default;
~FullPanel() override = default;
- // View
- void Layout() override;
-
private:
DISALLOW_COPY_AND_ASSIGN(FullPanel);
};
-void FullPanel::Layout() {
- DCHECK_EQ(2u, children().size());
- View* left_panel = children()[0];
- View* right_panel = children()[1];
- gfx::Rect bounds = GetContentsBounds();
- left_panel->SetBounds(bounds.x(), bounds.y(), (bounds.width() * 75) / 100,
- bounds.height());
- right_panel->SetBounds(left_panel->width(), bounds.y(),
- bounds.width() - left_panel->width(), bounds.height());
-}
-
} // namespace
LayoutExampleBase::ChildPanel::ChildPanel(LayoutExampleBase* example)
@@ -256,11 +243,15 @@
View* full_panel = new FullPanel();
container->AddChildView(full_panel);
+ auto* manager = full_panel->SetLayoutManager(
+ std::make_unique<BoxLayout>(views::BoxLayout::Orientation::kHorizontal));
layout_panel_ = new View();
layout_panel_->SetBorder(CreateSolidBorder(1, SK_ColorLTGRAY));
full_panel->AddChildView(layout_panel_);
+ manager->SetFlexForView(layout_panel_, 3);
control_panel_ = new View();
full_panel->AddChildView(control_panel_);
+ manager->SetFlexForView(control_panel_, 1);
int vertical_pos = kLayoutExampleVerticalSpacing;
int horizontal_pos = kLayoutExampleLeftPadding;