From e311fbb79754fffc68ae1e2289672fca8bd63f0a Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Fri, 15 Jun 2018 11:25:13 -0700 Subject: [PATCH] Fabric: CornerInsets: Graphical primitive for rect-corner-specific values Summary: CornerInsets is something like EdgeInsets but about corners instead of edges. Reviewed By: fkgozali Differential Revision: D8344062 fbshipit-source-id: 9bf7a8696fba96e3124cb15e8e84093c1f4f8747 --- ReactCommon/fabric/graphics/Geometry.h | 20 +++++++++++++++ ReactCommon/fabric/graphics/conversions.h | 30 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/ReactCommon/fabric/graphics/Geometry.h b/ReactCommon/fabric/graphics/Geometry.h index 9c198c4be..e44dba31e 100644 --- a/ReactCommon/fabric/graphics/Geometry.h +++ b/ReactCommon/fabric/graphics/Geometry.h @@ -125,5 +125,25 @@ struct EdgeInsets { } }; +/* + * CornerInsets + */ +struct CornerInsets { + Float topLeft {0}; + Float topRight {0}; + Float bottomLeft {0}; + Float bottomRight {0}; + + bool operator ==(const CornerInsets& rhs) const { + return + std::tie(this->topLeft, this->topRight, this->bottomLeft, this->bottomRight) == + std::tie(rhs.topLeft, rhs.topRight, rhs.bottomLeft, rhs.bottomRight); + } + + bool operator !=(const CornerInsets& rhs) const { + return !(*this == rhs); + } +}; + } // namespace react } // namespace facebook diff --git a/ReactCommon/fabric/graphics/conversions.h b/ReactCommon/fabric/graphics/conversions.h index 061725c01..7c79d0b38 100644 --- a/ReactCommon/fabric/graphics/conversions.h +++ b/ReactCommon/fabric/graphics/conversions.h @@ -105,6 +105,28 @@ inline void fromDynamic(const folly::dynamic &value, EdgeInsets &result) { abort(); } +inline void fromDynamic(const folly::dynamic &value, CornerInsets &result) { + if (value.isObject()) { + result = CornerInsets { + (Float)value["topLeft"].asDouble(), + (Float)value["topRight"].asDouble(), + (Float)value["bottomLeft"].asDouble(), + (Float)value["bottomRight"].asDouble() + }; + return; + } + if (value.isArray()) { + result = CornerInsets { + (Float)value[0].asDouble(), + (Float)value[1].asDouble(), + (Float)value[2].asDouble(), + (Float)value[3].asDouble() + }; + return; + } + abort(); +} + inline std::string toString(const Point &point) { return "{" + folly::to(point.x) + ", " + folly::to(point.y) + "}"; } @@ -125,5 +147,13 @@ inline std::string toString(const EdgeInsets &edgeInsets) { folly::to(edgeInsets.bottom) + "}"; } +inline std::string toString(const CornerInsets &cornerInsets) { + return "{" + + folly::to(cornerInsets.topLeft) + ", " + + folly::to(cornerInsets.topRight) + ", " + + folly::to(cornerInsets.bottomLeft) + ", " + + folly::to(cornerInsets.bottomRight) + "}"; +} + } // namespace react } // namespace facebook