1 #include "IGraphicsFlexBox.h" 4 using namespace igraphics;
8 mConfigRef = YGConfigNew();
9 mRootNodeRef = YGNodeNewWithConfig(mConfigRef);
14 YGNodeFreeRecursive(mRootNodeRef);
15 YGConfigFree(mConfigRef);
18 void IFlexBox::Init(
const IRECT& r, YGFlexDirection direction, YGJustify justify, YGWrap wrap,
float padding,
float margin)
20 YGNodeStyleSetWidth(mRootNodeRef, r.
W());
21 YGNodeStyleSetHeight(mRootNodeRef, r.
H());
22 YGNodeStyleSetFlexDirection(mRootNodeRef, direction);
23 YGNodeStyleSetJustifyContent(mRootNodeRef, justify);
24 YGNodeStyleSetFlexWrap(mRootNodeRef, wrap);
25 YGNodeStyleSetPadding(mRootNodeRef, YGEdgeAll, padding);
26 YGNodeStyleSetMargin(mRootNodeRef, YGEdgeAll, margin);
31 YGNodeCalculateLayout(mRootNodeRef, YGUndefined, YGUndefined, direction);
34 YGNodeRef
IFlexBox::AddItem(
float width,
float height, YGAlign alignSelf,
float grow,
float shrink,
float margin)
36 int index = mNodeCounter;
37 YGNodeRef child = YGNodeNew();
39 if(width == YGUndefined)
40 YGNodeStyleSetWidthAuto(child);
42 YGNodeStyleSetWidthPercent(child, width * -1.f);
44 YGNodeStyleSetWidth(child, width);
46 if(height == YGUndefined)
47 YGNodeStyleSetHeightAuto(child);
49 YGNodeStyleSetHeightPercent(child, height * -1.f);
51 YGNodeStyleSetHeight(child, height);
53 YGNodeStyleSetAlignSelf(child, alignSelf);
54 YGNodeStyleSetMargin(child, YGEdgeAll, margin);
55 YGNodeStyleSetFlexGrow(child, grow);
56 YGNodeStyleSetFlexShrink(child, shrink);
57 YGNodeInsertChild(mRootNodeRef, child, index);
66 YGNodeInsertChild(mRootNodeRef, child, mNodeCounter++);
71 return IRECT(YGNodeLayoutGetLeft(mRootNodeRef),
72 YGNodeLayoutGetTop(mRootNodeRef),
73 YGNodeLayoutGetLeft(mRootNodeRef) + YGNodeLayoutGetWidth(mRootNodeRef),
74 YGNodeLayoutGetTop(mRootNodeRef) + YGNodeLayoutGetHeight(mRootNodeRef));
79 YGNodeRef child = YGNodeGetChild(mRootNodeRef, nodeIndex);
80 return IRECT(YGNodeLayoutGetLeft(mRootNodeRef) + YGNodeLayoutGetLeft(child),
81 YGNodeLayoutGetTop(mRootNodeRef) + YGNodeLayoutGetTop(child),
82 YGNodeLayoutGetLeft(mRootNodeRef) + YGNodeLayoutGetLeft(child) + YGNodeLayoutGetWidth(child),
83 YGNodeLayoutGetTop(mRootNodeRef) + YGNodeLayoutGetTop(child) + YGNodeLayoutGetHeight(child));
88 #include "YGLayout.cpp" 89 #include "YGEnums.cpp" 90 #include "YGNodePrint.cpp" 91 #include "YGValue.cpp" 92 #include "YGConfig.cpp" 94 #include "YGStyle.cpp" 98 #include "event/event.cpp" Used to manage a rectangular area, independent of draw class/platform.
YGNodeRef AddItem(float width, float height, YGAlign alignSelf=YGAlignAuto, float grow=0.f, float shrink=1.f, float margin=0.f)
Add a flex item, with some parameters.
IRECT GetItemBounds(int nodeIndex) const
Get the bounds for a particular flex item.
IRECT GetRootBounds() const
Get an IRECT of the root node bounds.
void Init(const IRECT &r, YGFlexDirection direction=YGFlexDirectionRow, YGJustify justify=YGJustifyFlexStart, YGWrap wrap=YGWrapNoWrap, float padding=0.f, float margin=0.f)
Initialize the IFlexBox flex container.
void CalcLayout(YGDirection direction=YGDirectionLTR)
Calculate the layout, call after add all items.