Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: ui/views/layout/box_layout.h

Issue 2836313002: BoxLayout now suports per-view margins. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/views/layout/box_layout.cc » ('j') | ui/views/layout/box_layout.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/layout/box_layout.h
diff --git a/ui/views/layout/box_layout.h b/ui/views/layout/box_layout.h
index 9a87984d51f77cec0caa488860fa6dc1986f9e28..2705646140c0e4b6dc9d15c2b253291d1ea0697f 100644
--- a/ui/views/layout/box_layout.h
+++ b/ui/views/layout/box_layout.h
@@ -97,6 +97,14 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager {
// Sets the flex for views to use when none is specified.
void SetDefaultFlex(int default_flex);
+ // Clears the margins for the given |view|.
+ void ClearMarginsForView(const View* view);
+
+ // Sets the margins for a specific |view|. The margins are the area around
+ // the outside of the given view into which no other view is placed. This is
+ // in addition to any other horizontal or vertical spacing.
+ void SetViewMargins(const View* view, const gfx::Insets& margins);
sky 2017/04/25 17:28:58 Is there a reason you aren't using a UI property f
+
// Overridden from views::LayoutManager:
void Installed(View* host) override;
void ViewRemoved(View* host, View* view) override;
@@ -105,6 +113,25 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager {
int GetPreferredHeightForWidth(const View* host, int width) const override;
private:
+ struct ViewWrapper {
sky 2017/04/25 17:28:59 Please add a description of this.
+ ViewWrapper();
+ ViewWrapper(const BoxLayout* layout, const View* view);
+ ViewWrapper(const ViewWrapper& wrapper);
+ ~ViewWrapper();
+ gfx::Size GetPreferredSize() const;
+ void SetBoundsRect(const gfx::Rect& bounds);
+ const View* view() const { return view_; }
+ bool visible() const;
+
+ private:
+ const View* view_;
+ const BoxLayout* layout_;
+ gfx::Insets margins_;
+ };
+ using MarginMap = std::map<const View*, gfx::Insets>;
+ using FlexMap = std::map<const View*, int>;
+ friend struct ViewWrappper;
+
// Returns the flex for the specified |view|.
int GetFlexForView(const View* view) const;
@@ -139,6 +166,9 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager {
// child views.
gfx::Size NonChildSize(const View* host) const;
+ // Returns the margins for the specified |view|.
+ gfx::Insets GetViewMargins(const View* view) const;
+
const Orientation orientation_;
// Spacing between child views and host view border.
@@ -156,7 +186,7 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager {
CrossAxisAlignment cross_axis_alignment_;
// A map of views to their flex weights.
- std::map<const View*, int> flex_map_;
+ FlexMap flex_map_;
// The flex weight for views if none is set. Defaults to 0.
int default_flex_;
@@ -167,6 +197,9 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager {
// The view that this BoxLayout is managing the layout for.
views::View* host_;
+ // Unique margins around specific views.
+ MarginMap margin_map_;
+
DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout);
};
« no previous file with comments | « no previous file | ui/views/layout/box_layout.cc » ('j') | ui/views/layout/box_layout.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698