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

Remove manual layout for ScrollableView

The manual layout just put one child view at the start and one in the
middle vertically. This CL removes the manual layout by introducing two
container views to be placed in equal size vertically.

BUG=1005568

Change-Id: Iae552da751d71175d3967deaf788a323221d0a1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1884999
Commit-Queue: Wei Li <weili@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710578}
parent 94646487
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/controls/button/label_button.h" #include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/radio_button.h" #include "ui/views/controls/button/radio_button.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/grid_layout.h" #include "ui/views/layout/grid_layout.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -28,8 +29,19 @@ class ScrollViewExample::ScrollableView : public View { ...@@ -28,8 +29,19 @@ class ScrollViewExample::ScrollableView : public View {
public: public:
ScrollableView() { ScrollableView() {
SetColor(SK_ColorRED, SK_ColorCYAN); SetColor(SK_ColorRED, SK_ColorCYAN);
AddChildView(new LabelButton(nullptr, ASCIIToUTF16("Button")));
AddChildView(new RadioButton(ASCIIToUTF16("Radio Button"), 0)); auto* layout_manager = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, gfx::Insets(), 0));
const auto add_child = [this](std::unique_ptr<View> view) {
auto* container = AddChildView(std::make_unique<View>());
container->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
container->AddChildView(std::move(view));
};
add_child(std::make_unique<LabelButton>(nullptr, ASCIIToUTF16("Button")));
add_child(std::make_unique<RadioButton>(ASCIIToUTF16("Radio Button"), 0));
layout_manager->SetDefaultFlex(1);
} }
void SetColor(SkColor from, SkColor to) { void SetColor(SkColor from, SkColor to) {
...@@ -37,19 +49,6 @@ class ScrollViewExample::ScrollableView : public View { ...@@ -37,19 +49,6 @@ class ScrollViewExample::ScrollableView : public View {
to_color_ = to; to_color_ = to;
} }
void PlaceChildY(size_t index, int y) {
View* view = children()[index];
gfx::Size size = view->GetPreferredSize();
view->SetBounds(0, y, size.width(), size.height());
}
// View
void Layout() override {
PlaceChildY(0, 0);
PlaceChildY(1, height() / 2);
SizeToPreferredSize();
}
void OnPaintBackground(gfx::Canvas* canvas) override { void OnPaintBackground(gfx::Canvas* canvas) override {
cc::PaintFlags flags; cc::PaintFlags flags;
flags.setShader(gfx::CreateGradientShader( flags.setShader(gfx::CreateGradientShader(
...@@ -58,10 +57,6 @@ class ScrollViewExample::ScrollableView : public View { ...@@ -58,10 +57,6 @@ class ScrollViewExample::ScrollableView : public View {
canvas->DrawRect(GetLocalBounds(), flags); canvas->DrawRect(GetLocalBounds(), flags);
} }
gfx::Size CalculatePreferredSize() const override {
return gfx::Size(width(), height());
}
private: private:
SkColor from_color_; SkColor from_color_;
SkColor to_color_; SkColor to_color_;
......
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