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