26BEGIN_IGRAPHICS_NAMESPACE
33 using TabAttachFunc = std::function<void(
IVTabPage* pParent,
const IRECT& bounds)>;
34 static constexpr double kDefaultPadding = 10.0;
37 if (pTab->NChildren() == 1)
51 IVTabPage(TabAttachFunc attachFunc =
nullptr, ResizeFunc resizeFunc = DefaultResizeFunc,
const IVStyle& style = DEFAULT_STYLE,
double padding = kDefaultPadding)
66 double GetPadding()
const {
return mPadding; }
68 void SetPadding(
double padding) { mPadding = padding; }
72 ForAllChildrenFunc([
this](
int childIdx,
IControl* pChild) {
75 pVectorBase->SetStyle(GetStyle());
81 double mPadding = 0.0;
85using PageMap = std::vector<std::pair<const char*, IVTabPage*>>;
112 const IVStyle& style = DEFAULT_STYLE,
float tabBarHeight = 20.0f,
113 float tabBarFrac = 0.5f, EAlign tabsAlign = EAlign::Near)
115 ,
IVectorBase(style.WithDrawFrame(
false).WithDrawShadows(
false))
116 , mTabBarHeight(tabBarHeight)
117 , mTabBarFrac(tabBarFrac)
118 , mTabsAlign(tabsAlign)
122 for (
auto& page : pages)
124 AddPage(page.first, page.second);
137 ForAllChildrenFunc([hide](
int childIdx,
IControl* pChild) {
148 GetTabSwitchControl()->
Hide(
false);
149 GetPage(GetTabSwitchControl()->GetSelectedIdx())->
Hide(
false);
161 auto rcrForTabCorners = mTabBarFrac == 1.0f ? 0.0f : rcr;
164 mTabsAlign == EAlign::Far ? 0.0f : rcrForTabCorners,
167 if (mStyle.drawFrame)
177 }, mPageNames,
"",
GetStyle().WithWidgetFrac(1.0f)));
179 GetTabSwitchControl()->SetShape(EVShape::EndsRounded);
183 AddChildControl(pPage);
189 GetTabSwitchControl()->
Hide(
false);
190 GetPage(0)->
Hide(
false);
195 ForAllChildrenFunc([
this](
int childIdx,
IControl* pChild) {
198 pVectorBase->SetStyle(GetStyle());
202 auto adjustedStyle =
GetStyle().WithDrawFrame(
false).WithDrawShadows(
false);
203 GetTabSwitchControl()->
SetStyle(adjustedStyle.WithWidgetFrac(1.0));
204 GetTabSwitchControl()->SetShape(EVShape::EndsRounded);
221 float GetTabHeight()
const {
return mTabBarHeight; }
225 IRECT GetTabBarArea()
const
230 int NPages()
const {
return mPages.GetSize(); }
233 void AddPage(
const char* pageName,
IVTabPage* pPage)
235 pPage->SetLabelStr(pageName);
236 mPageNames.push_back(pageName);
240 void ForAllPagesFunc(std::function<
void(
IVTabPage* pControl)> func)
242 for (
int i=0; i<mPages.GetSize(); i++)
250 IVTabPage* GetPage(
int pageIdx) {
return mPages.Get(pageIdx); }
252 void SelectPage(
int index)
254 GetTabSwitchControl()->
SetValue(
static_cast<double>(index));
259 void ShowSelectedPage()
262 bool hide = strcmp(GetTabSwitchControl()->GetSelectedLabelStr(),
263 pPage->GetLabelStr());
269 pControl->
Hide(
true);
273 WDL_PtrList<IVTabPage> mPages;
274 std::vector<const char*> mPageNames;
280END_IGRAPHICS_NAMESPACE
A collection of IControls for common UI widgets, such as knobs, sliders, switches.
std::vector< std::pair< const char *, IVTabPage * > > PageMap
Ordered list of (tab name, page) pairs.
A special control to draw contextual info as a slider etc is moved If used in the main IControl stack...
IContainerBase allows a control to nest sub controls and it clips the drawing of those subcontrols In...
void Hide(bool hide) override
Shows or hides the IControl.
The lowest level base class of an IGraphics control.
virtual void Hide(bool hide)
Shows or hides the IControl.
void SetTargetRECT(const IRECT &bounds)
Set the rectangular mouse tracking target area, within the graphics context for this control.
T * As()
Helper function to dynamic cast an IControl to a subclass.
virtual void SetValue(double value, int valIdx=0)
Set one of the control's values.
void SetTargetAndDrawRECTs(const IRECT &bounds)
Set BOTH the draw rect and the target area, within the graphics context for this control.
The lowest level base class of an IGraphics context.
virtual void DrawRoundRect(const IColor &color, const IRECT &bounds, float cornerRadius=5.f, const IBlend *pBlend=0, float thickness=1.f)
Draw a rounded rectangle to the graphics context.
IBubbleControl * GetBubbleControl(int i=0)
virtual void FillRoundRect(const IColor &color, const IRECT &bounds, float cornerRadius=5.f, const IBlend *pBlend=0)
Fill a rounded rectangle with a color.
A control used as the base class for a tabbed page of subcontrols.
void OnStyleChanged() override
Implement if extra changes are required in response to style changing.
virtual void Draw(IGraphics &g) override
Draw the control to the graphics context.
IVTabPage(TabAttachFunc attachFunc=nullptr, ResizeFunc resizeFunc=DefaultResizeFunc, const IVStyle &style=DEFAULT_STYLE, double padding=kDefaultPadding)
Constructor.
A vector "tab" multi switch control.
A control to manage tabbed pages of sub controls Basic usage example:
void OnResize() override
Called when IControl is constructed or resized using SetRect().
void OnAttached() override
Called after the control has been attached, and its delegate and graphics member variable set.
void Hide(bool hide) override
Shows or hides the IControl.
void OnStyleChanged() override
Implement if extra changes are required in response to style changing.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
A base interface to be combined with IControl for vectorial controls "IVControls",...
IRECT MakeRects(const IRECT &parent, bool hasHandle=false)
Calculate the rectangles for the various areas, depending on the style.
virtual void SetStyle(const IVStyle &style)
Set the Style of this IVControl.
float GetRoundedCornerRadius(const IRECT &bounds) const
Get the radius of rounded corners for a rectangle, based on the style roundness factor.
void AttachIControl(IControl *pControl, const char *label)
Call in the constructor of your IVControl to link the IVectorBase and IControl.
virtual void DrawLabel(IGraphics &g)
Draw the IVControl label text.
const IColor & GetColor(EVColor color) const
Get value of a specific EVColor in the IVControl.
IVStyle GetStyle() const
Get the style of this IVControl.
Used to manage a rectangular area, independent of draw class/platform.
IRECT GetReducedFromTop(float amount) const
Get a subrect of this IRECT reduced in height from the top edge by 'amount'.
IRECT FracRectHorizontal(float frac, bool rhs=false) const
Returns a new IRECT with a width that is multiplied by frac.
IRECT GetFromTop(float amount) const
Get a subrect of this IRECT bounded in Y by the top edge and 'amount'.
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.
A struct encapsulating a set of properties used to configure IVControls.