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_F_H_ | 5 #ifndef UI_GFX_GEOMETRY_INSETS_F_H_ |
6 #define UI_GFX_GEOMETRY_INSETS_F_H_ | 6 #define UI_GFX_GEOMETRY_INSETS_F_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "ui/gfx/gfx_export.h" | 10 #include "ui/gfx/gfx_export.h" |
11 | 11 |
12 namespace gfx { | 12 namespace gfx { |
13 | 13 |
14 // A floating point version of gfx::Insets. | 14 // A floating point version of gfx::Insets. |
15 class GFX_EXPORT InsetsF { | 15 class GFX_EXPORT InsetsF { |
16 public: | 16 public: |
17 InsetsF(); | 17 constexpr InsetsF() : top_(0.f), left_(0.f), bottom_(0.f), right_(0.f) {} |
18 explicit InsetsF(float all); | 18 constexpr explicit InsetsF(float all) |
19 InsetsF(float vertical, float horizontal); | 19 : top_(all), left_(all), bottom_(all), right_(all) {} |
20 InsetsF(float top, float left, float bottom, float right); | 20 constexpr InsetsF(float vertical, float horizontal) |
| 21 : top_(vertical), |
| 22 left_(horizontal), |
| 23 bottom_(vertical), |
| 24 right_(horizontal) {} |
| 25 constexpr InsetsF(float top, float left, float bottom, float right) |
| 26 : top_(top), left_(left), bottom_(bottom), right_(right) {} |
21 | 27 |
22 ~InsetsF(); | 28 constexpr float top() const { return top_; } |
23 | 29 constexpr float left() const { return left_; } |
24 float top() const { return top_; } | 30 constexpr float bottom() const { return bottom_; } |
25 float left() const { return left_; } | 31 constexpr float right() const { return right_; } |
26 float bottom() const { return bottom_; } | |
27 float right() const { return right_; } | |
28 | 32 |
29 // Returns the total width taken up by the insets, which is the sum of the | 33 // Returns the total width taken up by the insets, which is the sum of the |
30 // left and right insets. | 34 // left and right insets. |
31 float width() const { return left_ + right_; } | 35 constexpr float width() const { return left_ + right_; } |
32 | 36 |
33 // Returns the total height taken up by the insets, which is the sum of the | 37 // Returns the total height taken up by the insets, which is the sum of the |
34 // top and bottom insets. | 38 // top and bottom insets. |
35 float height() const { return top_ + bottom_; } | 39 constexpr float height() const { return top_ + bottom_; } |
36 | 40 |
37 // Returns true if the insets are empty. | 41 // Returns true if the insets are empty. |
38 bool IsEmpty() const { return width() == 0.f && height() == 0.f; } | 42 bool IsEmpty() const { return width() == 0.f && height() == 0.f; } |
39 | 43 |
40 void Set(float top, float left, float bottom, float right) { | 44 void Set(float top, float left, float bottom, float right) { |
41 top_ = top; | 45 top_ = top; |
42 left_ = left; | 46 left_ = left; |
43 bottom_ = bottom; | 47 bottom_ = bottom; |
44 right_ = right; | 48 right_ = right; |
45 } | 49 } |
46 | 50 |
47 bool operator==(const InsetsF& insets) const { | 51 bool operator==(const InsetsF& insets) const { |
48 return top_ == insets.top_ && left_ == insets.left_ && | 52 return top_ == insets.top_ && left_ == insets.left_ && |
49 bottom_ == insets.bottom_ && right_ == insets.right_; | 53 bottom_ == insets.bottom_ && right_ == insets.right_; |
50 } | 54 } |
51 | 55 |
52 bool operator!=(const InsetsF& insets) const { | 56 bool operator!=(const InsetsF& insets) const { |
53 return !(*this == insets); | 57 return !(*this == insets); |
54 } | 58 } |
55 | 59 |
56 void operator+=(const InsetsF& insets) { | 60 void operator+=(const InsetsF& insets) { |
57 top_ += insets.top_; | 61 top_ += insets.top_; |
58 left_ += insets.left_; | 62 left_ += insets.left_; |
59 bottom_ += insets.bottom_; | 63 bottom_ += insets.bottom_; |
60 right_ += insets.right_; | 64 right_ += insets.right_; |
61 } | 65 } |
62 | 66 |
| 67 void operator-=(const InsetsF& insets) { |
| 68 top_ -= insets.top_; |
| 69 left_ -= insets.left_; |
| 70 bottom_ -= insets.bottom_; |
| 71 right_ -= insets.right_; |
| 72 } |
| 73 |
63 InsetsF operator-() const { | 74 InsetsF operator-() const { |
64 return InsetsF(-top_, -left_, -bottom_, -right_); | 75 return InsetsF(-top_, -left_, -bottom_, -right_); |
65 } | 76 } |
66 | 77 |
67 // Returns a string representation of the insets. | 78 // Returns a string representation of the insets. |
68 std::string ToString() const; | 79 std::string ToString() const; |
69 | 80 |
70 private: | 81 private: |
71 float top_; | 82 float top_; |
72 float left_; | 83 float left_; |
73 float bottom_; | 84 float bottom_; |
74 float right_; | 85 float right_; |
75 }; | 86 }; |
76 | 87 |
| 88 inline InsetsF operator+(InsetsF lhs, const InsetsF& rhs) { |
| 89 lhs += rhs; |
| 90 return lhs; |
| 91 } |
| 92 |
| 93 inline InsetsF operator-(InsetsF lhs, const InsetsF& rhs) { |
| 94 lhs -= rhs; |
| 95 return lhs; |
| 96 } |
| 97 |
77 } // namespace gfx | 98 } // namespace gfx |
78 | 99 |
79 #endif // UI_GFX_GEOMETRY_INSETS_F_H_ | 100 #endif // UI_GFX_GEOMETRY_INSETS_F_H_ |
OLD | NEW |