Mema
Memory Matrix — multi-channel audio matrix monitor and router
Loading...
Searching...
No Matches
CustomPopupMenuComponent.h
Go to the documentation of this file.
1/* Copyright (c) 2024-2025, Christian Ahrens
2 *
3 * This file is part of Mema <https://github.com/ChristianAhrens/Mema>
4 *
5 * This tool is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License version 3.0 as published
7 * by the Free Software Foundation.
8 *
9 * This tool is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this tool; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#pragma once
20
21#include <JuceHeader.h>
22
23
25class CustomAboutItem : public juce::PopupMenu::CustomComponent
26{
27public:
29 CustomAboutItem(juce::Component* componentToHold, juce::Rectangle<int> minIdealSize)
30 {
31 m_component = componentToHold;
32 addAndMakeVisible(m_component);
33
34 m_minIdealSize = minIdealSize;
35 }
37 {
38 if (m_component)
39 m_component->setVisible(false);
40 }
41
43 void getIdealSize(int& idealWidth, int& idealHeight) override
44 {
45 auto resultingIdealSize = juce::Rectangle<int>(idealWidth, idealHeight);
46 auto mc = juce::Desktop::getInstance().getComponent(0);
47 if (mc)
48 {
49 auto fBounds = mc->getBounds().toFloat();
50 auto h = fBounds.getHeight();
51 auto w = fBounds.getWidth();
52 if (h > 0.0f && w > 0.0f)
53 {
54 if (h > w)
55 {
56 w = 0.75f * w;
57 h = w;
58 }
59 else
60 {
61 h = 0.75f * h;
62 w = h;
63 }
64
65 resultingIdealSize = juce::Rectangle<float>(w, h).toNearestInt();
66 }
67 }
68
69 if (resultingIdealSize.getWidth() < m_minIdealSize.getWidth() && resultingIdealSize.getHeight() < m_minIdealSize.getHeight())
70 {
71 idealWidth = m_minIdealSize.getWidth();
72 idealHeight = m_minIdealSize.getHeight();
73 }
74 else
75 {
76 idealWidth = resultingIdealSize.getWidth();
77 idealHeight = resultingIdealSize.getHeight();
78 }
79 }
80
82 void resized() override
83 {
84 if (m_component)
85 m_component->setBounds(getLocalBounds());
86 }
87
88private:
89 juce::Component* m_component = nullptr;
90 juce::Rectangle<int> m_minIdealSize;
91};
92
void resized() override
Resizes the held component to fill the item bounds.
CustomAboutItem(juce::Component *componentToHold, juce::Rectangle< int > minIdealSize)
Constructs the item, holding the given component with a minimum size hint.
void getIdealSize(int &idealWidth, int &idealHeight) override
Returns the ideal display size for this item, scaled to the main window.