Skip to content

Commit

Permalink
Merge pull request #59 from ffAudio/develop
Browse files Browse the repository at this point in the history
Release 1.3.1
  • Loading branch information
ffAudio authored Mar 20, 2021
2 parents 9ba1996 + d0451ff commit 620dc0d
Show file tree
Hide file tree
Showing 17 changed files with 322 additions and 30 deletions.
11 changes: 8 additions & 3 deletions Editor/foleys_PropertiesEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ void PropertiesEditor::setNodeToEdit (juce::ValueTree node)

addDecoratorProperties();

addFlexItemProperties();

juce::Array<juce::PropertyComponent*> additional;

if (stylesheet.isClassNode (styleItem))
Expand All @@ -142,8 +144,6 @@ void PropertiesEditor::setNodeToEdit (juce::ValueTree node)
if (styleItem.getType() == IDs::view || stylesheet.isClassNode (styleItem))
addContainerProperties();

addFlexItemProperties();

if (stylesheet.isClassNode (styleItem))
nodeSelect.setText (TRANS ("Class: ") + styleItem.getType().toString(), juce::dontSendNotification);
else if (stylesheet.isTypeNode (styleItem))
Expand Down Expand Up @@ -289,6 +289,11 @@ void PropertiesEditor::addFlexItemProperties()
{
juce::Array<juce::PropertyComponent*> array;

array.add (new StyleTextPropertyComponent (builder, IDs::posX, styleItem));
array.add (new StyleTextPropertyComponent (builder, IDs::posY, styleItem));
array.add (new StyleTextPropertyComponent (builder, IDs::posWidth, styleItem));
array.add (new StyleTextPropertyComponent (builder, IDs::posHeight, styleItem));

array.add (new StyleTextPropertyComponent (builder, IDs::width, styleItem));
array.add (new StyleTextPropertyComponent (builder, IDs::height, styleItem));
array.add (new StyleTextPropertyComponent (builder, IDs::minWidth, styleItem));
Expand All @@ -300,7 +305,7 @@ void PropertiesEditor::addFlexItemProperties()
array.add (new StyleTextPropertyComponent (builder, IDs::flexOrder, styleItem));
array.add (new StyleChoicePropertyComponent (builder, IDs::flexAlignSelf, styleItem, { IDs::flexStretch, IDs::flexStart, IDs::flexEnd, IDs::flexCenter, IDs::flexAuto }));

properties.addSection ("Flex-Item", array, false);
properties.addSection ("Item", array, false);
}

void PropertiesEditor::addContainerProperties()
Expand Down
14 changes: 14 additions & 0 deletions General/foleys_MagicGUIBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ GuiItem* MagicGUIBuilder::findGuiItemWithId (const juce::String& name)
return nullptr;
}

GuiItem* MagicGUIBuilder::findGuiItem (const juce::ValueTree& node)
{
if (node.isValid() && root)
return root->findGuiItem (node);

return nullptr;
}

void MagicGUIBuilder::registerFactory (juce::Identifier type, std::unique_ptr<GuiItem>(*factory)(MagicGUIBuilder& builder, const juce::ValueTree&))
{
if (factories.find (type) != factories.cend())
Expand Down Expand Up @@ -389,10 +397,16 @@ void MagicGUIBuilder::setSelectedNode (const juce::ValueTree& node)
{
if (selectedNode != node)
{
if (auto* item = findGuiItem (selectedNode))
item->setDraggable (false);

selectedNode = node;
if (magicToolBox.get() != nullptr)
magicToolBox->setSelectedNode (selectedNode);

if (auto* item = findGuiItem (selectedNode))
item->setDraggable (true);

if (parent != nullptr)
parent->repaint();
}
Expand Down
5 changes: 5 additions & 0 deletions General/foleys_MagicGUIBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ class MagicGUIBuilder : public juce::ChangeListener
*/
GuiItem* findGuiItemWithId (const juce::String& name);

/**
Seeks recursively for a GuiItem
*/
GuiItem* findGuiItem (const juce::ValueTree& node);

/**
This selects the stylesheet node and sets it to the Stylesheet.
If no stylesheet is found, a default one is created.
Expand Down
4 changes: 4 additions & 0 deletions General/foleys_MagicPluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ void MagicPluginEditor::initialise (const char* data, int dataSize)
if (builder.get() == nullptr)
builder = createBuilderInstance();

#if FOLEYS_SAVE_EDITED_GUI_IN_PLUGIN_STATE
auto guiTree = processorState.getValueTree().getChildWithName ("magic");
if (guiTree.isValid())
setConfigTree (guiTree);
else if (data != nullptr)
setConfigTree (data, dataSize);
else
builder->createGUI (*this);
#else // FOLEYS_SAVE_EDITED_GUI_IN_PLUGIN_STATE
auto guiTree = processorState.getGuiTree();
#endif // FOLEYS_SAVE_EDITED_GUI_IN_PLUGIN_STATE

updateSize();

Expand Down
4 changes: 4 additions & 0 deletions General/foleys_MagicPluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ class MagicPluginEditor : public juce::AudioProcessorEditor,
public juce::DragAndDropContainer
{
public:
/**
Create an AudioProcessorEditor populated from a MagicGUIBuilder.
*/
MagicPluginEditor (MagicProcessorState& processorState, std::unique_ptr<MagicGUIBuilder> builder = {});

[[deprecated ("MagicPluginEditor will get the state from the processorState. Call processorState.setGuiValueTree() beforehand.")]]
MagicPluginEditor (MagicProcessorState& processorState, const char* data, const int dataSize, std::unique_ptr<MagicGUIBuilder> builder = {});

~MagicPluginEditor() override;
Expand Down
17 changes: 16 additions & 1 deletion General/foleys_MagicProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ namespace foleys
This is a convenience class to create a plugin using PluginGuiMagic. It has all wired up for you,
The MagicPluginEditor for you to design or use the generic default, the loading and saving of the state
and many more.
In the constructor you can create the GUI ValueTree either by using
\code{.cpp}
// generate a default GUI deduced from Parameters, ParameterGroups and MagicPlotSources
auto defaultGUI = magicState.createDefaultGUITree();
magicState.setGuiValueTree (defaultGUI);
// or you load an existing one from BinaryData
magicState.setGuiValueTree (BinaryData::magic_xml, BinaryData::magic_xmlSize);
\endcode
*/
class MagicProcessor : public juce::AudioProcessor
{
Expand All @@ -52,7 +62,12 @@ class MagicProcessor : public juce::AudioProcessor
MagicProcessor (const std::initializer_list<const short[2]>& channelLayoutList);

/**
Override that method to initialise the builder, register your own bespoke components or LookAndFeel classes
Override that method to initialise the builder, register your own bespoke components or LookAndFeel classes.
If you override this and you want to use the bundled components don't forget to call
\code{.cpp}
builder.registerJUCEFactories();
builder.registerJUCELookAndFeels();
\endcode
*/
virtual void initialiseBuilder (MagicGUIBuilder& builder);

Expand Down
5 changes: 5 additions & 0 deletions General/foleys_StringDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ namespace IDs
static juce::Identifier width { "width" };
static juce::Identifier height { "height" };

static juce::Identifier posX { "pos-x" };
static juce::Identifier posY { "pos-y" };
static juce::Identifier posWidth { "pos-width" };
static juce::Identifier posHeight { "pos-height" };

static juce::Identifier properties { "Properties" };
static juce::Identifier lastSize { "last-size" };
}
Expand Down
48 changes: 34 additions & 14 deletions Layout/foleys_Container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ void Container::update()

const auto display = magicBuilder.getStyleProperty (IDs::display, configNode).toString();
if (display == IDs::contents)
setLayoutMode (Container::Layout::Contents);
setLayoutMode (LayoutType::Contents);
else if (display == IDs::tabbed)
setLayoutMode (Container::Layout::Tabbed);
setLayoutMode (LayoutType::Tabbed);
else
setLayoutMode (Container::Layout::FlexBox);
setLayoutMode (LayoutType::FlexBox);

auto repaintHz = magicBuilder.getStyleProperty (IDs::repaintHz, configNode).toString();
if (repaintHz.isNotEmpty())
Expand Down Expand Up @@ -103,10 +103,22 @@ GuiItem* Container::findGuiItemWithId (const juce::String& name)
return nullptr;
}

void Container::setLayoutMode (Layout layoutToUse)
GuiItem* Container::findGuiItem (const juce::ValueTree& node)
{
if (node == configNode)
return this;

for (auto& child : children)
if (auto* item = child->findGuiItem (node))
return item;

return nullptr;
}

void Container::setLayoutMode (LayoutType layoutToUse)
{
layout = layoutToUse;
if (layout == Layout::Tabbed)
if (layout == LayoutType::Tabbed)
{
updateTabbedButtons();
}
Expand All @@ -120,6 +132,11 @@ void Container::setLayoutMode (Layout layoutToUse)
updateLayout();
}

LayoutType Container::getLayoutMode() const
{
return layout;
}

void Container::resized()
{
updateLayout();
Expand All @@ -132,27 +149,30 @@ void Container::updateLayout()

auto clientBounds = getClientBounds();

if (layout == Layout::FlexBox)
if (layout != LayoutType::Tabbed)
tabbedButtons.reset();

if (layout == LayoutType::FlexBox)
{
flexBox.items.clear();
for (auto& child : children)
flexBox.items.add (child->getFlexItem());

flexBox.performLayout (clientBounds);
}
else
else if (layout == LayoutType::Tabbed)
{
if (layout == Layout::Tabbed)
{
updateTabbedButtons();
tabbedButtons->setBounds (clientBounds.removeFromTop (30));
}
else
tabbedButtons.reset();
updateTabbedButtons();
tabbedButtons->setBounds (clientBounds.removeFromTop (30));

for (auto& child : children)
child->setBounds (clientBounds);
}
else // layout == Layout::Contents
{
for (auto& child : children)
child->setBounds (child->resolvePosition (clientBounds));
}

for (auto& child : children)
child->updateLayout();
Expand Down
31 changes: 22 additions & 9 deletions Layout/foleys_Container.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ namespace foleys

class MagicPlotComponent;

/**
The LayoutType defines after which method
*/
enum class LayoutType
{
Contents,
FlexBox,
Tabbed
};

/**
The Container is a GuiItem, that can hold multiple Components.
In the editor it is seen as "View". With the setting "display"
Expand All @@ -51,13 +61,6 @@ class Container : public GuiItem,
private juce::Timer
{
public:
enum class Layout
{
Contents,
FlexBox,
Tabbed
};

Container (MagicGUIBuilder& builder, juce::ValueTree node);

/**
Expand All @@ -76,7 +79,12 @@ class Container : public GuiItem,
/**
Sets the layout mode of the container
*/
void setLayoutMode (Layout layout);
void setLayoutMode (LayoutType layout);

/**
Returns the current layout mode
*/
LayoutType getLayoutMode() const;

void resized() override;

Expand All @@ -103,6 +111,11 @@ class Container : public GuiItem,
*/
GuiItem* findGuiItemWithId (const juce::String& name) override;

/**
Seeks recursively for a GuiItem
*/
GuiItem* findGuiItem (const juce::ValueTree& node) override;

#if FOLEYS_SHOW_GUI_EDITOR_PALLETTE
/**
This switches this node and all it's descendents in the edit
Expand All @@ -123,7 +136,7 @@ class Container : public GuiItem,
int currentTab = 0;
int refreshRateHz = 30;

Layout layout = Layout::FlexBox;
LayoutType layout = LayoutType::FlexBox;
juce::FlexBox flexBox;

std::unique_ptr<juce::TabbedButtonBar> tabbedButtons;
Expand Down
Loading

0 comments on commit 620dc0d

Please sign in to comment.