5#ifndef UI_GFX_GEOMETRY_INSETS_H_
6#define UI_GFX_GEOMETRY_INSETS_H_
28 constexpr Insets() : top_(0), left_(0), bottom_(0), right_(0) {}
32 bottom_(GetClampedValue(
all,
all)),
33 right_(GetClampedValue(
all,
all)) {}
34 constexpr explicit Insets(
int vertical,
int horizontal)
37 bottom_(GetClampedValue(vertical, vertical)),
38 right_(GetClampedValue(horizontal, horizontal)) {}
39 constexpr Insets(
int top,
int left,
int bottom,
int right)
42 bottom_(GetClampedValue(top, bottom)),
43 right_(GetClampedValue(left, right)) {}
45 constexpr int top()
const {
return top_; }
46 constexpr int left()
const {
return left_; }
47 constexpr int bottom()
const {
return bottom_; }
48 constexpr int right()
const {
return right_; }
52 constexpr int width()
const {
return left_ + right_; }
56 constexpr int height()
const {
return top_ + bottom_; }
67 bottom_ = GetClampedValue(top_, bottom_);
71 right_ = GetClampedValue(left_, right_);
73 void set_bottom(
int bottom) { bottom_ = GetClampedValue(top_, bottom); }
74 void set_right(
int right) { right_ = GetClampedValue(left_, right); }
76 void Set(
int top,
int left,
int bottom,
int right) {
79 bottom_ = GetClampedValue(top_, bottom);
80 right_ = GetClampedValue(left_, right);
84 return top_ == insets.top_ && left_ == insets.left_ &&
85 bottom_ == insets.bottom_ && right_ == insets.right_;
91 top_ = base::ClampAdd(top_, insets.top_);
92 left_ = base::ClampAdd(left_, insets.left_);
93 bottom_ = GetClampedValue(top_, base::ClampAdd(bottom_, insets.bottom_));
94 right_ = GetClampedValue(left_, base::ClampAdd(right_, insets.right_));
98 top_ = base::ClampSub(top_, insets.top_);
99 left_ = base::ClampSub(left_, insets.left_);
100 bottom_ = GetClampedValue(top_, base::ClampSub(bottom_, insets.bottom_));
101 right_ = GetClampedValue(left_, base::ClampSub(right_, insets.right_));
113 return Insets(
static_cast<int>(base::ClampMul(top(), y_scale)),
114 static_cast<int>(base::ClampMul(left(), x_scale)),
115 static_cast<int>(base::ClampMul(bottom(), y_scale)),
116 static_cast<int>(base::ClampMul(right(), x_scale)));
125 return InsetsF(
static_cast<float>(top()),
static_cast<float>(left()),
126 static_cast<float>(bottom()),
static_cast<float>(right()));
140 static constexpr bool AddWouldOverflow(
int a,
int b) {
147 return a > 0 &&
b > 0 &&
149 static_cast<unsigned>(
b);
153 static constexpr bool AddWouldUnderflow(
int a,
int b) {
162 static constexpr int GetClampedValue(
int top_or_left,
int bottom_or_right) {
163 if (AddWouldOverflow(top_or_left, bottom_or_right)) {
165 }
else if (AddWouldUnderflow(top_or_left, bottom_or_right)) {
170 return bottom_or_right;
void Set(int top, int left, int bottom, int right)
constexpr int width() const
constexpr int right() const
void set_right(int right)
constexpr int bottom() const
Insets Scale(float scale) const
constexpr Insets(int vertical, int horizontal)
constexpr Insets(int top, int left, int bottom, int right)
Insets Scale(float x_scale, float y_scale) const
constexpr Size size() const
bool operator!=(const Insets &insets) const
void set_bottom(int bottom)
constexpr int top() const
constexpr Insets(int all)
constexpr int height() const
constexpr int left() const
void operator+=(const Insets &insets)
void operator-=(const Insets &insets)
bool operator==(const Insets &insets) const
static float max(float r, float g, float b)
static float min(float r, float g, float b)
constexpr ClampedNumeric< typename UnderlyingType< T >::type > MakeClampedNum(const T value)
Insets operator+(Insets lhs, const Insets &rhs)
Insets operator-(Insets lhs, const Insets &rhs)
static std::string ToString(CompilerBackend::Type type)
SIT bool all(const Vec< 1, T > &x)