Skip to content

Commit

Permalink
Some tweaks for Custom Menus
Browse files Browse the repository at this point in the history
Addressing the surge-synthesizer#4418 checklist some
  • Loading branch information
baconpaul committed Sep 12, 2021
1 parent f52eab3 commit 24cf77c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/gui/SurgeGUIEditorValueCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1746,7 +1746,6 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c
}
}

contextMenu.addSeparator();
int n_ms = 0;

for (int ms = 1; ms < n_modsources; ms++)
Expand All @@ -1761,6 +1760,7 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c
}
if (n_ms)
{
contextMenu.addSeparator();
auto sectionLabel = fmt::format("{:s} Modulations", p->get_full_name());
contextMenu.addSectionHeader(sectionLabel);

Expand Down Expand Up @@ -1890,6 +1890,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c
}
}

contextMenu.addSeparator();

// see if we have any modulators that are unassigned, then create "Add Modulation
// from..." menu
if (n_ms != n_modsources)
Expand Down
12 changes: 8 additions & 4 deletions src/gui/widgets/MenuCustomComponents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ struct TinyLittleIconButton : public juce::Component
std::function<void()> callback;
SurgeImage *icons{nullptr};
int offset{0};

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TinyLittleIconButton);
};

void MenuTitleHelpComponent::getIdealSize(int &idealWidth, int &idealHeight)
Expand Down Expand Up @@ -93,11 +95,11 @@ void MenuTitleHelpComponent::paint(juce::Graphics &g)
g.setColour(findColour(juce::PopupMenu::headerTextColourId));

auto rText = r.withTrimmedLeft(12);
g.drawText(label, rText, juce::Justification::centredLeft);
g.drawText(label, rText, juce::Justification::centred);

auto yp = 4 * 20;
auto tl = r.getTopRight();
auto clipBox = juce::Rectangle<int>(tl.x - 22, tl.y, 20, 20);
auto tl = r.getTopLeft();
auto clipBox = juce::Rectangle<int>(tl.x, tl.y, 20, 20);
g.reduceClipRegion(clipBox);
if (icons)
icons->drawAt(g, clipBox.getX(), clipBox.getY() - yp, 1.0);
Expand Down Expand Up @@ -160,7 +162,9 @@ void ModMenuCustomComponent::paint(juce::Graphics &g)
}
auto h = getHeight() - 2 * mg;
auto r = getLocalBounds().withTrimmedLeft(xp + 3 * mg + 3 * (h + mg) + mg).withTrimmedRight(4);
g.setFont(getLookAndFeel().getPopupMenuFont());
auto ft = getLookAndFeel().getPopupMenuFont();
ft = ft.withHeight(ft.getHeight() - 1);
g.setFont(ft);
g.drawText(source, r, juce::Justification::centredLeft);
g.drawText(amount, r, juce::Justification::centredRight);
}
Expand Down
6 changes: 6 additions & 0 deletions src/gui/widgets/MenuCustomComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ struct MenuTitleHelpComponent : juce::PopupMenu::CustomComponent, Surge::GUI::Sk

std::string label, url;
SurgeImage *icons{nullptr};

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MenuTitleHelpComponent);
};

struct TinyLittleIconButton;
Expand Down Expand Up @@ -68,6 +70,8 @@ struct ModMenuCustomComponent : juce::PopupMenu::CustomComponent, Surge::GUI::Sk
std::unique_ptr<TinyLittleIconButton> clear, mute, edit;
std::string source, amount;
std::function<void(OpType)> callback;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ModMenuCustomComponent);
};

struct ModMenuForAllComponent : ModMenuCustomComponent
Expand All @@ -81,6 +85,8 @@ struct ModMenuForAllComponent : ModMenuCustomComponent
ModMenuForAllComponent(std::function<void(AllAction)> callback);
std::function<void(AllAction)> allCB;
void mouseUp(const juce::MouseEvent &e) override {}

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ModMenuForAllComponent);
};
} // namespace Widgets
} // namespace Surge
Expand Down

0 comments on commit 24cf77c

Please sign in to comment.