Skip to content

Commit

Permalink
Add a property 'tab-selected' to connect to a property in the state
Browse files Browse the repository at this point in the history
  • Loading branch information
ffAudio committed Jul 7, 2023
1 parent 3b92baf commit 9ed6385
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 18 deletions.
1 change: 1 addition & 0 deletions Editor/foleys_PropertiesEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ void PropertiesEditor::addContainerProperties()
array.add (new StyleTextPropertyComponent (builder, IDs::repaintHz, styleItem));
array.add (new StyleChoicePropertyComponent (builder, IDs::scrollMode, styleItem, { IDs::noScroll, IDs::scrollHorizontal, IDs::scrollVertical, IDs::scrollBoth }));
array.add (new StyleTextPropertyComponent (builder, IDs::tabHeight, styleItem));
array.add (new StyleChoicePropertyComponent (builder, IDs::selectedTab, styleItem, builder.createPropertiesMenuLambda()));

array.add (new StyleChoicePropertyComponent (builder, IDs::flexDirection, styleItem, { IDs::flexDirRow, IDs::flexDirRowReverse, IDs::flexDirColumn, IDs::flexDirColumnReverse }));
array.add (new StyleChoicePropertyComponent (builder, IDs::flexWrap, styleItem, { IDs::flexNoWrap, IDs::flexWrapNormal, IDs::flexWrapReverse }));
Expand Down
43 changes: 33 additions & 10 deletions General/foleys_MagicJUCEFactories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class TextButtonItem : public GuiItem
FOLEYS_DECLARE_GUI_FACTORY (TextButtonItem)

static const juce::Identifier pText;
static const juce::Identifier pProperty;
static const juce::Identifier pOnClick;

TextButtonItem (MagicGUIBuilder& builder, const juce::ValueTree& node) : GuiItem (builder, node)
Expand All @@ -284,13 +285,17 @@ class TextButtonItem : public GuiItem
attachment.reset();

auto parameterName = configNode.getProperty (IDs::parameter, juce::String()).toString();
auto radioValue = getProperty (IDs::buttonRadioValue);
auto radioValue = getProperty (IDs::buttonRadioValue);
auto propertyName = getProperty (pProperty).toString();

if (parameterName.isNotEmpty() && radioValue.isVoid())
attachment = getMagicState().createAttachment (parameterName, button);
else
attachment.reset();

if (propertyName.isNotEmpty())
property.referTo (getMagicState().getPropertyAsValue (propertyName));

auto groupID = static_cast<int>(getProperty (IDs::buttonRadioGroup));
if (groupID > 0)
{
Expand All @@ -301,8 +306,22 @@ class TextButtonItem : public GuiItem
button.setButtonText (magicBuilder.getStyleProperty (pText, configNode));

auto triggerID = getProperty (pOnClick).toString();
if (triggerID.isNotEmpty())
button.onClick = getMagicState().getTrigger (triggerID);
triggerToCall = triggerID.isNotEmpty() ? getMagicState().getTrigger (triggerID) : nullptr;

if (propertyName.isNotEmpty())
{
button.onClick = [this, radioValue]
{
property.setValue (radioValue);

if (triggerToCall)
triggerToCall();
};
}
else
{
button.onClick = triggerToCall;
}

handler.setRadioGroupValue(radioValue, getMagicState().getParameter(parameterName));
}
Expand All @@ -313,6 +332,7 @@ class TextButtonItem : public GuiItem

props.push_back ({ configNode, IDs::parameter, SettableProperty::Choice, {}, magicBuilder.createParameterMenuLambda() });
props.push_back ({ configNode, pText, SettableProperty::Text, {}, {} });
props.push_back ({ configNode, pProperty, SettableProperty::Choice, {}, magicBuilder.createPropertiesMenuLambda() });
props.push_back ({ configNode, pOnClick, SettableProperty::Choice, {}, magicBuilder.createTriggerMenuLambda() });
props.push_back ({ configNode, IDs::buttonRadioGroup, SettableProperty::Number, {}, {} });
props.push_back ({ configNode, IDs::buttonRadioValue, SettableProperty::Number, {}, {} });
Expand All @@ -329,11 +349,14 @@ class TextButtonItem : public GuiItem
juce::TextButton button;
RadioButtonHandler handler {button, magicBuilder.getRadioButtonManager()};
std::unique_ptr<juce::ButtonParameterAttachment> attachment;
std::function<void()> triggerToCall;
juce::Value property;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextButtonItem)
};
const juce::Identifier TextButtonItem::pText { "text" };
const juce::Identifier TextButtonItem::pOnClick { "onClick" };
const juce::Identifier TextButtonItem::pText { "text" };
const juce::Identifier TextButtonItem::pOnClick { "onClick" };
const juce::Identifier TextButtonItem::pProperty { "property" };


//==============================================================================
Expand All @@ -344,7 +367,7 @@ class ToggleButtonItem : public GuiItem
FOLEYS_DECLARE_GUI_FACTORY (ToggleButtonItem)

static const juce::Identifier pText;
static const juce::Identifier pValue;
static const juce::Identifier pProperty;

ToggleButtonItem (MagicGUIBuilder& builder, const juce::ValueTree& node) : GuiItem (builder, node)
{
Expand All @@ -371,7 +394,7 @@ class ToggleButtonItem : public GuiItem

button.setButtonText (magicBuilder.getStyleProperty (pText, configNode));

auto propertyID = getProperty (pValue).toString();
auto propertyID = getProperty (pProperty).toString();
if (propertyID.isNotEmpty())
button.getToggleStateValue().referTo (getMagicState().getPropertyAsValue (propertyID));

Expand All @@ -390,7 +413,7 @@ class ToggleButtonItem : public GuiItem
std::vector<SettableProperty> props;
props.push_back ({ configNode, pText, SettableProperty::Text, {}, {} });
props.push_back ({ configNode, IDs::parameter, SettableProperty::Choice, {}, magicBuilder.createParameterMenuLambda() });
props.push_back ({ configNode, pValue, SettableProperty::Choice, {}, magicBuilder.createPropertiesMenuLambda() });
props.push_back ({ configNode, pProperty, SettableProperty::Choice, {}, magicBuilder.createPropertiesMenuLambda() });
props.push_back ({ configNode, IDs::buttonRadioGroup, SettableProperty::Number, {}, {} });
props.push_back ({ configNode, IDs::buttonRadioValue, SettableProperty::Number, {}, {} });
return props;
Expand All @@ -408,8 +431,8 @@ class ToggleButtonItem : public GuiItem

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToggleButtonItem)
};
const juce::Identifier ToggleButtonItem::pText { "text" };
const juce::Identifier ToggleButtonItem::pValue { "value" };
const juce::Identifier ToggleButtonItem::pText { "text" };
const juce::Identifier ToggleButtonItem::pProperty { "property" };


//==============================================================================
Expand Down
1 change: 1 addition & 0 deletions General/foleys_StringDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ namespace IDs
static juce::String tabbed { "tabbed" };
static juce::String flexbox { "flexbox" };
static juce::Identifier tabHeight { "tab-height" };
static juce::Identifier selectedTab { "tab-selected" };

static juce::Identifier focusContainerType { "focus-container" };
static juce::String focusNone { "focus-none" };
Expand Down
18 changes: 17 additions & 1 deletion Layout/foleys_Container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ Container::Container (MagicGUIBuilder& builder, juce::ValueTree node)
{
addAndMakeVisible (viewport);
viewport.setViewedComponent (&containerBox, false);
currentTab.addListener (this);
}

Container::~Container()
{
currentTab.removeListener (this);
}

void Container::update()
Expand Down Expand Up @@ -74,6 +80,10 @@ void Container::update()
auto tabHeightProperty = magicBuilder.getStyleProperty (IDs::tabHeight, configNode).toString();
tabbarHeight = tabHeightProperty.isNotEmpty() ? tabHeightProperty.getIntValue() : 30;

const auto tabProperty = magicBuilder.getStyleProperty (IDs::selectedTab, configNode).toString();
if (tabProperty.isNotEmpty())
currentTab.referTo(getMagicState().getPropertyAsValue(tabProperty));

auto repaintHz = magicBuilder.getStyleProperty (IDs::repaintHz, configNode).toString();
if (repaintHz.isNotEmpty())
{
Expand Down Expand Up @@ -272,7 +282,7 @@ void Container::updateTabbedButtons()
}

tabbedButtons->addChangeListener (this);
tabbedButtons->setCurrentTabIndex (currentTab, false);
tabbedButtons->setCurrentTabIndex (currentTab.getValue(), false);
updateSelectedTab();
}

Expand Down Expand Up @@ -351,6 +361,12 @@ void Container::changeListenerCallback (juce::ChangeBroadcaster*)
updateSelectedTab();
}

void Container::valueChanged (juce::Value& source)
{
if (source == currentTab)
updateSelectedTab();
}

void Container::updateSelectedTab()
{
int index = 0;
Expand Down
10 changes: 5 additions & 5 deletions Layout/foleys_Container.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Container : public GuiItem,
{
public:
Container (MagicGUIBuilder& builder, juce::ValueTree node);
~Container();

/**
Updates the layout fo children
Expand Down Expand Up @@ -154,18 +155,17 @@ class Container : public GuiItem,
};

void changeListenerCallback (juce::ChangeBroadcaster*) override;
void valueChanged (juce::Value&) override;
void timerCallback() override;

void updateTabbedButtons();
void updateSelectedTab();

int currentTab = 0;
int tabbarHeight = 30;
int refreshRateHz = 30;

juce::Value currentTab { juce::var {0} };
int tabbarHeight = 30;
int refreshRateHz = 30;
LayoutType layout = LayoutType::FlexBox;
juce::FlexBox flexBox;

ScrollMode scrollMode = ScrollMode::NoScroll;

juce::Component containerBox;
Expand Down
2 changes: 1 addition & 1 deletion Layout/foleys_GuiItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ enum class LayoutType;
to an AudioProcessorValueTreeState.
*/
class GuiItem : public juce::Component,
private juce::Value::Listener,
public juce::Value::Listener,
private juce::ValueTree::Listener,
public juce::DragAndDropTarget
{
Expand Down
2 changes: 1 addition & 1 deletion State/foleys_MagicGUIState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void MagicGUIState::addPropertiesToMenu (const juce::ValueTree& tree, juce::Comb
for (int i=0; i < tree.getNumProperties(); ++i)
{
const auto name = tree.getPropertyName (i).toString();
menu.addItem (name, [&combo, t = path + name]
menu.addItem (name, true, false, [&combo, t = path + name]
{
combo.setText (t);
});
Expand Down
4 changes: 4 additions & 0 deletions VERSION.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ PluginGuiMagic - Versions history
- Updated updatePlayheadInformation for JUCE 7
- Added safety to RadioButtonManager
- Allow setStateInformation to occur on a background thread
- Add setting a property from a TextButton
- Changed name "value" to "property" on ToggleButton
- Allow setting of Tab-Bar height
- Add a property "tab-selected" to connect to a property in the state

1.3.8 - 31.10.2022
------------------
Expand Down

0 comments on commit 9ed6385

Please sign in to comment.