Move files around
This commit is contained in:
30
javascript/sources/Layout.hh
Normal file
30
javascript/sources/Layout.hh
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nbind/api.h>
|
||||
#include <nbind/BindDefiner.h>
|
||||
|
||||
struct Layout
|
||||
{
|
||||
double left;
|
||||
double right;
|
||||
|
||||
double top;
|
||||
double bottom;
|
||||
|
||||
double width;
|
||||
double height;
|
||||
|
||||
void toJS(nbind::cbOutput expose) const
|
||||
{
|
||||
expose(left, right, top, bottom, width, height);
|
||||
}
|
||||
};
|
455
javascript/sources/Node.cc
Normal file
455
javascript/sources/Node.cc
Normal file
@@ -0,0 +1,455 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
#include "./Node.hh"
|
||||
#include "./Layout.hh"
|
||||
#include "./Size.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 */ Node * Node::create(void)
|
||||
{
|
||||
return new Node();
|
||||
}
|
||||
|
||||
/* static */ void Node::destroy(Node * node)
|
||||
{
|
||||
delete node;
|
||||
}
|
||||
|
||||
/* static */ Node * Node::fromYGNode(YGNodeRef nodeRef)
|
||||
{
|
||||
return reinterpret_cast<Node *>(YGNodeGetContext(nodeRef));
|
||||
}
|
||||
|
||||
Node::Node(void)
|
||||
: m_node(YGNodeNew())
|
||||
, m_measureFunc(nullptr)
|
||||
{
|
||||
YGNodeSetContext(m_node, reinterpret_cast<void *>(this));
|
||||
}
|
||||
|
||||
Node::~Node(void)
|
||||
{
|
||||
YGNodeFree(m_node);
|
||||
}
|
||||
|
||||
void Node::reset(void)
|
||||
{
|
||||
m_measureFunc.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::setOverflow(int overflow)
|
||||
{
|
||||
YGNodeStyleSetOverflow(m_node, static_cast<YGOverflow>(overflow));
|
||||
}
|
||||
|
||||
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::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::setHeight(double height)
|
||||
{
|
||||
YGNodeStyleSetHeight(m_node, height);
|
||||
}
|
||||
|
||||
void Node::setHeightPercent(double height)
|
||||
{
|
||||
YGNodeStyleSetHeightPercent(m_node, height);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
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(nbind::cbFunction & measureFunc)
|
||||
{
|
||||
m_measureFunc.reset(new nbind::cbFunction(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->call<Size>(width, widthMode, height, heightMode);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
185
javascript/sources/Node.hh
Normal file
185
javascript/sources/Node.hh
Normal file
@@ -0,0 +1,185 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <nbind/api.h>
|
||||
#include <nbind/BindDefiner.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
#include "./Layout.hh"
|
||||
#include "./Size.hh"
|
||||
#include "./Value.hh"
|
||||
|
||||
class Node {
|
||||
|
||||
public:
|
||||
|
||||
static Node * create(void);
|
||||
static void destroy(Node * node);
|
||||
|
||||
public:
|
||||
|
||||
static Node * fromYGNode(YGNodeRef nodeRef);
|
||||
|
||||
private:
|
||||
|
||||
Node(void);
|
||||
|
||||
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 setOverflow(int overflow);
|
||||
|
||||
void setFlex(double flex);
|
||||
void setFlexBasis(double flexBasis);
|
||||
void setFlexBasisPercent(double flexBasis);
|
||||
void setFlexGrow(double flexGrow);
|
||||
void setFlexShrink(double flexShrink);
|
||||
|
||||
void setWidth(double width);
|
||||
void setWidthPercent(double width);
|
||||
void setHeight(double height);
|
||||
void setHeightPercent(double height);
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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(nbind::cbFunction & measureFunc);
|
||||
void unsetMeasureFunc(void);
|
||||
|
||||
public: // Measure func inspectors
|
||||
|
||||
Size callMeasureFunc(double width, int widthMode, double height, int heightMode) 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;
|
||||
|
||||
private:
|
||||
|
||||
YGNodeRef m_node;
|
||||
|
||||
std::unique_ptr<nbind::cbFunction> m_measureFunc;
|
||||
|
||||
};
|
36
javascript/sources/Size.hh
Normal file
36
javascript/sources/Size.hh
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nbind/api.h>
|
||||
#include <nbind/BindDefiner.h>
|
||||
|
||||
struct Size
|
||||
{
|
||||
double width;
|
||||
double height;
|
||||
|
||||
Size(void)
|
||||
: width(0.0)
|
||||
, height(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
Size(double width, double height)
|
||||
: width(width)
|
||||
, height(height)
|
||||
{
|
||||
}
|
||||
|
||||
void toJS(nbind::cbOutput expose) const
|
||||
{
|
||||
expose(width, height);
|
||||
}
|
||||
};
|
31
javascript/sources/Value.hh
Normal file
31
javascript/sources/Value.hh
Normal file
@@ -0,0 +1,31 @@
|
||||
#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)
|
||||
{
|
||||
}
|
||||
|
||||
void toJS(nbind::cbOutput expose) const
|
||||
{
|
||||
expose(unit, value);
|
||||
}
|
||||
};
|
91
javascript/sources/YGEnums.js
Normal file
91
javascript/sources/YGEnums.js
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
|
||||
FLEX_DIRECTION_COUNT: 4,
|
||||
FLEX_DIRECTION_COLUMN: 0,
|
||||
FLEX_DIRECTION_COLUMN_REVERSE: 1,
|
||||
FLEX_DIRECTION_ROW: 2,
|
||||
FLEX_DIRECTION_ROW_REVERSE: 3,
|
||||
|
||||
MEASURE_MODE_COUNT: 3,
|
||||
MEASURE_MODE_UNDEFINED: 0,
|
||||
MEASURE_MODE_EXACTLY: 1,
|
||||
MEASURE_MODE_AT_MOST: 2,
|
||||
|
||||
PRINT_OPTIONS_COUNT: 3,
|
||||
PRINT_OPTIONS_LAYOUT: 1,
|
||||
PRINT_OPTIONS_STYLE: 2,
|
||||
PRINT_OPTIONS_CHILDREN: 4,
|
||||
|
||||
EDGE_COUNT: 9,
|
||||
EDGE_LEFT: 0,
|
||||
EDGE_TOP: 1,
|
||||
EDGE_RIGHT: 2,
|
||||
EDGE_BOTTOM: 3,
|
||||
EDGE_START: 4,
|
||||
EDGE_END: 5,
|
||||
EDGE_HORIZONTAL: 6,
|
||||
EDGE_VERTICAL: 7,
|
||||
EDGE_ALL: 8,
|
||||
|
||||
POSITION_TYPE_COUNT: 2,
|
||||
POSITION_TYPE_RELATIVE: 0,
|
||||
POSITION_TYPE_ABSOLUTE: 1,
|
||||
|
||||
DIMENSION_COUNT: 2,
|
||||
DIMENSION_WIDTH: 0,
|
||||
DIMENSION_HEIGHT: 1,
|
||||
|
||||
JUSTIFY_COUNT: 5,
|
||||
JUSTIFY_FLEX_START: 0,
|
||||
JUSTIFY_CENTER: 1,
|
||||
JUSTIFY_FLEX_END: 2,
|
||||
JUSTIFY_SPACE_BETWEEN: 3,
|
||||
JUSTIFY_SPACE_AROUND: 4,
|
||||
|
||||
DIRECTION_COUNT: 3,
|
||||
DIRECTION_INHERIT: 0,
|
||||
DIRECTION_LTR: 1,
|
||||
DIRECTION_RTL: 2,
|
||||
|
||||
LOG_LEVEL_COUNT: 5,
|
||||
LOG_LEVEL_ERROR: 0,
|
||||
LOG_LEVEL_WARN: 1,
|
||||
LOG_LEVEL_INFO: 2,
|
||||
LOG_LEVEL_DEBUG: 3,
|
||||
LOG_LEVEL_VERBOSE: 4,
|
||||
|
||||
WRAP_COUNT: 2,
|
||||
WRAP_NO_WRAP: 0,
|
||||
WRAP_WRAP: 1,
|
||||
|
||||
OVERFLOW_COUNT: 3,
|
||||
OVERFLOW_VISIBLE: 0,
|
||||
OVERFLOW_HIDDEN: 1,
|
||||
OVERFLOW_SCROLL: 2,
|
||||
|
||||
EXPERIMENTAL_FEATURE_COUNT: 2,
|
||||
EXPERIMENTAL_FEATURE_ROUNDING: 0,
|
||||
EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS: 1,
|
||||
|
||||
ALIGN_COUNT: 5,
|
||||
ALIGN_AUTO: 0,
|
||||
ALIGN_FLEX_START: 1,
|
||||
ALIGN_CENTER: 2,
|
||||
ALIGN_FLEX_END: 3,
|
||||
ALIGN_STRETCH: 4,
|
||||
|
||||
UNIT_COUNT: 3,
|
||||
UNIT_UNDEFINED: 0,
|
||||
UNIT_PIXEL: 1,
|
||||
UNIT_PERCENT: 2,
|
||||
|
||||
};
|
32
javascript/sources/entry-browser.js
Normal file
32
javascript/sources/entry-browser.js
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
var nbind = require('../build/Release/nbind.js');
|
||||
|
||||
var ran = false;
|
||||
var ret = null;
|
||||
|
||||
nbind({}, function (err, result) {
|
||||
|
||||
if (ran)
|
||||
return;
|
||||
|
||||
ran = true;
|
||||
|
||||
if (err)
|
||||
throw err;
|
||||
|
||||
ret = result;
|
||||
|
||||
});
|
||||
|
||||
if (!ran)
|
||||
throw new Error('Failed to load the yoga module - it needed to be loaded synchronously, but didn\'t');
|
||||
|
||||
module.exports = require('./entry-common')(ret.bind, ret.lib);
|
235
javascript/sources/entry-common.js
Normal file
235
javascript/sources/entry-common.js
Normal file
@@ -0,0 +1,235 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
function patch(prototype, name, fn) {
|
||||
|
||||
let original = prototype[name];
|
||||
|
||||
prototype[name] = function (... args) {
|
||||
return fn.call(this, original, ... args);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
module.exports = function (bind, lib) {
|
||||
|
||||
let constants = Object.assign({
|
||||
|
||||
UNDEFINED: NaN
|
||||
|
||||
}, require(`./YGEnums`));
|
||||
|
||||
class Layout {
|
||||
|
||||
constructor(left, right, top, bottom, width, height) {
|
||||
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
|
||||
this.top = top;
|
||||
this.bottom = bottom;
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
}
|
||||
|
||||
fromJS(expose) {
|
||||
|
||||
expose(this.left, this.right, this.top, this.bottom, this.width, this.height);
|
||||
|
||||
}
|
||||
|
||||
toString() {
|
||||
|
||||
return `<Layout#${this.left}:${this.right};${this.top}:${this.bottom};${this.width}:${this.height}>`;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Size {
|
||||
|
||||
static fromJS({ width, height }) {
|
||||
|
||||
return new Size(width, height);
|
||||
|
||||
}
|
||||
|
||||
constructor(width, height) {
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
}
|
||||
|
||||
fromJS(expose) {
|
||||
|
||||
expose(this.width, this.height);
|
||||
|
||||
}
|
||||
|
||||
toString() {
|
||||
|
||||
return `<Size#${this.width}x${this.height}>`;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Value {
|
||||
|
||||
constructor(unit, value) {
|
||||
|
||||
this.unit = unit;
|
||||
this.value = value;
|
||||
|
||||
}
|
||||
|
||||
fromJS(expose) {
|
||||
|
||||
expose(this.unit, this.value);
|
||||
|
||||
}
|
||||
|
||||
toString() {
|
||||
|
||||
switch (this.unit) {
|
||||
|
||||
case constants.UNIT_PIXEL:
|
||||
return `${this.value}`;
|
||||
|
||||
case constants.UNIT_PERCENT:
|
||||
return `${this.value}%`;
|
||||
|
||||
default: {
|
||||
return `${this.value}?`;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
|
||||
return this.value;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (let fnName of [ `setPosition`, `setMargin`, `setFlexBasis`, `setWidth`, `setHeight`, `setMinWidth`, `setMinHeight`, `setMaxWidth`, `setMaxHeight`, `setPadding` ]) {
|
||||
|
||||
let methods = { [constants.UNIT_PIXEL]: lib.Node.prototype[fnName], [constants.UNIT_PERCENT]: lib.Node.prototype[`${fnName}Percent`] };
|
||||
|
||||
if (Object.keys(methods).some(method => methods[method] == null))
|
||||
throw new Error(`Assertion failed; some unit derivates of ${fnName} seem missing`);
|
||||
|
||||
patch(lib.Node.prototype, fnName, function (original, ... args) {
|
||||
|
||||
// We patch all these functions to add support for the following calls:
|
||||
// .setWidth(100) / .setWidth("100%") / .setWidth(.getWidth())
|
||||
|
||||
let value = args.pop();
|
||||
let unit, asNumber;
|
||||
|
||||
if (value instanceof Value) {
|
||||
|
||||
unit = value.unit;
|
||||
asNumber = value.valueOf();
|
||||
|
||||
} else {
|
||||
|
||||
unit = typeof value === `string` && value.endsWith(`%`) ? constants.UNIT_PERCENT : constants.UNIT_PIXEL;
|
||||
asNumber = parseFloat(value);
|
||||
|
||||
}
|
||||
|
||||
return methods[unit].call(this, ... args, asNumber);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
patch(lib.Node.prototype, `free`, function () {
|
||||
|
||||
// Since we handle the memory allocation ourselves (via lib.Node.create), we also need to handle the deallocation
|
||||
|
||||
lib.Node.destroy(this);
|
||||
|
||||
});
|
||||
|
||||
patch(lib.Node.prototype, `freeRecursive`, function () {
|
||||
|
||||
for (let t = 0, T = this.getChildCount(); t < T; ++t)
|
||||
this.getChild(0).freeRecursive();
|
||||
|
||||
this.free();
|
||||
|
||||
});
|
||||
|
||||
patch(lib.Node.prototype, `setMeasureFunc`, function (original, measureFunc) {
|
||||
|
||||
// This patch is just a convenience patch, since it helps write more idiomatic source code (such as .setMeasureFunc(null))
|
||||
// We also automatically convert the return value of the measureFunc to a Size object, so that we can return anything that has .width and .height properties
|
||||
|
||||
if (measureFunc) {
|
||||
return original.call(this, (... args) => Size.fromJS(measureFunc(... args)));
|
||||
} else {
|
||||
return this.unsetMeasureFunc();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
patch(lib.Node.prototype, `calculateLayout`, function (original, width = constants.UNDEFINED, height = constants.UNDEFINED, direction = constants.DIRECTION_LTR) {
|
||||
|
||||
// Just a small patch to add support for the function default parameters
|
||||
|
||||
return original.call(this, width, height, direction);
|
||||
|
||||
});
|
||||
|
||||
function setExperimentalFeatureEnabled(... args) {
|
||||
|
||||
return lib.setExperimentalFeatureEnabled(... args);
|
||||
|
||||
}
|
||||
|
||||
function isExperimentalFeatureEnabled(... args) {
|
||||
|
||||
return lib.isExperimentalFeatureEnabled(... args);
|
||||
|
||||
}
|
||||
|
||||
function getInstanceCount(... args) {
|
||||
|
||||
return lib.getInstanceCount(... args);
|
||||
|
||||
}
|
||||
|
||||
bind(`Layout`, Layout);
|
||||
bind(`Size`, Size);
|
||||
bind(`Value`, Value);
|
||||
|
||||
return Object.assign({
|
||||
|
||||
Node: lib.Node,
|
||||
|
||||
Layout,
|
||||
Size,
|
||||
Value,
|
||||
|
||||
setExperimentalFeatureEnabled,
|
||||
isExperimentalFeatureEnabled,
|
||||
|
||||
getInstanceCount
|
||||
|
||||
}, constants);
|
||||
|
||||
};
|
13
javascript/sources/entry-node.js
Normal file
13
javascript/sources/entry-node.js
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
var nbind = require('nbind');
|
||||
var ret = nbind.init(__dirname + '/../');
|
||||
|
||||
module.exports = require('./entry-common')(ret.bind, ret.lib);
|
27
javascript/sources/global.cc
Normal file
27
javascript/sources/global.cc
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
#include "./global.hh"
|
||||
|
||||
void setExperimentalFeatureEnabled(int feature, bool enabled)
|
||||
{
|
||||
YGSetExperimentalFeatureEnabled(static_cast<YGExperimentalFeature>(feature), enabled);
|
||||
}
|
||||
|
||||
bool isExperimentalFeatureEnabled(int feature)
|
||||
{
|
||||
return YGIsExperimentalFeatureEnabled(static_cast<YGExperimentalFeature>(feature));
|
||||
}
|
||||
|
||||
unsigned getInstanceCount(void)
|
||||
{
|
||||
return YGNodeGetInstanceCount();
|
||||
}
|
15
javascript/sources/global.hh
Normal file
15
javascript/sources/global.hh
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
void setExperimentalFeatureEnabled(int feature, bool enabled);
|
||||
bool isExperimentalFeatureEnabled(int feature);
|
||||
|
||||
unsigned getInstanceCount(void);
|
156
javascript/sources/nbind.cc
Normal file
156
javascript/sources/nbind.cc
Normal file
@@ -0,0 +1,156 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
#include "./Node.hh"
|
||||
#include "./Layout.hh"
|
||||
#include "./Size.hh"
|
||||
#include "./Value.hh"
|
||||
#include "./global.hh"
|
||||
|
||||
#define NBIND_DUPLICATE_POINTERS true
|
||||
|
||||
#include <nbind/nbind.h>
|
||||
|
||||
NBIND_GLOBAL()
|
||||
{
|
||||
function(setExperimentalFeatureEnabled);
|
||||
function(isExperimentalFeatureEnabled);
|
||||
function(getInstanceCount);
|
||||
}
|
||||
|
||||
NBIND_CLASS(Size)
|
||||
{
|
||||
construct<>();
|
||||
construct<double, double>();
|
||||
}
|
||||
|
||||
NBIND_CLASS(Layout)
|
||||
{
|
||||
construct<>();
|
||||
}
|
||||
|
||||
NBIND_CLASS(Value)
|
||||
{
|
||||
construct<>();
|
||||
construct<int, double>();
|
||||
}
|
||||
|
||||
NBIND_CLASS(Node)
|
||||
{
|
||||
method(create);
|
||||
method(destroy);
|
||||
|
||||
method(reset);
|
||||
|
||||
method(copyStyle);
|
||||
|
||||
method(setPositionType);
|
||||
method(setPosition);
|
||||
method(setPositionPercent);
|
||||
|
||||
method(setAlignContent);
|
||||
method(setAlignItems);
|
||||
method(setAlignSelf);
|
||||
method(setFlexDirection);
|
||||
method(setFlexWrap);
|
||||
method(setJustifyContent);
|
||||
|
||||
method(setMargin);
|
||||
method(setMarginPercent);
|
||||
|
||||
method(setOverflow);
|
||||
|
||||
method(setFlex);
|
||||
method(setFlexBasis);
|
||||
method(setFlexBasisPercent);
|
||||
method(setFlexGrow);
|
||||
method(setFlexShrink);
|
||||
|
||||
method(setWidth);
|
||||
method(setWidthPercent);
|
||||
method(setHeight);
|
||||
method(setHeightPercent);
|
||||
|
||||
method(setMinWidth);
|
||||
method(setMinWidthPercent);
|
||||
method(setMinHeight);
|
||||
method(setMinHeightPercent);
|
||||
|
||||
method(setMaxWidth);
|
||||
method(setMaxWidthPercent);
|
||||
method(setMaxHeight);
|
||||
method(setMaxHeightPercent);
|
||||
|
||||
method(setAspectRatio);
|
||||
|
||||
method(setBorder);
|
||||
|
||||
method(setPadding);
|
||||
method(setPaddingPercent);
|
||||
|
||||
method(getPositionType);
|
||||
method(getPosition);
|
||||
|
||||
method(getAlignContent);
|
||||
method(getAlignItems);
|
||||
method(getAlignSelf);
|
||||
method(getFlexDirection);
|
||||
method(getFlexWrap);
|
||||
method(getJustifyContent);
|
||||
|
||||
method(getMargin);
|
||||
|
||||
method(getFlexBasis);
|
||||
method(getFlexGrow);
|
||||
method(getFlexShrink);
|
||||
|
||||
method(getWidth);
|
||||
method(getHeight);
|
||||
|
||||
method(getMinWidth);
|
||||
method(getMinHeight);
|
||||
|
||||
method(getMaxWidth);
|
||||
method(getMaxHeight);
|
||||
|
||||
method(getAspectRatio);
|
||||
|
||||
method(getBorder);
|
||||
|
||||
method(getPadding);
|
||||
|
||||
method(insertChild);
|
||||
method(removeChild);
|
||||
|
||||
method(getChildCount);
|
||||
|
||||
method(getParent);
|
||||
method(getChild);
|
||||
|
||||
method(setMeasureFunc);
|
||||
method(unsetMeasureFunc);
|
||||
|
||||
method(markDirty);
|
||||
method(isDirty);
|
||||
|
||||
method(calculateLayout);
|
||||
|
||||
method(getComputedLeft);
|
||||
method(getComputedRight);
|
||||
|
||||
method(getComputedTop);
|
||||
method(getComputedBottom);
|
||||
|
||||
method(getComputedWidth);
|
||||
method(getComputedHeight);
|
||||
|
||||
method(getComputedLayout);
|
||||
}
|
Reference in New Issue
Block a user