Commit c55e269d authored by Wei Li's avatar Wei Li Committed by Commit Bot

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: default avatarRobert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704007}
parent e51f5cc7
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ui/views/controls/combobox/combobox.h" #include "ui/views/controls/combobox/combobox.h"
#include "ui/views/controls/textfield/textfield.h" #include "ui/views/controls/textfield/textfield.h"
#include "ui/views/examples/example_combobox_model.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/layout/fill_layout.h"
#include "ui/views/view_class_properties.h" #include "ui/views/view_class_properties.h"
...@@ -39,24 +40,10 @@ class FullPanel : public View { ...@@ -39,24 +40,10 @@ class FullPanel : public View {
FullPanel() = default; FullPanel() = default;
~FullPanel() override = default; ~FullPanel() override = default;
// View
void Layout() override;
private: private:
DISALLOW_COPY_AND_ASSIGN(FullPanel); 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 } // namespace
LayoutExampleBase::ChildPanel::ChildPanel(LayoutExampleBase* example) LayoutExampleBase::ChildPanel::ChildPanel(LayoutExampleBase* example)
...@@ -256,11 +243,15 @@ void LayoutExampleBase::CreateExampleView(View* container) { ...@@ -256,11 +243,15 @@ void LayoutExampleBase::CreateExampleView(View* container) {
View* full_panel = new FullPanel(); View* full_panel = new FullPanel();
container->AddChildView(full_panel); container->AddChildView(full_panel);
auto* manager = full_panel->SetLayoutManager(
std::make_unique<BoxLayout>(views::BoxLayout::Orientation::kHorizontal));
layout_panel_ = new View(); layout_panel_ = new View();
layout_panel_->SetBorder(CreateSolidBorder(1, SK_ColorLTGRAY)); layout_panel_->SetBorder(CreateSolidBorder(1, SK_ColorLTGRAY));
full_panel->AddChildView(layout_panel_); full_panel->AddChildView(layout_panel_);
manager->SetFlexForView(layout_panel_, 3);
control_panel_ = new View(); control_panel_ = new View();
full_panel->AddChildView(control_panel_); full_panel->AddChildView(control_panel_);
manager->SetFlexForView(control_panel_, 1);
int vertical_pos = kLayoutExampleVerticalSpacing; int vertical_pos = kLayoutExampleVerticalSpacing;
int horizontal_pos = kLayoutExampleLeftPadding; int horizontal_pos = kLayoutExampleLeftPadding;
......
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