Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions include/sst/jucegui/component-adapters/PopupMenuParentMarker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* sst-jucegui - an open source library of juce widgets
* built by Surge Synth Team.
*
* Copyright 2023-2024, various authors, as described in the GitHub
* transaction log.
*
* sst-jucegui is released under the MIT license, as described
* by "LICENSE.md" in this repository. This means you may use this
* in commercial software if you are a JUCE Licensee. If you use JUCE
* in the open source / GPL3 context, your combined work must be
* released under GPL3.
*
* All source in sst-jucegui available at
* https://github.com/surge-synthesizer/sst-jucegui
*/

#ifndef INCLUDE_SST_JUCEGUI_COMPONENT_ADAPTERS_POPUPMENUPARENTMARKER_H
#define INCLUDE_SST_JUCEGUI_COMPONENT_ADAPTERS_POPUPMENUPARENTMARKER_H

#include <juce_gui_basics/juce_gui_basics.h>
#include <optional>

namespace sst::jucegui::component_adapters
{
/*
* This is a marker struct which, if it is in our parent
* hierarchy, we use to indicate that we are default popup
* menu parent
*/
struct PopupMenuParentMarker
{
};

} // namespace sst::jucegui::component_adapters

#endif // COMPONENTTAGS_H
6 changes: 3 additions & 3 deletions include/sst/jucegui/components/DiscreteParamMenuBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ struct DiscreteParamMenuBuilder
data::Discrete *data{nullptr};
void setData(data::Discrete *d) { data = d; };

std::function<juce::PopupMenu::Options()> createMenuOptions = []() {
return juce::PopupMenu::Options();
};
std::function<juce::PopupMenu::Options()> createMenuOptions = nullptr;

juce::PopupMenu::Options menuOptionsFor(juce::Component *) const;

/*
* The component here is used to assume the lifetime fo the data object. As long
Expand Down
27 changes: 25 additions & 2 deletions src/sst/jucegui/components/DiscreteParamMenuBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "sst/jucegui/components/DiscreteParamMenuBuilder.h"
#include "sst/jucegui/components/DiscreteParamEditor.h"
#include <cassert>
#include "sst/jucegui/component-adapters/PopupMenuParentMarker.h"

namespace sst::jucegui::components
{
Expand Down Expand Up @@ -97,7 +98,7 @@ void DiscreteParamMenuBuilder::showMenu(DiscreteParamEditor *c)
if (!data)
{
p.addSectionHeader("ERROR: No discrete data");
p.showMenuAsync(createMenuOptions());
p.showMenuAsync(menuOptionsFor(c));
return;
}

Expand All @@ -114,7 +115,7 @@ void DiscreteParamMenuBuilder::showMenu(DiscreteParamEditor *c)
break;
}

p.showMenuAsync(createMenuOptions());
p.showMenuAsync(menuOptionsFor(c));
}

int DiscreteParamMenuBuilder::jogFromValue(int fromThis, int jog)
Expand Down Expand Up @@ -158,4 +159,26 @@ int DiscreteParamMenuBuilder::jogFromValue(int fromThis, int jog)
}
return fromThis;
}

juce::PopupMenu::Options DiscreteParamMenuBuilder::menuOptionsFor(juce::Component *c) const
{
if (createMenuOptions == nullptr)
{
auto cp = c;
while (cp)
{
if (dynamic_cast<component_adapters::PopupMenuParentMarker *>(cp))
{
return juce::PopupMenu::Options().withParentComponent(cp);
}
else
{
cp = cp->getParentComponent();
}
}
return juce::PopupMenu::Options();
}
return createMenuOptions();
}

} // namespace sst::jucegui::components