Fabric/Graphics: New graphic values conversion functions and type refinments

Summary: Quite trivial. We need this to debug print LayoutMetrics.

Reviewed By: fkgozali

Differential Revision: D7607417

fbshipit-source-id: f4fa52ad04be9757545a8ac627db184f171288e5
This commit is contained in:
Valentin Shergin
2018-04-26 18:03:06 -07:00
committed by Facebook Github Bot
parent f72df7a6e7
commit 88c368b488
2 changed files with 36 additions and 4 deletions
@@ -7,10 +7,12 @@
#include "graphicValuesConversions.h"
#include <folly/Conv.h>
namespace facebook {
namespace react {
SharedColor colorFromDynamic(folly::dynamic value) {
SharedColor colorFromDynamic(const folly::dynamic &value) {
float red;
float green;
float blue;
@@ -37,7 +39,7 @@ SharedColor colorFromDynamic(folly::dynamic value) {
return colorFromComponents(red, green, blue, alpha);
}
std::string colorNameFromColor(SharedColor value) {
std::string colorNameFromColor(const SharedColor &value) {
ColorComponents components = colorComponentsFromColor(value);
const float ratio = 256;
return "rgba(" +
@@ -47,5 +49,25 @@ std::string colorNameFromColor(SharedColor value) {
folly::to<std::string>(round(components.alpha * ratio)) + ")";
}
std::string stringFromPoint(const Point &point) {
return "{" + folly::to<std::string>(point.x) + ", " + folly::to<std::string>(point.y) + "}";
}
std::string stringFromSize(const Size &size) {
return "{" + folly::to<std::string>(size.width) + ", " + folly::to<std::string>(size.height) + "}";
}
std::string stringFromRect(const Rect &rect) {
return "{" + stringFromPoint(rect.origin) + ", " + stringFromSize(rect.size) + "}";
}
std::string stringFromEdgeInsets(const EdgeInsets &edgeInsets) {
return "{" +
folly::to<std::string>(edgeInsets.left) + ", " +
folly::to<std::string>(edgeInsets.top) + ", " +
folly::to<std::string>(edgeInsets.right) + ", " +
folly::to<std::string>(edgeInsets.bottom) + "}";
}
} // namespace react
} // namespace facebook
@@ -9,12 +9,22 @@
#include <folly/dynamic.h>
#include <fabric/graphics/Color.h>
#include <fabric/graphics/Geometry.h>
namespace facebook {
namespace react {
SharedColor colorFromDynamic(folly::dynamic value);
std::string colorNameFromColor(SharedColor value);
#pragma mark - Color
SharedColor colorFromDynamic(const folly::dynamic &value);
std::string colorNameFromColor(const SharedColor &value);
#pragma mark - Geometry
std::string stringFromPoint(const Point &point);
std::string stringFromSize(const Size &size);
std::string stringFromRect(const Rect &rect);
std::string stringFromEdgeInsets(const EdgeInsets &edgeInsets);
} // namespace react
} // namespace facebook