fsh::stk
fantastic spatial holophonic synthesis toolkit
Loading...
Searching...
No Matches
Labeled.h
1/***************************************************************************************************
2 ██████ █████ █████ █████
3 ███░░███ ░░███ ░░███ ░░███
4 ░███ ░░░ █████ ░███████ ██ ██ █████ ███████ ░███ █████
5 ███████ ███░░ ░███░░███ ░░ ░░ ███░░ ░░░███░ ░███░░███
6 ░░░███░ ░░█████ ░███ ░███ ░░█████ ░███ ░██████░
7 ░███ ░░░░███ ░███ ░███ ░░░░███ ░███ ███ ░███░░███
8 █████ ██████ ████ █████ ██ ██ ██████ ░░█████ ████ █████
9 ░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░ ░░ ░░░░░░ ░░░░░ ░░░░ ░░░░░
10
11 fantastic spatial holophonic synthesis tool kit
12
13 copyright (c) fabian hummel
14 www.github.com/fshstk
15 www.fshstk.com
16
17 this file is part of the fantastic spatial holophonic synthesis toolkit (fsh::stk)
18 fsh::stk is free software: it is provided under the terms of the gnu general public license v3.0
19 www.gnu.org/licenses/gpl-3.0
20***************************************************************************************************/
21
22#pragma once
23#include "Fonts.h"
24#include "Knob.h"
25#include "StateManager.h"
26#include <juce_gui_basics/juce_gui_basics.h>
27
28namespace fsh::gui
29{
33template<typename T>
34class Labeled : public juce::Component
35{
36public:
38 struct Params
39 {
40 juce::String label;
41 typename T::Params child;
42 };
43
45 explicit Labeled(const Params& params)
46 : _params(params)
47 , _child(params.child)
48 {
49 addAndMakeVisible(_child);
50 }
51
53 void attach(plugin::StateManager& state, juce::ParameterID id) { _child.attach(state, id); }
54
55private:
56 void paint(juce::Graphics& g) override
57 {
58 g.setColour(_params.child.color);
59 g.setFont(_fonts->h4);
60
61 const auto area = getLocalBounds();
62 const auto margin = 5;
63 const auto childBottomY = _child.getBoundsInParent().getBottom() + margin;
64
65 const auto text = [this]()
66 {
67 // Only show the value for knobs, not for buttons:
68 if constexpr (std::is_same_v<decltype(_child), fsh::gui::Knob>)
69 return _child.isMouseButtonDown() ? _child.getTextFromValue(_child.getValue())
70 : _params.label.toUpperCase();
71 else
72 return _params.label.toUpperCase();
73 }();
74
75 g.drawText(text, area.withTop(childBottomY), juce::Justification::centredTop, true);
76 }
77
78 void resized() override
79 {
80 const auto offsetY = 10;
81 const auto x = getLocalBounds().getCentreX();
82 const auto y = getLocalBounds().getCentreY() - offsetY;
83 const auto childSize = 30;
84 _child.setBounds(x - (childSize / 2), y - (childSize / 2), childSize, childSize);
85 }
86
87 Fonts::Instance _fonts;
88 Params _params;
89 T _child;
90};
91} // namespace fsh::gui
Custom knob component that displays a label and a value.
Definition Knob.h:35
A component with a label.
Definition Labeled.h:35
void attach(plugin::StateManager &state, juce::ParameterID id)
Attach the child component to a parameter.
Definition Labeled.h:53
Labeled(const Params &params)
Constructor.
Definition Labeled.h:45
Base class for storing plugin state.
Definition StateManager.h:39
juce::SharedResourcePointer< Fonts > Instance
Add this as a member to your component/editor class to access the fonts.
Definition Fonts.h:58
Parameters.
Definition Labeled.h:39
juce::String label
The label to be displayed.
Definition Labeled.h:40
T::Params child
The parameters for the child component.
Definition Labeled.h:41