Commit 4a985723 authored by Thomas Lukaszewicz's avatar Thomas Lukaszewicz Committed by Commit Bot

Views: Add FlexLayoutView

Add a FlexLayoutView with the various setters and getters for the
FlexLayout exposed as View properties.

Bug: None
Change-Id: Id4380e9353c7f47774ac35a074559dc31492ab77
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419135Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809870}
parent 229a7c61
......@@ -198,6 +198,7 @@ component("views") {
"layout/fill_layout.h",
"layout/flex_layout.h",
"layout/flex_layout_types.h",
"layout/flex_layout_view.h",
"layout/grid_layout.h",
"layout/layout_manager.h",
"layout/layout_manager_base.h",
......@@ -399,6 +400,7 @@ component("views") {
"layout/fill_layout.cc",
"layout/flex_layout.cc",
"layout/flex_layout_types.cc",
"layout/flex_layout_view.cc",
"layout/grid_layout.cc",
"layout/layout_manager.cc",
"layout/layout_manager_base.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/layout/flex_layout_view.h"
#include <memory>
namespace {
// An enum giving different RenderText properties unique keys for the
// OnPropertyChanged call.
enum LabelPropertyKey {
kOrientation = 1,
kMainAxisAlignment,
kCrossAxisAlignment,
kInteriorMargin,
kMinimumCrossAxisSize,
kCollapseMargins,
kIncludeHostInsetsInLayout,
kIgnoreMainAxisMargins,
kFlexAllocationOrder,
};
} // namespace
namespace views {
FlexLayoutView::FlexLayoutView()
: layout_(SetLayoutManager(std::make_unique<FlexLayout>())) {}
FlexLayoutView::~FlexLayoutView() = default;
void FlexLayoutView::SetOrientation(LayoutOrientation orientation) {
if (orientation == layout_->orientation())
return;
layout_->SetOrientation(orientation);
OnPropertyChanged(&layout_ + kOrientation, kPropertyEffectsLayout);
}
LayoutOrientation FlexLayoutView::GetOrientation() const {
return layout_->orientation();
}
void FlexLayoutView::SetMainAxisAlignment(LayoutAlignment main_axis_alignment) {
if (main_axis_alignment == layout_->main_axis_alignment())
return;
layout_->SetMainAxisAlignment(main_axis_alignment);
OnPropertyChanged(&layout_ + kMainAxisAlignment, kPropertyEffectsLayout);
}
LayoutAlignment FlexLayoutView::GetMainAxisAlignment() const {
return layout_->main_axis_alignment();
}
void FlexLayoutView::SetCrossAxisAlignment(
LayoutAlignment cross_axis_alignment) {
if (cross_axis_alignment == layout_->cross_axis_alignment())
return;
layout_->SetCrossAxisAlignment(cross_axis_alignment);
OnPropertyChanged(&layout_ + kCrossAxisAlignment, kPropertyEffectsLayout);
}
LayoutAlignment FlexLayoutView::GetCrossAxisAlignment() const {
return layout_->cross_axis_alignment();
}
void FlexLayoutView::SetInteriorMargin(const gfx::Insets& interior_margin) {
if (interior_margin == layout_->interior_margin())
return;
layout_->SetInteriorMargin(interior_margin);
OnPropertyChanged(&layout_ + kInteriorMargin, kPropertyEffectsLayout);
}
const gfx::Insets& FlexLayoutView::GetInteriorMargin() const {
return layout_->interior_margin();
}
void FlexLayoutView::SetMinimumCrossAxisSize(int size) {
if (size == layout_->minimum_cross_axis_size())
return;
layout_->SetMinimumCrossAxisSize(size);
OnPropertyChanged(&layout_ + kMinimumCrossAxisSize, kPropertyEffectsLayout);
}
int FlexLayoutView::GetMinimumCrossAxisSize() const {
return layout_->minimum_cross_axis_size();
}
void FlexLayoutView::SetCollapseMargins(bool collapse_margins) {
if (collapse_margins == layout_->collapse_margins())
return;
layout_->SetCollapseMargins(collapse_margins);
OnPropertyChanged(&layout_ + kCollapseMargins, kPropertyEffectsLayout);
}
bool FlexLayoutView::GetCollapseMargins() const {
return layout_->collapse_margins();
}
void FlexLayoutView::SetIncludeHostInsetsInLayout(
bool include_host_insets_in_layout) {
if (include_host_insets_in_layout == layout_->include_host_insets_in_layout())
return;
layout_->SetIncludeHostInsetsInLayout(include_host_insets_in_layout);
OnPropertyChanged(&layout_ + kIncludeHostInsetsInLayout,
kPropertyEffectsLayout);
}
bool FlexLayoutView::GetIncludeHostInsetsInLayout() const {
return layout_->include_host_insets_in_layout();
}
void FlexLayoutView::SetIgnoreDefaultMainAxisMargins(
bool ignore_default_main_axis_margins) {
if (ignore_default_main_axis_margins ==
layout_->ignore_default_main_axis_margins()) {
return;
}
layout_->SetIgnoreDefaultMainAxisMargins(ignore_default_main_axis_margins);
OnPropertyChanged(&layout_ + kIgnoreMainAxisMargins, kPropertyEffectsLayout);
}
bool FlexLayoutView::GetIgnoreDefaultMainAxisMargins() const {
return layout_->ignore_default_main_axis_margins();
}
void FlexLayoutView::SetFlexAllocationOrder(
FlexAllocationOrder flex_allocation_order) {
if (flex_allocation_order == layout_->flex_allocation_order())
return;
layout_->SetFlexAllocationOrder(flex_allocation_order);
OnPropertyChanged(&layout_ + kFlexAllocationOrder, kPropertyEffectsLayout);
}
FlexAllocationOrder FlexLayoutView::GetFlexAllocationOrder() const {
return layout_->flex_allocation_order();
}
FlexRule FlexLayoutView::GetDefaultFlexRule() const {
return layout_->GetDefaultFlexRule();
}
} // namespace views
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_LAYOUT_FLEX_LAYOUT_VIEW_H_
#define UI_VIEWS_LAYOUT_FLEX_LAYOUT_VIEW_H_
#include "ui/views/layout/flex_layout.h"
#include "ui/views/layout/flex_layout_types.h"
#include "ui/views/view.h"
#include "ui/views/views_export.h"
namespace views {
class VIEWS_EXPORT FlexLayoutView : public View {
public:
FlexLayoutView();
FlexLayoutView(const FlexLayoutView&) = delete;
FlexLayoutView operator=(const FlexLayoutView&) = delete;
~FlexLayoutView() override;
void SetOrientation(LayoutOrientation orientation);
LayoutOrientation GetOrientation() const;
void SetMainAxisAlignment(LayoutAlignment main_axis_alignment);
LayoutAlignment GetMainAxisAlignment() const;
void SetCrossAxisAlignment(LayoutAlignment cross_axis_alignment);
LayoutAlignment GetCrossAxisAlignment() const;
void SetInteriorMargin(const gfx::Insets& interior_margin);
const gfx::Insets& GetInteriorMargin() const;
void SetMinimumCrossAxisSize(int size);
int GetMinimumCrossAxisSize() const;
void SetCollapseMargins(bool collapse_margins);
bool GetCollapseMargins() const;
void SetIncludeHostInsetsInLayout(bool include_host_insets_in_layout);
bool GetIncludeHostInsetsInLayout() const;
void SetIgnoreDefaultMainAxisMargins(bool ignore_default_main_axis_margins);
bool GetIgnoreDefaultMainAxisMargins() const;
void SetFlexAllocationOrder(FlexAllocationOrder flex_allocation_order);
FlexAllocationOrder GetFlexAllocationOrder() const;
// Returns a flex rule that allows flex layouts to be nested with expected
// behavior.
FlexRule GetDefaultFlexRule() const;
// Moves and uses |value| as the default value for layout property |key|.
template <class T, class U>
void SetDefault(const ui::ClassProperty<T>* key, U&& value) {
layout_->SetDefault(key, value);
}
// Copies and uses |value| as the default value for layout property |key|.
template <class T, class U>
void SetDefault(const ui::ClassProperty<T>* key, const U& value) {
layout_->SetDefault(key, value);
}
private:
FlexLayout* layout_;
};
} // namespace views
#endif // UI_VIEWS_LAYOUT_FLEX_LAYOUT_VIEW_H_
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