2019-06-06 19:36:56 -07:00
|
|
|
/*
|
2022-10-04 13:59:32 -07:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2017-01-02 02:22:45 -08:00
|
|
|
*
|
2019-10-15 10:30:08 -07:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-01-02 02:22:45 -08:00
|
|
|
*/
|
2019-10-15 10:30:08 -07:00
|
|
|
|
2017-01-02 02:22:45 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
#include <emscripten/bind.h>
|
2017-01-02 02:22:45 -08:00
|
|
|
#include <yoga/Yoga.h>
|
|
|
|
|
|
|
|
#include "./Layout.hh"
|
|
|
|
#include "./Size.hh"
|
2017-01-04 04:33:39 -08:00
|
|
|
#include "./Value.hh"
|
2017-03-01 09:19:55 -08:00
|
|
|
#include "./Config.hh"
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
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"); }
|
|
|
|
};
|
|
|
|
|
2017-01-02 02:22:45 -08:00
|
|
|
class Node {
|
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public:
|
|
|
|
static Node* createDefault(void);
|
|
|
|
static Node* createWithConfig(Config* config);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
static void destroy(Node* node);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public:
|
|
|
|
static Node* fromYGNode(YGNodeRef nodeRef);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
private:
|
|
|
|
Node(Config* config);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public:
|
|
|
|
~Node(void);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public: // Prevent accidental copy
|
|
|
|
Node(Node const&) = delete;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
Node const& operator=(Node const&) = delete;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public:
|
|
|
|
void reset(void);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public: // Style setters
|
|
|
|
void copyStyle(Node const& other);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
void setPositionType(int positionType);
|
|
|
|
void setPosition(int edge, double position);
|
|
|
|
void setPositionPercent(int edge, double position);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
void setAlignContent(int alignContent);
|
|
|
|
void setAlignItems(int alignItems);
|
|
|
|
void setAlignSelf(int alignSelf);
|
|
|
|
void setFlexDirection(int flexDirection);
|
|
|
|
void setFlexWrap(int flexWrap);
|
|
|
|
void setJustifyContent(int justifyContent);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
void setMargin(int edge, double margin);
|
|
|
|
void setMarginPercent(int edge, double margin);
|
|
|
|
void setMarginAuto(int edge);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
void setOverflow(int overflow);
|
|
|
|
void setDisplay(int display);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
void setFlex(double flex);
|
|
|
|
void setFlexBasis(double flexBasis);
|
|
|
|
void setFlexBasisPercent(double flexBasis);
|
|
|
|
void setFlexBasisAuto();
|
|
|
|
void setFlexGrow(double flexGrow);
|
|
|
|
void setFlexShrink(double flexShrink);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
void setWidth(double width);
|
|
|
|
void setWidthPercent(double width);
|
|
|
|
void setWidthAuto();
|
|
|
|
void setHeight(double height);
|
|
|
|
void setHeightPercent(double height);
|
|
|
|
void setHeightAuto();
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
void setMinWidth(double minWidth);
|
|
|
|
void setMinWidthPercent(double minWidth);
|
|
|
|
void setMinHeight(double minHeight);
|
|
|
|
void setMinHeightPercent(double minHeight);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
void setMaxWidth(double maxWidth);
|
|
|
|
void setMaxWidthPercent(double maxWidth);
|
|
|
|
void setMaxHeight(double maxHeight);
|
|
|
|
void setMaxHeightPercent(double maxHeight);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
void setAspectRatio(double aspectRatio);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
void setBorder(int edge, double border);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
void setPadding(int edge, double padding);
|
|
|
|
void setPaddingPercent(int edge, double padding);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2022-10-13 08:18:49 -07:00
|
|
|
void setGap(int gutter, double gapLength);
|
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public: // Style getters
|
|
|
|
int getPositionType(void) const;
|
|
|
|
Value getPosition(int edge) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
int getAlignContent(void) const;
|
|
|
|
int getAlignItems(void) const;
|
|
|
|
int getAlignSelf(void) const;
|
|
|
|
int getFlexDirection(void) const;
|
|
|
|
int getFlexWrap(void) const;
|
|
|
|
int getJustifyContent(void) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
Value getMargin(int edge) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
int getOverflow(void) const;
|
|
|
|
int getDisplay(void) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
Value getFlexBasis(void) const;
|
|
|
|
double getFlexGrow(void) const;
|
|
|
|
double getFlexShrink(void) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
Value getWidth(void) const;
|
|
|
|
Value getHeight(void) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
Value getMinWidth(void) const;
|
|
|
|
Value getMinHeight(void) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
Value getMaxWidth(void) const;
|
|
|
|
Value getMaxHeight(void) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
double getAspectRatio(void) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
double getBorder(int edge) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
Value getPadding(int edge) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
float getGap(int gutter);
|
2022-10-13 08:18:49 -07:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public: // Tree hierarchy mutators
|
|
|
|
void insertChild(Node* child, unsigned index);
|
|
|
|
void removeChild(Node* child);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public: // Tree hierarchy inspectors
|
|
|
|
unsigned getChildCount(void) const;
|
2019-01-31 09:06:57 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
// The following functions cannot be const because they could discard const
|
|
|
|
// qualifiers (ex: constNode->getChild(0)->getParent() wouldn't be const)
|
2019-01-31 09:06:57 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
Node* getParent(void);
|
|
|
|
Node* getChild(unsigned index);
|
2019-01-31 09:06:57 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public: // Measure func mutators
|
2022-12-28 01:27:12 -08:00
|
|
|
void setMeasureFunc(MeasureCallback* measureFunc);
|
2019-03-25 05:37:36 -07:00
|
|
|
void unsetMeasureFunc(void);
|
2019-01-31 09:06:57 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public: // Measure func inspectors
|
|
|
|
Size callMeasureFunc(
|
|
|
|
double width,
|
|
|
|
int widthMode,
|
|
|
|
double height,
|
|
|
|
int heightMode) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public: // Dirtied func mutators
|
2022-12-28 01:27:12 -08:00
|
|
|
void setDirtiedFunc(DirtiedCallback* dirtiedFunc);
|
2019-03-25 05:37:36 -07:00
|
|
|
void unsetDirtiedFunc(void);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public: // Dirtied func inspectors
|
|
|
|
void callDirtiedFunc(void) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public: // Dirtiness accessors
|
|
|
|
void markDirty(void);
|
|
|
|
bool isDirty(void) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public: // Layout mutators
|
|
|
|
void calculateLayout(double width, double height, int direction);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public: // Layout inspectors
|
|
|
|
double getComputedLeft(void) const;
|
|
|
|
double getComputedRight(void) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
double getComputedTop(void) const;
|
|
|
|
double getComputedBottom(void) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
double getComputedWidth(void) const;
|
|
|
|
double getComputedHeight(void) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
Layout getComputedLayout(void) const;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
double getComputedMargin(int edge) const;
|
|
|
|
double getComputedBorder(int edge) const;
|
|
|
|
double getComputedPadding(int edge) const;
|
2017-01-15 15:16:10 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
public:
|
|
|
|
void setIsReferenceBaseline(bool isReferenceBaseline);
|
|
|
|
bool isReferenceBaseline();
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
YGNodeRef m_node;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
std::unique_ptr<MeasureCallback> m_measureFunc;
|
|
|
|
std::unique_ptr<DirtiedCallback> m_dirtiedFunc;
|
2017-01-02 02:22:45 -08:00
|
|
|
};
|