Umsci
Upmix Spatial Control Interface — OCA/OCP.1 spatial audio utility
Loading...
Searching...
No Matches
CustomPopupMenuComponent.h
Go to the documentation of this file.
1/* Copyright (c) 2026, Christian Ahrens
2 *
3 * This file is part of Umsci <https://github.com/ChristianAhrens/Umsci>
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
36class CustomAboutItem : public juce::PopupMenu::CustomComponent
37{
38public:
39 CustomAboutItem(juce::Component* componentToHold, juce::Rectangle<int> minIdealSize)
40 {
41 m_component = componentToHold;
42 addAndMakeVisible(m_component);
43
44 m_minIdealSize = minIdealSize;
45 }
47 {
48 if (m_component)
49 m_component->setVisible(false);
50 }
51
52 void getIdealSize(int& idealWidth, int& idealHeight) override
53 {
54 auto resultingIdealSize = juce::Rectangle<int>(idealWidth, idealHeight);
55 auto mc = juce::Desktop::getInstance().getComponent(0);
56 if (mc)
57 {
58 auto fBounds = mc->getBounds().toFloat();
59 auto h = fBounds.getHeight();
60 auto w = fBounds.getWidth();
61 if (h > 0.0f && w > 0.0f)
62 {
63 if (h > w)
64 {
65 w = 0.75f * w;
66 h = w;
67 }
68 else
69 {
70 h = 0.75f * h;
71 w = h;
72 }
73
74 resultingIdealSize = juce::Rectangle<float>(w, h).toNearestInt();
75 }
76 }
77
78 if (resultingIdealSize.getWidth() < m_minIdealSize.getWidth() && resultingIdealSize.getHeight() < m_minIdealSize.getHeight())
79 {
80 idealWidth = m_minIdealSize.getWidth();
81 idealHeight = m_minIdealSize.getHeight();
82 }
83 else
84 {
85 idealWidth = resultingIdealSize.getWidth();
86 idealHeight = resultingIdealSize.getHeight();
87 }
88 }
89
90 void resized() override
91 {
92 if (m_component)
93 m_component->setBounds(getLocalBounds());
94 }
95
96private:
97 juce::Component* m_component = nullptr;
98 juce::Rectangle<int> m_minIdealSize;
99};
100
A juce::PopupMenu::CustomComponent wrapper that embeds an arbitrary juce::Component as a full-size it...
CustomAboutItem(juce::Component *componentToHold, juce::Rectangle< int > minIdealSize)
void getIdealSize(int &idealWidth, int &idealHeight) override