outsets.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2022 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. #ifndef UI_GFX_GEOMETRY_OUTSETS_H_
  5. #define UI_GFX_GEOMETRY_OUTSETS_H_
  6. #include "base/numerics/clamped_math.h"
  7. #include "ui/gfx/geometry/geometry_export.h"
  8. #include "ui/gfx/geometry/insets.h"
  9. #include "ui/gfx/geometry/insets_outsets_base.h"
  10. namespace gfx {
  11. // This can be used to represent a space surrounding a rectangle, by
  12. // "expanding" the rectangle by the outset amount on all four sides.
  13. class Outsets : public InsetsOutsetsBase<Outsets> {
  14. public:
  15. using InsetsOutsetsBase::InsetsOutsetsBase;
  16. // Conversion from Outsets to Insets negates all components.
  17. Insets ToInsets() const {
  18. return Insets()
  19. .set_left_right(-left(), -right())
  20. .set_top_bottom(-top(), -bottom());
  21. }
  22. };
  23. inline Outsets operator+(Outsets lhs, const Outsets& rhs) {
  24. lhs += rhs;
  25. return lhs;
  26. }
  27. inline Outsets operator-(Outsets lhs, const Outsets& rhs) {
  28. lhs -= rhs;
  29. return lhs;
  30. }
  31. // This is declared here for use in gtest-based unit tests but is defined in
  32. // the //ui/gfx:test_support target. Depend on that to use this in your unit
  33. // test. This should not be used in production code - call ToString() instead.
  34. void PrintTo(const Outsets&, ::std::ostream* os);
  35. } // namespace gfx
  36. #endif // UI_GFX_GEOMETRY_OUTSETS_H_