Cleanup entrypoints
This commit is contained in:
38
javascript/src_native/Config.cc
Normal file
38
javascript/src_native/Config.cc
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
#include "./Config.hh"
|
||||
|
||||
/* static */ Config* Config::create(void) {
|
||||
return new Config();
|
||||
}
|
||||
|
||||
/* static */ void Config::destroy(Config* node) {
|
||||
delete node;
|
||||
}
|
||||
|
||||
Config::Config(void) : m_config(YGConfigNew()) {}
|
||||
|
||||
Config::~Config(void) {
|
||||
YGConfigFree(m_config);
|
||||
}
|
||||
|
||||
void Config::setExperimentalFeatureEnabled(int feature, bool enabled) {
|
||||
YGConfigSetExperimentalFeatureEnabled(
|
||||
m_config, static_cast<YGExperimentalFeature>(feature), enabled);
|
||||
}
|
||||
|
||||
void Config::setPointScaleFactor(float pixelsInPoint) {
|
||||
YGConfigSetPointScaleFactor(m_config, pixelsInPoint);
|
||||
}
|
||||
|
||||
bool Config::isExperimentalFeatureEnabled(int feature) const {
|
||||
return YGConfigIsExperimentalFeatureEnabled(
|
||||
m_config, static_cast<YGExperimentalFeature>(feature));
|
||||
}
|
41
javascript/src_native/Config.hh
Normal file
41
javascript/src_native/Config.hh
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
class Config {
|
||||
|
||||
friend class Node;
|
||||
|
||||
public:
|
||||
static Config* create(void);
|
||||
|
||||
static void destroy(Config* config);
|
||||
|
||||
private:
|
||||
Config(void);
|
||||
|
||||
public:
|
||||
~Config(void);
|
||||
|
||||
public: // Prevent accidental copy
|
||||
Config(Config const&) = delete;
|
||||
|
||||
Config const& operator=(Config const&) = delete;
|
||||
|
||||
public: // Setters
|
||||
void setExperimentalFeatureEnabled(int feature, bool enabled);
|
||||
void setPointScaleFactor(float pixelsInPoint);
|
||||
|
||||
public: // Getters
|
||||
bool isExperimentalFeatureEnabled(int feature) const;
|
||||
|
||||
private:
|
||||
YGConfigRef m_config;
|
||||
};
|
19
javascript/src_native/Layout.hh
Normal file
19
javascript/src_native/Layout.hh
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
struct Layout {
|
||||
double left;
|
||||
double right;
|
||||
|
||||
double top;
|
||||
double bottom;
|
||||
|
||||
double width;
|
||||
double height;
|
||||
};
|
470
javascript/src_native/Node.cc
Normal file
470
javascript/src_native/Node.cc
Normal file
@@ -0,0 +1,470 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
#include "./Node.hh"
|
||||
#include "./Layout.hh"
|
||||
#include "./Size.hh"
|
||||
#include "./Config.hh"
|
||||
|
||||
static YGSize globalMeasureFunc(
|
||||
YGNodeRef nodeRef,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
Node const& node = *reinterpret_cast<Node const*>(YGNodeGetContext(nodeRef));
|
||||
|
||||
Size size = node.callMeasureFunc(width, widthMode, height, heightMode);
|
||||
YGSize ygSize = {
|
||||
static_cast<float>(size.width), static_cast<float>(size.height)};
|
||||
|
||||
return ygSize;
|
||||
}
|
||||
|
||||
static void globalDirtiedFunc(YGNodeRef nodeRef) {
|
||||
Node const& node = *reinterpret_cast<Node const*>(YGNodeGetContext(nodeRef));
|
||||
|
||||
node.callDirtiedFunc();
|
||||
}
|
||||
|
||||
/* static */ Node* Node::createDefault(void) {
|
||||
return new Node(nullptr);
|
||||
}
|
||||
|
||||
/* static */ Node* Node::createWithConfig(Config* config) {
|
||||
return new Node(config);
|
||||
}
|
||||
|
||||
/* static */ void Node::destroy(Node* node) {
|
||||
delete node;
|
||||
}
|
||||
|
||||
/* static */ Node* Node::fromYGNode(YGNodeRef nodeRef) {
|
||||
return reinterpret_cast<Node*>(YGNodeGetContext(nodeRef));
|
||||
}
|
||||
|
||||
Node::Node(Config* config)
|
||||
: m_node(
|
||||
config != nullptr ? YGNodeNewWithConfig(config->m_config)
|
||||
: YGNodeNew()),
|
||||
m_measureFunc(nullptr),
|
||||
m_dirtiedFunc(nullptr) {
|
||||
YGNodeSetContext(m_node, reinterpret_cast<void*>(this));
|
||||
}
|
||||
|
||||
Node::~Node(void) {
|
||||
YGNodeFree(m_node);
|
||||
}
|
||||
|
||||
void Node::reset(void) {
|
||||
m_measureFunc.reset(nullptr);
|
||||
m_dirtiedFunc.reset(nullptr);
|
||||
|
||||
YGNodeReset(m_node);
|
||||
}
|
||||
|
||||
void Node::copyStyle(Node const& other) {
|
||||
YGNodeCopyStyle(m_node, other.m_node);
|
||||
}
|
||||
|
||||
void Node::setPositionType(int positionType) {
|
||||
YGNodeStyleSetPositionType(m_node, static_cast<YGPositionType>(positionType));
|
||||
}
|
||||
|
||||
void Node::setPosition(int edge, double position) {
|
||||
YGNodeStyleSetPosition(m_node, static_cast<YGEdge>(edge), position);
|
||||
}
|
||||
|
||||
void Node::setPositionPercent(int edge, double position) {
|
||||
YGNodeStyleSetPositionPercent(m_node, static_cast<YGEdge>(edge), position);
|
||||
}
|
||||
|
||||
void Node::setAlignContent(int alignContent) {
|
||||
YGNodeStyleSetAlignContent(m_node, static_cast<YGAlign>(alignContent));
|
||||
}
|
||||
|
||||
void Node::setAlignItems(int alignItems) {
|
||||
YGNodeStyleSetAlignItems(m_node, static_cast<YGAlign>(alignItems));
|
||||
}
|
||||
|
||||
void Node::setAlignSelf(int alignSelf) {
|
||||
YGNodeStyleSetAlignSelf(m_node, static_cast<YGAlign>(alignSelf));
|
||||
}
|
||||
|
||||
void Node::setFlexDirection(int flexDirection) {
|
||||
YGNodeStyleSetFlexDirection(
|
||||
m_node, static_cast<YGFlexDirection>(flexDirection));
|
||||
}
|
||||
|
||||
void Node::setFlexWrap(int flexWrap) {
|
||||
YGNodeStyleSetFlexWrap(m_node, static_cast<YGWrap>(flexWrap));
|
||||
}
|
||||
|
||||
void Node::setJustifyContent(int justifyContent) {
|
||||
YGNodeStyleSetJustifyContent(m_node, static_cast<YGJustify>(justifyContent));
|
||||
}
|
||||
|
||||
void Node::setMargin(int edge, double margin) {
|
||||
YGNodeStyleSetMargin(m_node, static_cast<YGEdge>(edge), margin);
|
||||
}
|
||||
|
||||
void Node::setMarginPercent(int edge, double margin) {
|
||||
YGNodeStyleSetMarginPercent(m_node, static_cast<YGEdge>(edge), margin);
|
||||
}
|
||||
|
||||
void Node::setMarginAuto(int edge) {
|
||||
YGNodeStyleSetMarginAuto(m_node, static_cast<YGEdge>(edge));
|
||||
}
|
||||
|
||||
void Node::setOverflow(int overflow) {
|
||||
YGNodeStyleSetOverflow(m_node, static_cast<YGOverflow>(overflow));
|
||||
}
|
||||
|
||||
void Node::setDisplay(int display) {
|
||||
YGNodeStyleSetDisplay(m_node, static_cast<YGDisplay>(display));
|
||||
}
|
||||
|
||||
void Node::setFlex(double flex) {
|
||||
YGNodeStyleSetFlex(m_node, flex);
|
||||
}
|
||||
|
||||
void Node::setFlexBasis(double flexBasis) {
|
||||
YGNodeStyleSetFlexBasis(m_node, flexBasis);
|
||||
}
|
||||
|
||||
void Node::setFlexBasisPercent(double flexBasis) {
|
||||
YGNodeStyleSetFlexBasisPercent(m_node, flexBasis);
|
||||
}
|
||||
|
||||
void Node::setFlexBasisAuto() {
|
||||
YGNodeStyleSetFlexBasisAuto(m_node);
|
||||
}
|
||||
|
||||
void Node::setFlexGrow(double flexGrow) {
|
||||
YGNodeStyleSetFlexGrow(m_node, flexGrow);
|
||||
}
|
||||
|
||||
void Node::setFlexShrink(double flexShrink) {
|
||||
YGNodeStyleSetFlexShrink(m_node, flexShrink);
|
||||
}
|
||||
|
||||
void Node::setWidth(double width) {
|
||||
YGNodeStyleSetWidth(m_node, width);
|
||||
}
|
||||
|
||||
void Node::setWidthPercent(double width) {
|
||||
YGNodeStyleSetWidthPercent(m_node, width);
|
||||
}
|
||||
|
||||
void Node::setWidthAuto() {
|
||||
YGNodeStyleSetWidthAuto(m_node);
|
||||
}
|
||||
|
||||
void Node::setHeight(double height) {
|
||||
YGNodeStyleSetHeight(m_node, height);
|
||||
}
|
||||
|
||||
void Node::setHeightPercent(double height) {
|
||||
YGNodeStyleSetHeightPercent(m_node, height);
|
||||
}
|
||||
|
||||
void Node::setHeightAuto() {
|
||||
YGNodeStyleSetHeightAuto(m_node);
|
||||
}
|
||||
|
||||
void Node::setMinWidth(double minWidth) {
|
||||
YGNodeStyleSetMinWidth(m_node, minWidth);
|
||||
}
|
||||
|
||||
void Node::setMinWidthPercent(double minWidth) {
|
||||
YGNodeStyleSetMinWidthPercent(m_node, minWidth);
|
||||
}
|
||||
|
||||
void Node::setMinHeight(double minHeight) {
|
||||
YGNodeStyleSetMinHeight(m_node, minHeight);
|
||||
}
|
||||
|
||||
void Node::setMinHeightPercent(double minHeight) {
|
||||
YGNodeStyleSetMinHeightPercent(m_node, minHeight);
|
||||
}
|
||||
|
||||
void Node::setMaxWidth(double maxWidth) {
|
||||
YGNodeStyleSetMaxWidth(m_node, maxWidth);
|
||||
}
|
||||
|
||||
void Node::setMaxWidthPercent(double maxWidth) {
|
||||
YGNodeStyleSetMaxWidthPercent(m_node, maxWidth);
|
||||
}
|
||||
|
||||
void Node::setMaxHeight(double maxHeight) {
|
||||
YGNodeStyleSetMaxHeight(m_node, maxHeight);
|
||||
}
|
||||
|
||||
void Node::setMaxHeightPercent(double maxHeight) {
|
||||
YGNodeStyleSetMaxHeightPercent(m_node, maxHeight);
|
||||
}
|
||||
|
||||
void Node::setAspectRatio(double aspectRatio) {
|
||||
YGNodeStyleSetAspectRatio(m_node, aspectRatio);
|
||||
}
|
||||
|
||||
void Node::setBorder(int edge, double border) {
|
||||
YGNodeStyleSetBorder(m_node, static_cast<YGEdge>(edge), border);
|
||||
}
|
||||
|
||||
void Node::setPadding(int edge, double padding) {
|
||||
YGNodeStyleSetPadding(m_node, static_cast<YGEdge>(edge), padding);
|
||||
}
|
||||
|
||||
void Node::setPaddingPercent(int edge, double padding) {
|
||||
YGNodeStyleSetPaddingPercent(m_node, static_cast<YGEdge>(edge), padding);
|
||||
}
|
||||
|
||||
void Node::setIsReferenceBaseline(bool isReferenceBaseline) {
|
||||
YGNodeSetIsReferenceBaseline(m_node, isReferenceBaseline);
|
||||
}
|
||||
|
||||
void Node::setGap(int gutter, double gapLength) {
|
||||
YGNodeStyleSetGap(m_node, static_cast<YGGutter>(gutter), gapLength);
|
||||
}
|
||||
|
||||
int Node::getPositionType(void) const {
|
||||
return YGNodeStyleGetPositionType(m_node);
|
||||
}
|
||||
|
||||
Value Node::getPosition(int edge) const {
|
||||
return Value::fromYGValue(
|
||||
YGNodeStyleGetPosition(m_node, static_cast<YGEdge>(edge)));
|
||||
}
|
||||
|
||||
int Node::getAlignContent(void) const {
|
||||
return YGNodeStyleGetAlignContent(m_node);
|
||||
}
|
||||
|
||||
int Node::getAlignItems(void) const {
|
||||
return YGNodeStyleGetAlignItems(m_node);
|
||||
}
|
||||
|
||||
int Node::getAlignSelf(void) const {
|
||||
return YGNodeStyleGetAlignSelf(m_node);
|
||||
}
|
||||
|
||||
int Node::getFlexDirection(void) const {
|
||||
return YGNodeStyleGetFlexDirection(m_node);
|
||||
}
|
||||
|
||||
int Node::getFlexWrap(void) const {
|
||||
return YGNodeStyleGetFlexWrap(m_node);
|
||||
}
|
||||
|
||||
int Node::getJustifyContent(void) const {
|
||||
return YGNodeStyleGetJustifyContent(m_node);
|
||||
}
|
||||
|
||||
Value Node::getMargin(int edge) const {
|
||||
return Value::fromYGValue(
|
||||
YGNodeStyleGetMargin(m_node, static_cast<YGEdge>(edge)));
|
||||
}
|
||||
|
||||
int Node::getOverflow(void) const {
|
||||
return YGNodeStyleGetOverflow(m_node);
|
||||
}
|
||||
|
||||
int Node::getDisplay(void) const {
|
||||
return YGNodeStyleGetDisplay(m_node);
|
||||
}
|
||||
|
||||
Value Node::getFlexBasis(void) const {
|
||||
return Value::fromYGValue(YGNodeStyleGetFlexBasis(m_node));
|
||||
}
|
||||
|
||||
double Node::getFlexGrow(void) const {
|
||||
return YGNodeStyleGetFlexGrow(m_node);
|
||||
}
|
||||
|
||||
double Node::getFlexShrink(void) const {
|
||||
return YGNodeStyleGetFlexShrink(m_node);
|
||||
}
|
||||
|
||||
Value Node::getWidth(void) const {
|
||||
return Value::fromYGValue(YGNodeStyleGetWidth(m_node));
|
||||
}
|
||||
|
||||
Value Node::getHeight(void) const {
|
||||
return Value::fromYGValue(YGNodeStyleGetHeight(m_node));
|
||||
}
|
||||
|
||||
Value Node::getMinWidth(void) const {
|
||||
return Value::fromYGValue(YGNodeStyleGetMinWidth(m_node));
|
||||
}
|
||||
|
||||
Value Node::getMinHeight(void) const {
|
||||
return Value::fromYGValue(YGNodeStyleGetMinHeight(m_node));
|
||||
}
|
||||
|
||||
Value Node::getMaxWidth(void) const {
|
||||
return Value::fromYGValue(YGNodeStyleGetMaxWidth(m_node));
|
||||
}
|
||||
|
||||
Value Node::getMaxHeight(void) const {
|
||||
return Value::fromYGValue(YGNodeStyleGetMaxHeight(m_node));
|
||||
}
|
||||
|
||||
double Node::getAspectRatio(void) const {
|
||||
return YGNodeStyleGetAspectRatio(m_node);
|
||||
}
|
||||
|
||||
double Node::getBorder(int edge) const {
|
||||
return YGNodeStyleGetBorder(m_node, static_cast<YGEdge>(edge));
|
||||
}
|
||||
|
||||
Value Node::getPadding(int edge) const {
|
||||
return Value::fromYGValue(
|
||||
YGNodeStyleGetPadding(m_node, static_cast<YGEdge>(edge)));
|
||||
}
|
||||
|
||||
float Node::getGap(int gutter) {
|
||||
return YGNodeStyleGetGap(m_node, static_cast<YGGutter>(gutter));
|
||||
}
|
||||
|
||||
bool Node::isReferenceBaseline() {
|
||||
return YGNodeIsReferenceBaseline(m_node);
|
||||
}
|
||||
|
||||
void Node::insertChild(Node* child, unsigned index) {
|
||||
YGNodeInsertChild(m_node, child->m_node, index);
|
||||
}
|
||||
|
||||
void Node::removeChild(Node* child) {
|
||||
YGNodeRemoveChild(m_node, child->m_node);
|
||||
}
|
||||
|
||||
unsigned Node::getChildCount(void) const {
|
||||
return YGNodeGetChildCount(m_node);
|
||||
}
|
||||
|
||||
Node* Node::getParent(void) {
|
||||
auto nodePtr = YGNodeGetParent(m_node);
|
||||
|
||||
if (nodePtr == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return Node::fromYGNode(nodePtr);
|
||||
}
|
||||
|
||||
Node* Node::getChild(unsigned index) {
|
||||
auto nodePtr = YGNodeGetChild(m_node, index);
|
||||
|
||||
if (nodePtr == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return Node::fromYGNode(nodePtr);
|
||||
}
|
||||
|
||||
void Node::setMeasureFunc(MeasureCallback* measureFunc) {
|
||||
m_measureFunc.reset(measureFunc);
|
||||
|
||||
YGNodeSetMeasureFunc(m_node, &globalMeasureFunc);
|
||||
}
|
||||
|
||||
void Node::unsetMeasureFunc(void) {
|
||||
m_measureFunc.reset(nullptr);
|
||||
|
||||
YGNodeSetMeasureFunc(m_node, nullptr);
|
||||
}
|
||||
|
||||
Size Node::callMeasureFunc(
|
||||
double width,
|
||||
int widthMode,
|
||||
double height,
|
||||
int heightMode) const {
|
||||
return m_measureFunc->measure(width, widthMode, height, heightMode);
|
||||
}
|
||||
|
||||
void Node::setDirtiedFunc(DirtiedCallback* dirtiedFunc) {
|
||||
m_dirtiedFunc.reset(dirtiedFunc);
|
||||
|
||||
YGNodeSetDirtiedFunc(m_node, &globalDirtiedFunc);
|
||||
}
|
||||
|
||||
void Node::unsetDirtiedFunc(void) {
|
||||
m_dirtiedFunc.reset(nullptr);
|
||||
|
||||
YGNodeSetDirtiedFunc(m_node, nullptr);
|
||||
}
|
||||
|
||||
void Node::callDirtiedFunc(void) const {
|
||||
m_dirtiedFunc->dirtied();
|
||||
}
|
||||
|
||||
void Node::markDirty(void) {
|
||||
YGNodeMarkDirty(m_node);
|
||||
}
|
||||
|
||||
bool Node::isDirty(void) const {
|
||||
return YGNodeIsDirty(m_node);
|
||||
}
|
||||
|
||||
void Node::calculateLayout(double width, double height, int direction) {
|
||||
YGNodeCalculateLayout(
|
||||
m_node, width, height, static_cast<YGDirection>(direction));
|
||||
}
|
||||
|
||||
double Node::getComputedLeft(void) const {
|
||||
return YGNodeLayoutGetLeft(m_node);
|
||||
}
|
||||
|
||||
double Node::getComputedRight(void) const {
|
||||
return YGNodeLayoutGetRight(m_node);
|
||||
}
|
||||
|
||||
double Node::getComputedTop(void) const {
|
||||
return YGNodeLayoutGetTop(m_node);
|
||||
}
|
||||
|
||||
double Node::getComputedBottom(void) const {
|
||||
return YGNodeLayoutGetBottom(m_node);
|
||||
}
|
||||
|
||||
double Node::getComputedWidth(void) const {
|
||||
return YGNodeLayoutGetWidth(m_node);
|
||||
}
|
||||
|
||||
double Node::getComputedHeight(void) const {
|
||||
return YGNodeLayoutGetHeight(m_node);
|
||||
}
|
||||
|
||||
Layout Node::getComputedLayout(void) const {
|
||||
Layout layout;
|
||||
|
||||
layout.left = YGNodeLayoutGetLeft(m_node);
|
||||
layout.right = YGNodeLayoutGetRight(m_node);
|
||||
|
||||
layout.top = YGNodeLayoutGetTop(m_node);
|
||||
layout.bottom = YGNodeLayoutGetBottom(m_node);
|
||||
|
||||
layout.width = YGNodeLayoutGetWidth(m_node);
|
||||
layout.height = YGNodeLayoutGetHeight(m_node);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
double Node::getComputedMargin(int edge) const {
|
||||
return YGNodeLayoutGetMargin(m_node, static_cast<YGEdge>(edge));
|
||||
}
|
||||
|
||||
double Node::getComputedBorder(int edge) const {
|
||||
return YGNodeLayoutGetBorder(m_node, static_cast<YGEdge>(edge));
|
||||
}
|
||||
|
||||
double Node::getComputedPadding(int edge) const {
|
||||
return YGNodeLayoutGetPadding(m_node, static_cast<YGEdge>(edge));
|
||||
}
|
228
javascript/src_native/Node.hh
Normal file
228
javascript/src_native/Node.hh
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <emscripten/bind.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
#include "./Layout.hh"
|
||||
#include "./Size.hh"
|
||||
#include "./Value.hh"
|
||||
#include "./Config.hh"
|
||||
|
||||
class MeasureCallback {
|
||||
public:
|
||||
virtual ~MeasureCallback() {}
|
||||
virtual Size measure(
|
||||
float width,
|
||||
int widthMode,
|
||||
float height,
|
||||
int heightMode) = 0;
|
||||
};
|
||||
|
||||
class MeasureCallbackWrapper : public emscripten::wrapper<MeasureCallback> {
|
||||
public:
|
||||
EMSCRIPTEN_WRAPPER(MeasureCallbackWrapper);
|
||||
Size measure(float width, int widthMode, float height, int heightMode) {
|
||||
return call<Size>("measure", width, widthMode, height, heightMode);
|
||||
}
|
||||
};
|
||||
|
||||
class DirtiedCallback {
|
||||
public:
|
||||
virtual ~DirtiedCallback() {}
|
||||
virtual void dirtied() = 0;
|
||||
};
|
||||
|
||||
class DirtiedCallbackWrapper : public emscripten::wrapper<DirtiedCallback> {
|
||||
public:
|
||||
EMSCRIPTEN_WRAPPER(DirtiedCallbackWrapper);
|
||||
void dirtied() { return call<void>("dirtied"); }
|
||||
};
|
||||
|
||||
class Node {
|
||||
|
||||
public:
|
||||
static Node* createDefault(void);
|
||||
static Node* createWithConfig(Config* config);
|
||||
|
||||
static void destroy(Node* node);
|
||||
|
||||
public:
|
||||
static Node* fromYGNode(YGNodeRef nodeRef);
|
||||
|
||||
private:
|
||||
Node(Config* config);
|
||||
|
||||
public:
|
||||
~Node(void);
|
||||
|
||||
public: // Prevent accidental copy
|
||||
Node(Node const&) = delete;
|
||||
|
||||
Node const& operator=(Node const&) = delete;
|
||||
|
||||
public:
|
||||
void reset(void);
|
||||
|
||||
public: // Style setters
|
||||
void copyStyle(Node const& other);
|
||||
|
||||
void setPositionType(int positionType);
|
||||
void setPosition(int edge, double position);
|
||||
void setPositionPercent(int edge, double position);
|
||||
|
||||
void setAlignContent(int alignContent);
|
||||
void setAlignItems(int alignItems);
|
||||
void setAlignSelf(int alignSelf);
|
||||
void setFlexDirection(int flexDirection);
|
||||
void setFlexWrap(int flexWrap);
|
||||
void setJustifyContent(int justifyContent);
|
||||
|
||||
void setMargin(int edge, double margin);
|
||||
void setMarginPercent(int edge, double margin);
|
||||
void setMarginAuto(int edge);
|
||||
|
||||
void setOverflow(int overflow);
|
||||
void setDisplay(int display);
|
||||
|
||||
void setFlex(double flex);
|
||||
void setFlexBasis(double flexBasis);
|
||||
void setFlexBasisPercent(double flexBasis);
|
||||
void setFlexBasisAuto();
|
||||
void setFlexGrow(double flexGrow);
|
||||
void setFlexShrink(double flexShrink);
|
||||
|
||||
void setWidth(double width);
|
||||
void setWidthPercent(double width);
|
||||
void setWidthAuto();
|
||||
void setHeight(double height);
|
||||
void setHeightPercent(double height);
|
||||
void setHeightAuto();
|
||||
|
||||
void setMinWidth(double minWidth);
|
||||
void setMinWidthPercent(double minWidth);
|
||||
void setMinHeight(double minHeight);
|
||||
void setMinHeightPercent(double minHeight);
|
||||
|
||||
void setMaxWidth(double maxWidth);
|
||||
void setMaxWidthPercent(double maxWidth);
|
||||
void setMaxHeight(double maxHeight);
|
||||
void setMaxHeightPercent(double maxHeight);
|
||||
|
||||
void setAspectRatio(double aspectRatio);
|
||||
|
||||
void setBorder(int edge, double border);
|
||||
|
||||
void setPadding(int edge, double padding);
|
||||
void setPaddingPercent(int edge, double padding);
|
||||
|
||||
void setGap(int gutter, double gapLength);
|
||||
|
||||
public: // Style getters
|
||||
int getPositionType(void) const;
|
||||
Value getPosition(int edge) const;
|
||||
|
||||
int getAlignContent(void) const;
|
||||
int getAlignItems(void) const;
|
||||
int getAlignSelf(void) const;
|
||||
int getFlexDirection(void) const;
|
||||
int getFlexWrap(void) const;
|
||||
int getJustifyContent(void) const;
|
||||
|
||||
Value getMargin(int edge) const;
|
||||
|
||||
int getOverflow(void) const;
|
||||
int getDisplay(void) const;
|
||||
|
||||
Value getFlexBasis(void) const;
|
||||
double getFlexGrow(void) const;
|
||||
double getFlexShrink(void) const;
|
||||
|
||||
Value getWidth(void) const;
|
||||
Value getHeight(void) const;
|
||||
|
||||
Value getMinWidth(void) const;
|
||||
Value getMinHeight(void) const;
|
||||
|
||||
Value getMaxWidth(void) const;
|
||||
Value getMaxHeight(void) const;
|
||||
|
||||
double getAspectRatio(void) const;
|
||||
|
||||
double getBorder(int edge) const;
|
||||
|
||||
Value getPadding(int edge) const;
|
||||
|
||||
float getGap(int gutter);
|
||||
|
||||
public: // Tree hierarchy mutators
|
||||
void insertChild(Node* child, unsigned index);
|
||||
void removeChild(Node* child);
|
||||
|
||||
public: // Tree hierarchy inspectors
|
||||
unsigned getChildCount(void) const;
|
||||
|
||||
// The following functions cannot be const because they could discard const
|
||||
// qualifiers (ex: constNode->getChild(0)->getParent() wouldn't be const)
|
||||
|
||||
Node* getParent(void);
|
||||
Node* getChild(unsigned index);
|
||||
|
||||
public: // Measure func mutators
|
||||
void setMeasureFunc(MeasureCallback* measureFunc);
|
||||
void unsetMeasureFunc(void);
|
||||
|
||||
public: // Measure func inspectors
|
||||
Size callMeasureFunc(
|
||||
double width,
|
||||
int widthMode,
|
||||
double height,
|
||||
int heightMode) const;
|
||||
|
||||
public: // Dirtied func mutators
|
||||
void setDirtiedFunc(DirtiedCallback* dirtiedFunc);
|
||||
void unsetDirtiedFunc(void);
|
||||
|
||||
public: // Dirtied func inspectors
|
||||
void callDirtiedFunc(void) const;
|
||||
|
||||
public: // Dirtiness accessors
|
||||
void markDirty(void);
|
||||
bool isDirty(void) const;
|
||||
|
||||
public: // Layout mutators
|
||||
void calculateLayout(double width, double height, int direction);
|
||||
|
||||
public: // Layout inspectors
|
||||
double getComputedLeft(void) const;
|
||||
double getComputedRight(void) const;
|
||||
|
||||
double getComputedTop(void) const;
|
||||
double getComputedBottom(void) const;
|
||||
|
||||
double getComputedWidth(void) const;
|
||||
double getComputedHeight(void) const;
|
||||
|
||||
Layout getComputedLayout(void) const;
|
||||
|
||||
double getComputedMargin(int edge) const;
|
||||
double getComputedBorder(int edge) const;
|
||||
double getComputedPadding(int edge) const;
|
||||
|
||||
public:
|
||||
void setIsReferenceBaseline(bool isReferenceBaseline);
|
||||
bool isReferenceBaseline();
|
||||
|
||||
YGNodeRef m_node;
|
||||
|
||||
std::unique_ptr<MeasureCallback> m_measureFunc;
|
||||
std::unique_ptr<DirtiedCallback> m_dirtiedFunc;
|
||||
};
|
17
javascript/src_native/Size.hh
Normal file
17
javascript/src_native/Size.hh
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
struct Size {
|
||||
double width;
|
||||
double height;
|
||||
|
||||
Size(void) : width(0.0), height(0.0) {}
|
||||
|
||||
Size(double width, double height) : width(width), height(height) {}
|
||||
};
|
23
javascript/src_native/Value.hh
Normal file
23
javascript/src_native/Value.hh
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
struct Value {
|
||||
static Value fromYGValue(YGValue const& ygValue) {
|
||||
return Value(static_cast<int>(ygValue.unit), ygValue.value);
|
||||
}
|
||||
|
||||
int unit;
|
||||
double value;
|
||||
|
||||
Value(void) : unit(YGUnitUndefined), value(0.0) {}
|
||||
|
||||
Value(int unit, double value) : unit(unit), value(value) {}
|
||||
};
|
187
javascript/src_native/embind.cc
Normal file
187
javascript/src_native/embind.cc
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "./Node.hh"
|
||||
#include "./Layout.hh"
|
||||
#include "./Size.hh"
|
||||
#include "./Value.hh"
|
||||
#include "./Config.hh"
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
#include <emscripten/bind.h>
|
||||
|
||||
using namespace emscripten;
|
||||
|
||||
EMSCRIPTEN_BINDINGS(YOGA_LAYOUT) {
|
||||
class_<MeasureCallback>("MeasureCallback")
|
||||
.function("measure", &MeasureCallback::measure, pure_virtual())
|
||||
.allow_subclass<MeasureCallbackWrapper>("MeasureCallbackWrapper");
|
||||
class_<DirtiedCallback>("DirtiedCallback")
|
||||
.function("dirtied", &DirtiedCallback::dirtied, pure_virtual())
|
||||
.allow_subclass<DirtiedCallbackWrapper>("DirtiedCallbackWrapper");
|
||||
|
||||
class_<Config>("Config")
|
||||
.constructor<>(&Config::create, allow_raw_pointers())
|
||||
.class_function<>("create", &Config::create, allow_raw_pointers())
|
||||
.class_function<>("destroy", &Config::destroy, allow_raw_pointers())
|
||||
.function(
|
||||
"setExperimentalFeatureEnabled",
|
||||
&Config::setExperimentalFeatureEnabled)
|
||||
.function("setPointScaleFactor", &Config::setPointScaleFactor)
|
||||
.function(
|
||||
"isExperimentalFeatureEnabled",
|
||||
&Config::isExperimentalFeatureEnabled);
|
||||
|
||||
value_object<Layout>("Layout")
|
||||
.field("left", &Layout::left)
|
||||
.field("right", &Layout::right)
|
||||
.field("top", &Layout::top)
|
||||
.field("bottom", &Layout::bottom)
|
||||
.field("width", &Layout::width)
|
||||
.field("height", &Layout::height);
|
||||
|
||||
value_object<Size>("Size")
|
||||
.field("width", &Size::width)
|
||||
.field("height", &Size::height);
|
||||
|
||||
value_object<Value>("Value")
|
||||
.field("value", &Value::value)
|
||||
.field("unit", &Value::unit);
|
||||
|
||||
class_<Node>("Node")
|
||||
.constructor<>(&Node::createDefault, allow_raw_pointers())
|
||||
|
||||
.class_function<>(
|
||||
"createDefault", &Node::createDefault, allow_raw_pointers())
|
||||
.class_function<>(
|
||||
"createWithConfig", &Node::createWithConfig, allow_raw_pointers())
|
||||
.class_function<>("destroy", &Node::destroy, allow_raw_pointers())
|
||||
.function("reset", &Node::reset)
|
||||
|
||||
.function("copyStyle", &Node::copyStyle)
|
||||
|
||||
.function("setPositionType", &Node::setPositionType)
|
||||
.function("setPosition", &Node::setPosition)
|
||||
.function("setPositionPercent", &Node::setPositionPercent)
|
||||
|
||||
.function("setAlignContent", &Node::setAlignContent)
|
||||
.function("setAlignItems", &Node::setAlignItems)
|
||||
.function("setAlignSelf", &Node::setAlignSelf)
|
||||
.function("setFlexDirection", &Node::setFlexDirection)
|
||||
.function("setFlexWrap", &Node::setFlexWrap)
|
||||
.function("setJustifyContent", &Node::setJustifyContent)
|
||||
|
||||
.function("setMargin", &Node::setMargin)
|
||||
.function("setMarginPercent", &Node::setMarginPercent)
|
||||
.function("setMarginAuto", &Node::setMarginAuto)
|
||||
|
||||
.function("setOverflow", &Node::setOverflow)
|
||||
.function("setDisplay", &Node::setDisplay)
|
||||
|
||||
.function("setFlex", &Node::setFlex)
|
||||
.function("setFlexBasis", &Node::setFlexBasis)
|
||||
.function("setFlexBasisPercent", &Node::setFlexBasisPercent)
|
||||
.function("setFlexGrow", &Node::setFlexGrow)
|
||||
.function("setFlexShrink", &Node::setFlexShrink)
|
||||
|
||||
.function("setWidth", &Node::setWidth)
|
||||
.function("setWidthPercent", &Node::setWidthPercent)
|
||||
.function("setWidthAuto", &Node::setWidthAuto)
|
||||
.function("setHeight", &Node::setHeight)
|
||||
.function("setHeightPercent", &Node::setHeightPercent)
|
||||
.function("setHeightAuto", &Node::setHeightAuto)
|
||||
|
||||
.function("setMinWidth", &Node::setMinWidth)
|
||||
.function("setMinWidthPercent", &Node::setMinWidthPercent)
|
||||
.function("setMinHeight", &Node::setMinHeight)
|
||||
.function("setMinHeightPercent", &Node::setMinHeightPercent)
|
||||
|
||||
.function("setMaxWidth", &Node::setMaxWidth)
|
||||
.function("setMaxWidthPercent", &Node::setMaxWidthPercent)
|
||||
.function("setMaxHeight", &Node::setMaxHeight)
|
||||
.function("setMaxHeightPercent", &Node::setMaxHeightPercent)
|
||||
|
||||
.function("setAspectRatio", &Node::setAspectRatio)
|
||||
|
||||
.function("setBorder", &Node::setBorder)
|
||||
|
||||
.function("setPadding", &Node::setPadding)
|
||||
.function("setPaddingPercent", &Node::setPaddingPercent)
|
||||
.function("setGap", &Node::setGap)
|
||||
|
||||
.function("getPositionType", &Node::getPositionType)
|
||||
.function("getPosition", &Node::getPosition)
|
||||
|
||||
.function("getAlignContent", &Node::getAlignContent)
|
||||
.function("getAlignItems", &Node::getAlignItems)
|
||||
.function("getAlignSelf", &Node::getAlignSelf)
|
||||
.function("getFlexDirection", &Node::getFlexDirection)
|
||||
.function("getFlexWrap", &Node::getFlexWrap)
|
||||
.function("getJustifyContent", &Node::getJustifyContent)
|
||||
|
||||
.function("getMargin", &Node::getMargin)
|
||||
|
||||
.function("getFlexBasis", &Node::getFlexBasis)
|
||||
.function("getFlexGrow", &Node::getFlexGrow)
|
||||
.function("getFlexShrink", &Node::getFlexShrink)
|
||||
|
||||
.function("getWidth", &Node::getWidth)
|
||||
.function("getHeight", &Node::getHeight)
|
||||
|
||||
.function("getMinWidth", &Node::getMinWidth)
|
||||
.function("getMinHeight", &Node::getMinHeight)
|
||||
|
||||
.function("getMaxWidth", &Node::getMaxWidth)
|
||||
.function("getMaxHeight", &Node::getMaxHeight)
|
||||
|
||||
.function("getAspectRatio", &Node::getAspectRatio)
|
||||
|
||||
.function("getBorder", &Node::getBorder)
|
||||
|
||||
.function("getOverflow", &Node::getOverflow)
|
||||
.function("getDisplay", &Node::getDisplay)
|
||||
|
||||
.function("getPadding", &Node::getPadding)
|
||||
.function("getGap", &Node::getGap)
|
||||
|
||||
.function("insertChild", &Node::insertChild, allow_raw_pointers())
|
||||
.function("removeChild", &Node::removeChild, allow_raw_pointers())
|
||||
|
||||
.function("getChildCount", &Node::getChildCount)
|
||||
|
||||
.function("getParent", &Node::getParent, allow_raw_pointers())
|
||||
.function("getChild", &Node::getChild, allow_raw_pointers())
|
||||
|
||||
.function("isReferenceBaseline", &Node::isReferenceBaseline)
|
||||
.function("setIsReferenceBaseline", &Node::setIsReferenceBaseline)
|
||||
|
||||
.function("setMeasureFunc", &Node::setMeasureFunc, allow_raw_pointers())
|
||||
.function("unsetMeasureFunc", &Node::unsetMeasureFunc)
|
||||
|
||||
.function("setDirtiedFunc", &Node::setDirtiedFunc, allow_raw_pointers())
|
||||
.function("unsetDirtiedFunc", &Node::unsetDirtiedFunc)
|
||||
|
||||
.function("markDirty", &Node::markDirty)
|
||||
.function("isDirty", &Node::isDirty)
|
||||
|
||||
.function("calculateLayout", &Node::calculateLayout)
|
||||
|
||||
.function("getComputedLeft", &Node::getComputedLeft)
|
||||
.function("getComputedRight", &Node::getComputedRight)
|
||||
|
||||
.function("getComputedTop", &Node::getComputedTop)
|
||||
.function("getComputedBottom", &Node::getComputedBottom)
|
||||
|
||||
.function("getComputedWidth", &Node::getComputedWidth)
|
||||
.function("getComputedHeight", &Node::getComputedHeight)
|
||||
|
||||
.function("getComputedLayout", &Node::getComputedLayout)
|
||||
|
||||
.function("getComputedMargin", &Node::getComputedMargin)
|
||||
.function("getComputedBorder", &Node::getComputedBorder)
|
||||
.function("getComputedPadding", &Node::getComputedPadding);
|
||||
}
|
Reference in New Issue
Block a user