OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_GFX_GEOMETRY_INSETS_H_ | 5 #ifndef UI_GFX_GEOMETRY_INSETS_H_ |
6 #define UI_GFX_GEOMETRY_INSETS_H_ | 6 #define UI_GFX_GEOMETRY_INSETS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "ui/gfx/geometry/insets_f.h" | 10 #include "ui/gfx/geometry/insets_f.h" |
11 #include "ui/gfx/gfx_export.h" | 11 #include "ui/gfx/gfx_export.h" |
12 | 12 |
13 namespace gfx { | 13 namespace gfx { |
14 | 14 |
15 class Vector2d; | |
16 | |
15 // Represents the widths of the four borders or margins of an unspecified | 17 // Represents the widths of the four borders or margins of an unspecified |
16 // rectangle. An Insets stores the thickness of the top, left, bottom and right | 18 // rectangle. An Insets stores the thickness of the top, left, bottom and right |
17 // edges, without storing the actual size and position of the rectangle itself. | 19 // edges, without storing the actual size and position of the rectangle itself. |
18 // | 20 // |
19 // This can be used to represent a space within a rectangle, by "shrinking" the | 21 // This can be used to represent a space within a rectangle, by "shrinking" the |
20 // rectangle by the inset amount on all four sides. Alternatively, it can | 22 // rectangle by the inset amount on all four sides. Alternatively, it can |
21 // represent a border that has a different thickness on each side. | 23 // represent a border that has a different thickness on each side. |
22 class GFX_EXPORT Insets { | 24 class GFX_EXPORT Insets { |
23 public: | 25 public: |
24 constexpr Insets() : top_(0), left_(0), bottom_(0), right_(0) {} | 26 constexpr Insets() : top_(0), left_(0), bottom_(0), right_(0) {} |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 return Scale(scale, scale); | 88 return Scale(scale, scale); |
87 } | 89 } |
88 | 90 |
89 Insets Scale(float x_scale, float y_scale) const { | 91 Insets Scale(float x_scale, float y_scale) const { |
90 return Insets(static_cast<int>(top() * y_scale), | 92 return Insets(static_cast<int>(top() * y_scale), |
91 static_cast<int>(left() * x_scale), | 93 static_cast<int>(left() * x_scale), |
92 static_cast<int>(bottom() * y_scale), | 94 static_cast<int>(bottom() * y_scale), |
93 static_cast<int>(right() * x_scale)); | 95 static_cast<int>(right() * x_scale)); |
94 } | 96 } |
95 | 97 |
98 Insets Offset(const gfx::Vector2d& vector) const; | |
danakj
2016/10/29 00:45:53
Can you leave a comment explaining in more detail
Evan Stade
2016/11/01 16:26:23
Done.
| |
99 | |
96 operator InsetsF() const { | 100 operator InsetsF() const { |
97 return InsetsF(static_cast<float>(top()), static_cast<float>(left()), | 101 return InsetsF(static_cast<float>(top()), static_cast<float>(left()), |
98 static_cast<float>(bottom()), static_cast<float>(right())); | 102 static_cast<float>(bottom()), static_cast<float>(right())); |
99 } | 103 } |
100 | 104 |
101 // Returns a string representation of the insets. | 105 // Returns a string representation of the insets. |
102 std::string ToString() const; | 106 std::string ToString() const; |
103 | 107 |
104 private: | 108 private: |
105 int top_; | 109 int top_; |
106 int left_; | 110 int left_; |
107 int bottom_; | 111 int bottom_; |
108 int right_; | 112 int right_; |
109 }; | 113 }; |
110 | 114 |
111 inline Insets operator+(Insets lhs, const Insets& rhs) { | 115 inline Insets operator+(Insets lhs, const Insets& rhs) { |
112 lhs += rhs; | 116 lhs += rhs; |
113 return lhs; | 117 return lhs; |
114 } | 118 } |
115 | 119 |
116 inline Insets operator-(Insets lhs, const Insets& rhs) { | 120 inline Insets operator-(Insets lhs, const Insets& rhs) { |
117 lhs -= rhs; | 121 lhs -= rhs; |
118 return lhs; | 122 return lhs; |
119 } | 123 } |
120 | 124 |
121 } // namespace gfx | 125 } // namespace gfx |
122 | 126 |
123 #endif // UI_GFX_GEOMETRY_INSETS_H_ | 127 #endif // UI_GFX_GEOMETRY_INSETS_H_ |
OLD | NEW |