25BEGIN_IGRAPHICS_NAMESPACE
32 using TabAttachFunc = std::function<void(
IVTabPage* pParent,
const IRECT& bounds)>;
33 static constexpr double kDefaultPadding = 10.0;
36 if (pTab->NChildren() == 1)
50 IVTabPage(TabAttachFunc attachFunc =
nullptr, ResizeFunc resizeFunc = DefaultResizeFunc,
const IVStyle& style = DEFAULT_STYLE,
double padding = kDefaultPadding)
65 double GetPadding()
const {
return mPadding; }
67 void SetPadding(
double padding) { mPadding = padding; }
71 ForAllChildrenFunc([
this](
int childIdx,
IControl* pChild) {
74 pVectorBase->SetStyle(GetStyle());
80 double mPadding = 0.0;
83using PageMap = std::map<const char*, IVTabPage*>;
110 const IVStyle& style = DEFAULT_STYLE,
float tabBarHeight = 20.0f,
111 float tabBarFrac = 0.5f, EAlign tabsAlign = EAlign::Near)
113 ,
IVectorBase(style.WithDrawFrame(
false).WithDrawShadows(
false))
114 , mTabBarHeight(tabBarHeight)
115 , mTabBarFrac(tabBarFrac)
116 , mTabsAlign(tabsAlign)
120 for (
auto& page : pages)
122 AddPage(page.first, page.second);
135 ForAllChildrenFunc([hide](
int childIdx,
IControl* pChild) {
146 GetTabSwitchControl()->
Hide(
false);
147 GetPage(GetTabSwitchControl()->GetSelectedIdx())->
Hide(
false);
159 auto rcrForTabCorners = mTabBarFrac == 1.0f ? 0.0f : rcr;
162 mTabsAlign == EAlign::Far ? 0.0f : rcrForTabCorners,
165 if (mStyle.drawFrame)
175 }, mPageNames,
"",
GetStyle().WithWidgetFrac(1.0f)));
177 GetTabSwitchControl()->SetShape(EVShape::EndsRounded);
181 AddChildControl(pPage);
187 GetTabSwitchControl()->
Hide(
false);
188 GetPage(0)->
Hide(
false);
193 ForAllChildrenFunc([
this](
int childIdx,
IControl* pChild) {
196 pVectorBase->SetStyle(GetStyle());
200 auto adjustedStyle =
GetStyle().WithDrawFrame(
false).WithDrawShadows(
false);
201 GetTabSwitchControl()->
SetStyle(adjustedStyle.WithWidgetFrac(1.0));
202 GetTabSwitchControl()->SetShape(EVShape::EndsRounded);
219 float GetTabHeight()
const {
return mTabBarHeight; }
223 IRECT GetTabBarArea()
const
228 int NPages()
const {
return mPages.GetSize(); }
231 void AddPage(
const char* pageName,
IVTabPage* pPage)
233 pPage->SetLabelStr(pageName);
234 mPageNames.push_back(pageName);
238 void ForAllPagesFunc(std::function<
void(
IVTabPage* pControl)> func)
240 for (
int i=0; i<mPages.GetSize(); i++)
248 IVTabPage* GetPage(
int pageIdx) {
return mPages.Get(pageIdx); }
250 void SelectPage(
int index)
252 GetTabSwitchControl()->
SetValue(
static_cast<double>(index));
257 void ShowSelectedPage()
260 bool hide = strcmp(GetTabSwitchControl()->GetSelectedLabelStr(),
261 pPage->GetLabelStr());
267 pControl->
Hide(
true);
271 WDL_PtrList<IVTabPage> mPages;
272 std::vector<const char*> mPageNames;
278END_IGRAPHICS_NAMESPACE
A collection of IControls for common UI widgets, such as knobs, sliders, switches.
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.