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

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

Issue 360213002: Add Flex to views::BoxLayout. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comment Created 6 years, 5 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
Index: ui/views/layout/box_layout.h
diff --git a/ui/views/layout/box_layout.h b/ui/views/layout/box_layout.h
index 54fa502eb569ef60643aaffd84962c3d326cfc7c..28124a4e5c14fdbf178e4a7e7d8f4d3abbce9934 100644
--- a/ui/views/layout/box_layout.h
+++ b/ui/views/layout/box_layout.h
@@ -5,6 +5,8 @@
#ifndef UI_VIEWS_LAYOUT_BOX_LAYOUT_H_
#define UI_VIEWS_LAYOUT_BOX_LAYOUT_H_
+#include <map>
+
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ui/gfx/insets.h"
@@ -38,11 +40,6 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager {
MAIN_AXIS_ALIGNMENT_START,
MAIN_AXIS_ALIGNMENT_CENTER,
MAIN_AXIS_ALIGNMENT_END,
-
- // This distributes extra space among the child views. This increases the
- // size of child views along the main axis rather than the space between
- // them.
- MAIN_AXIS_ALIGNMENT_FILL,
// TODO(calamity): Add MAIN_AXIS_ALIGNMENT_JUSTIFY which spreads blank space
// in-between the child views.
};
@@ -80,6 +77,24 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager {
inside_border_insets_ = insets;
}
+ // Sets the flex weight for the view at |index|. Using the preferred size as
+ // the basis, free space along the main axis is distributed to views in the
+ // ratio of their flex weights. Similarly, if the views will overflow the
+ // parent, space is subtracted in these ratios.
+ //
+ // A flex of 0 means this view is not resized. Flex values must not be
+ // negative.
+ // Flex weights are set for the index and will not rearrange when the host's
+ // views do.
+ void SetFlexForViewAt(int index, int flex);
sky 2014/07/18 15:54:00 Using indices like this is fragile and I suspect p
calamity 2014/07/22 05:35:15 Done.
+
+ // Clears the flex for the view at |index|, causing it to use the default
+ // flex.
+ void ClearFlexForViewAt(int index);
+
+ // Sets the flex for views to use when none is specified.
+ void SetDefaultFlex(int default_flex);
+
// Overridden from views::LayoutManager:
virtual void Layout(View* host) OVERRIDE;
virtual gfx::Size GetPreferredSize(const View* host) const OVERRIDE;
@@ -87,6 +102,9 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager {
int width) const OVERRIDE;
private:
+ // Returns the flex for the specified index.
+ int GetFlexForViewAt(int index);
sky 2014/07/18 15:54:00 const
calamity 2014/07/22 05:35:14 Done.
+
// Returns the size and position along the main axis of |rect|.
int MainAxisSize(const gfx::Rect& rect) const;
int MainAxisPosition(const gfx::Rect& rect) const;
@@ -134,6 +152,12 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager {
// CROSS_AXIS_ALIGNMENT_STRETCH by default.
CrossAxisAlignment cross_axis_alignment_;
+ // A map of view indexes to flex weights.
+ std::map<int, int> flex_map_;
+
+ // The flex weight for views if none is set. Defaults to 0.
+ int default_flex_;
+
DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout);
};

Powered by Google App Engine
This is Rietveld 408576698