30BEGIN_IGRAPHICS_NAMESPACE
49 using EType = FaustUIItem::EType;
103 str.SetFormatted(64,
"%.2f %s", mMin +
GetValue() * (mMax - mMin), mUnit.Get());
104 g.
DrawText(mStyle.valueText, str.Get(), mWidgetBounds, &mBlend);
125 , mConfig(std::make_shared<Config>())
127 mConfig->style = style;
129 for (
int t = 0; t < kNumTypes; t++)
147 void SetPadding(
float padding) { mConfig->padding = padding; }
155 const char* label = item.label.c_str();
163 case EType::CheckButton:
169 const EDirection dir = item.type == EType::HSlider ? EDirection::Horizontal : EDirection::Vertical;
181 case EType::NumEntry:
191 case EType::HBargraph:
192 case EType::VBargraph:
195 else if (item.numerical)
198 pControl =
new IVMeterControl<1>(
IRECT(), label, style, item.type == EType::HBargraph ? EDirection::Horizontal : EDirection::Vertical);
204 if (pControl && item.tooltip.size())
213 auto constrain = [&cell](
float maxW,
float maxH) {
220 case EType::CheckButton:
221 return constrain(150.f, 60.f);
223 if (item.knob)
return constrain(100.f, 130.f);
224 if (item.menu)
return constrain(150.f, 60.f);
225 return constrain(300.f, item.radio ? 100.f : 70.f);
227 if (item.knob)
return constrain(100.f, 130.f);
228 if (item.menu)
return constrain(150.f, 60.f);
229 return constrain(item.radio ? 150.f : 70.f, 300.f);
230 case EType::NumEntry:
231 if (item.knob)
return constrain(100.f, 130.f);
232 return constrain(150.f, item.radio ? 150.f : 60.f);
233 case EType::HBargraph:
234 if (item.led)
return constrain(30.f, 30.f);
235 return constrain(300.f, item.numerical ? 50.f : 60.f);
236 case EType::VBargraph:
237 if (item.led)
return constrain(30.f, 30.f);
238 return constrain(item.numerical ? 150.f : 50.f, 300.f);
245 static constexpr int kNumTypes =
static_cast<int>(EType::Soundfile) + 1;
250 std::array<CreateControlFunc, kNumTypes> createFuncs;
253 float tabBarHeight = 25.f;
260 std::vector<int> plugParamIdx;
261 std::shared_ptr<const Config> config;
263 int GetPlugParamIdx(
const Item& item)
const
265 return (item.paramIdx > kNoParameter && item.paramIdx <
static_cast<int>(plugParamIdx.size())) ? plugParamIdx[item.paramIdx] : kNoParameter;
269 static bool IsVisible(
const Item& item)
271 return !item.hidden && item.type != EType::Soundfile;
274 static inline IControl* CreateItemControl(
const std::shared_ptr<const Context>& pContext,
const Item& item,
const IRECT& bounds =
IRECT());
277 std::shared_ptr<Config> mConfig;
283 BoxControl(
const std::shared_ptr<const Context>& pContext,
const Item& item,
const IRECT& bounds)
303 if (mStyle.drawFrame)
309 for (
const auto& child : mItem.children)
311 if (!IsVisible(child))
314 if (
IControl* pControl = CreateItemControl(mContext, child))
316 AddChildControl(pControl, child.ctrlTag);
317 mChildItems.push_back(&child);
331 const int nChildren = NChildren();
336 const float padding = mContext->config->padding;
337 const IRECT area = (HasLabel() ? mWidgetBounds : mRECT).GetPadded(-padding);
338 const EDirection dir = mItem.type == EType::HBox ? EDirection::Horizontal : EDirection::Vertical;
341 float totalWeight = 0.f;
343 for (
const Item* pChildItem : mChildItems)
344 totalWeight +=
Weight(*pChildItem, dir);
348 for (
int i = 0; i < nChildren; i++)
350 const Item& childItem = *mChildItems[i];
351 const float end = start +
Weight(childItem, dir) / totalWeight;
354 GetChild(i)->
SetTargetAndDrawRECTs(childItem.IsGroup() ? cell : mContext->config->boundsFunc(childItem, cell));
365 const bool sum = (item.type == EType::HBox && dir == EDirection::Horizontal) || (item.type == EType::VBox && dir == EDirection::Vertical);
368 for (
const auto& child : item.children)
370 if (!IsVisible(child))
373 const float childWeight =
Weight(child, dir);
374 weight = sum ? weight + childWeight : std::max(weight, childWeight);
377 return std::max(weight, 1.f);
381 bool HasLabel()
const {
return mShowLabel && !mItem.label.empty(); }
383 std::shared_ptr<const Context> mContext;
385 bool mShowLabel =
true;
386 std::vector<const Item*> mChildItems;
389IControl* IGraphicsFaustUI::CreateItemControl(
const std::shared_ptr<const Context>& pContext,
const Item& item,
const IRECT& bounds)
391 const Config& config = *pContext->config;
397 return new BoxControl(pContext, item, bounds);
400 std::vector<const Item*> visibleChildren;
402 for (
const auto& child : item.children)
404 if (IsVisible(child))
405 visibleChildren.push_back(&child);
409 if (visibleChildren.size() == 1)
410 return CreateItemControl(pContext, *visibleChildren[0], bounds);
414 for (
const auto& child : item.children)
416 if (!IsVisible(child))
419 const Item* pChild = &child;
421 auto attachFunc = [pContext, pChild](
IVTabPage* pPage,
const IRECT& bounds) {
422 if (
IControl* pControl = CreateItemControl(pContext, *pChild))
424 if (
auto* pBox = pControl->As<BoxControl>())
427 pPage->AddChildControl(pControl, pChild->ctrlTag);
432 if (pPage->NChildren() == 1)
435 pPage->GetChild(0)->SetTargetAndDrawRECTs(pChild->IsGroup() ? cell : pContext->config->boundsFunc(*pChild, cell));
439 pages.push_back({child.label.c_str(),
new IVTabPage(attachFunc, resizeFunc, config.style, 0.)});
445 return new IVTabbedPagesControl(bounds, pages, item.label.c_str(), config.style, config.tabBarHeight, 1.f);
449 const CreateControlFunc& createFunc = config.createFuncs[
static_cast<int>(item.type)];
450 return createFunc ? createFunc(item, pContext->GetPlugParamIdx(item), config.style) : nullptr;
457 auto pContext = std::make_shared<Context>();
459 pContext->config = std::make_shared<const Config>(*mConfig);
461 for (
int p = 0; p < mFaust.
NParams(); p++)
464 const Item& root = pContext->root;
466 if (root.children.empty())
469 return CreateItemControl(pContext, root, bounds);
472END_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.
IContainerBase allows a control to nest sub controls and it clips the drawing of those subcontrols In...
The lowest level base class of an IGraphics control.
void SetTargetRECT(const IRECT &bounds)
Set the rectangular mouse tracking target area, within the graphics context for this control.
virtual void SetParamIdx(int paramIdx, int valIdx=0)
Set the index of a parameter that the control is linked to If you are calling this "manually" to reus...
IControl * SetTooltip(const char *str)
Set a tooltip for the control.
virtual void SetValue(double value, int valIdx=0)
Set one of the control's values.
double GetValue(int valIdx=0) const
Get the control's value.
void SetTargetAndDrawRECTs(const IRECT &bounds)
Set BOTH the draw rect and the target area, within the graphics context for this control.
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
static float Weight(const Item &item, EDirection dir)
The relative amount of space an item needs in a direction: widgets count as 1, boxes sum their childr...
void OnAttached() override
Called after the control has been attached, and its delegate and graphics member variable set.
void HideLabel()
Don't show the label, e.g.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnResize() override
Called when IControl is constructed or resized using SetRect().
Displays a bargraph's value as text, for [style:numerical].
void OnResize() override
Called when IControl is constructed or resized using SetRect().
void Draw(IGraphics &g) override
Draw the control to the graphics context.
Builds an IGraphics user interface from the UI description of an IPlugFaust DSP, like Faust's own gen...
static IControl * DefaultCreateControl(const Item &item, int paramIdx, const IVStyle &style)
The default control for each widget type.
void SetTabBarHeight(float height)
Set the height of the tab bar for tab boxes.
IControl * CreateControl(const IRECT &bounds)
Create a control containing the whole Faust UI.
void SetControlBoundsFunc(ControlBoundsFunc func)
Replace the function that sizes the controls within their layout cells.
void SetPadding(float padding)
Set the padding between controls and around boxes.
IGraphicsFaustUI(IPlugFaust &faust, const IVStyle &style=DEFAULT_STYLE)
void SetCreateControlFunc(EType type, CreateControlFunc func)
Replace the function that creates the controls for a widget type.
std::function< IRECT(const Item &item, const IRECT &cell)> ControlBoundsFunc
Returns the bounds of a widget's control, given the cell that the layout allocated for it.
std::function< IControl *(const Item &item, int paramIdx, const IVStyle &style)> CreateControlFunc
Creates the control for a widget.
static IRECT DefaultControlBounds(const Item &item, const IRECT &cell)
Default control sizing: stops controls from stretching too much in large cells.
The lowest level base class of an IGraphics 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.
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.
IPlugFaust is the base class for hosting a Faust DSP inside an iPlug2 plug-in.
int GetPlugParamIdx(int faustParamIdx) const
const FaustUIItem & GetUIRoot() const
A vector knob control drawn using graphics primitives.
Vectorial multi-channel capable meter control, linear or log response.
A "meta control" for a number box with an Inc/Dec button It adds several child buttons if buttons = t...
A control used as the base class for a tabbed page of subcontrols.
A control to manage tabbed pages of sub controls Basic usage example:
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.
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.
A node in the description of a Faust DSP's user interface, as declared by its buildUserInterface() me...
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 FracRectVertical(float frac, bool fromTop=false) const
Returns a new IRECT with a height that is multiplied by frac.
IRECT FracRectHorizontal(float frac, bool rhs=false) const
Returns a new IRECT with a width that is multiplied by frac.
IRECT GetVShifted(float y) const
Get a copy of this rectangle translated on the Y axis.
IRECT GetHShifted(float x) const
Get a copy of this rectangle translated on the X axis.
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.