19#include "IGraphicsFlexBox.h"
21static const std::initializer_list<const char*> alignStrs = {
"YGAlignAuto",
"YGAlignFlexStart",
"YGAlignCenter",
"YGAlignFlexEnd",
"YGAlignStretch",
"YGAlignBaseline",
"YGAlignSpaceBetween",
"YGAlignSpaceAround" };
22static const std::initializer_list<const char*> dirStrs = {
"YGFlexDirectionColumn",
"YGFlexDirectionColumnReverse",
"YGFlexDirectionRow",
"YGFlexDirectionRowReverse" };
23static const std::initializer_list<const char*> justifyStrs = {
"YGJustifyFlexStart",
"YGJustifyCenter",
"YGJustifyFlexEnd",
"YGJustifySpaceBetween",
"YGJustifySpaceAround",
"YGJustifySpaceEvenly" };
24static 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;
This file contains the base IControl implementation, along with some base classes for specific types ...
The lowest level base class of an IGraphics control.
IControl * SetTooltip(const char *str)
Set a tooltip for the control.
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
IFlexBox is a basic C++ helper for Yoga https://yogalayout.com.
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 CalcLayout(YGDirection direction=YGDirectionLTR)
Calculate the layout, call after add all items.
IRECT GetItemBounds(int nodeIndex) const
Get the bounds for a particular flex item.
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.
IRECT GetRootBounds() const
Get an IRECT of the root node bounds.
The lowest level base class of an IGraphics context.
virtual void DrawRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f)
Draw a rectangle to the graphics context.
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 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.
virtual void FillRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill a rectangular region of the graphics context with a color.
virtual float MeasureText(const IText &text, const char *str, IRECT &bounds) const
Measure the rectangular region that some text will occupy.
Control to test IGraphicsFlexBox.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
void OnResize() override
Called when IControl is constructed or resized using SetRect().
void OnPopupMenuSelection(IPopupMenu *pSelectedMenu, int) override
Implement this method to handle popup menu selection after IGraphics::CreatePopupMenu/IControlPromptU...
void Draw(IGraphics &g) override
Draw the control to the graphics context.
IColor WithOpacity(float alpha) const
Returns a new IColor with a different opacity.
Used to manage mouse modifiers i.e.
Used to manage a rectangular area, independent of draw class/platform.
IRECT GetCentredInside(const IRECT &sr) const
Get a rectangle the size of sr but with the same center point as this rectangle.
IRECT Inset(const IRECT &rhs) const
Offsets the input IRECT based on the parent.
IText is used to manage font and text/text entry style for a piece of text on the UI,...