19 #include "IGraphicsFlexBox.h" 21 static const std::initializer_list<const char*> alignStrs = {
"YGAlignAuto",
"YGAlignFlexStart",
"YGAlignCenter",
"YGAlignFlexEnd",
"YGAlignStretch",
"YGAlignBaseline",
"YGAlignSpaceBetween",
"YGAlignSpaceAround" };
22 static const std::initializer_list<const char*> dirStrs = {
"YGFlexDirectionColumn",
"YGFlexDirectionColumnReverse",
"YGFlexDirectionRow",
"YGFlexDirectionRowReverse" };
23 static const std::initializer_list<const char*> justifyStrs = {
"YGJustifyFlexStart",
"YGJustifyCenter",
"YGJustifyFlexEnd",
"YGJustifySpaceBetween",
"YGJustifySpaceAround",
"YGJustifySpaceEvenly" };
24 static const std::initializer_list<const char*> wrapStrs = {
"YGWrapNoWrap",
"YGWrapWrap",
"YGWrapWrapReverse" };
34 mMenu.GetItem(0)->SetSubmenu(
new IPopupMenu(
"Align", alignStrs));
35 mMenu.GetItem(1)->SetSubmenu(
new IPopupMenu(
"Direction", dirStrs));
36 mMenu.GetItem(2)->SetSubmenu(
new IPopupMenu(
"Justify", justifyStrs));
37 mMenu.GetItem(3)->SetSubmenu(
new IPopupMenu(
"Wrap", wrapStrs));
39 mText =
IText(70.f, EVAlign::Middle);
48 for (
int i=0; i<7; i++)
50 g.
FillRect(GetRainbow(i), mItemRects[i]);
51 g.
DrawRect(COLOR_BLACK, mItemRects[i]);
52 str.SetFormatted(2,
"%i", i);
53 g.
DrawText(mText, str.Get(), mItemRects[i]);
57 g.
MeasureText(mText.WithSize(14.f), mSettingsStr.Get(), textRect);
61 g.
DrawText(mText.WithSize(14.f), mSettingsStr.Get(), adjusted);
73 for (
int i=0; i<7; i++)
75 mItemRects.push_back(
IRECT());
79 f.
Init(mRECT, YGFlexDirection(mDirection), YGJustify(mJustify), YGWrap(mWrap));
83 for (
int i=0; i<7; i++)
85 r = f.
AddItem(100.f, 100.f, YGAlign(mAlign));
90 for (
int i=0; i<7; i++)
96 mSettingsStr.SetFormatted(256,
"%s, %s, %s, %s", alignStrs.begin()[mAlign], dirStrs.begin()[mDirection], justifyStrs.begin()[mJustify], wrapStrs.begin()[mWrap]);
101 mMenu.GetItem(0)->GetSubmenu()->CheckItemAlone(mAlign);
102 mMenu.GetItem(1)->GetSubmenu()->CheckItemAlone(mDirection);
103 mMenu.GetItem(2)->GetSubmenu()->CheckItemAlone(mJustify);
104 mMenu.GetItem(3)->GetSubmenu()->CheckItemAlone(mWrap);
113 int idx = pSelectedMenu->GetChosenItemIdx();
114 if (strcmp(pSelectedMenu->GetRootTitle(),
"Align") == 0) { mAlign = idx; }
115 else if(strcmp(pSelectedMenu->GetRootTitle(),
"Direction") == 0) { mDirection = idx; }
116 else if(strcmp(pSelectedMenu->GetRootTitle(),
"Justify") == 0) { mJustify = idx; }
117 else if(strcmp(pSelectedMenu->GetRootTitle(),
"Wrap") == 0) { mWrap = idx; }
125 WDL_String mSettingsStr;
126 IPopupMenu mMenu {
"FlexBox", {
"Align",
"Direction",
"Justify",
"Wrap"}};
128 int mAlign = YGAlignAuto;
129 int mDirection = YGFlexDirectionColumn;
130 int mJustify = YGJustifyFlexStart;
131 int mWrap = YGWrapNoWrap;
132 std::vector<IRECT> mItemRects;
IRECT Inset(const IRECT &rhs) const
Offsets the input IRECT based on the parent.
The lowest level base class of an IGraphics control.
Used to manage a rectangular area, independent of draw class/platform.
virtual void DrawRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f)
Draw a rectangle to the graphics context.
Control to test IGraphicsFlexBox.
Used to manage mouse modifiers i.e.
void OnResize() override
Called when IControl is constructed or resized using SetRect().
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.
void OnPopupMenuSelection(IPopupMenu *pSelectedMenu, int) override
Implement this method to handle popup menu selection after IGraphics::CreatePopupMenu/IControl::Promp...
void SetTooltip(const char *str)
Set a tooltip for the control.
void DrawText(const IText &text, const char *str, const IRECT &bounds, const IBlend *pBlend=0)
Draw some text to the graphics context in a specific rectangle.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
This file contains the base IControl implementation, along with some base classes for specific types ...
void CreatePopupMenu(IControl &control, IPopupMenu &menu, const IRECT &bounds, int valIdx=0)
Shows a pop up/contextual menu in relation to a rectangular region of the graphics context...
IColor WithOpacity(float alpha) const
Returns a new IColor with a different opacity.
IText is used to manage font and text/text entry style for a piece of text on the UI...
IControl(const IRECT &bounds, int paramIdx=kNoParameter, IActionFunction actionFunc=nullptr)
Constructor.
IRECT GetItemBounds(int nodeIndex) const
Get the bounds for a particular flex item.
IRECT GetRootBounds() const
Get an IRECT of the root node bounds.
The lowest level base class of an IGraphics context.
virtual void FillRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill a rectangular region of the graphics context with a color.
IFlexBox is a basic C++ helper for Yoga https://yogalayout.com.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
IRECT GetCentredInside(const IRECT &sr) const
Get a rectangle the size of sr but with the same center point as this rectangle.
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.
virtual float MeasureText(const IText &text, const char *str, IRECT &bounds) const
Measure the rectangular region that some text will occupy.
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.