This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathPresetListBox.h
74 lines (61 loc) · 1.94 KB
/
PresetListBox.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once
class PresetListBox : public juce::ListBoxModel,
public juce::ChangeBroadcaster,
public juce::ChangeListener
{
public:
PresetListBox()
{
settings->addChangeListener (this);
}
~PresetListBox() override
{
settings->removeChangeListener (this);
}
void setPresetsNode (juce::ValueTree node)
{
presets = node;
sendChangeMessage();
}
int getNumRows() override
{
return presets.getNumChildren();
}
void listBoxItemClicked (int rowNumber, const juce::MouseEvent& event) override
{
if (event.mods.isPopupMenu())
{
juce::PopupMenu::Options options;
juce::PopupMenu menu;
menu.addItem ("Remove", [this, rowNumber]()
{
presets.removeChild (rowNumber, nullptr);
});
menu.showMenuAsync (options);
}
if (onSelectionChanged)
onSelectionChanged (rowNumber);
}
void paintListBoxItem (int rowNumber, juce::Graphics &g, int width, int height, bool rowIsSelected) override
{
auto bounds = juce::Rectangle<int> (0, 0, width, height);
if (rowIsSelected)
{
g.setColour (juce::Colours::grey);
g.fillRect (bounds);
}
g.setColour (juce::Colours::silver);
g.drawFittedText (presets.getChild (rowNumber).getProperty ("name", "foo").toString(), bounds, juce::Justification::centredLeft, 1);
}
void changeListenerCallback (juce::ChangeBroadcaster*) override
{
presets = settings->settings.getOrCreateChildWithName ("presets", nullptr);
// forward to ListBox
sendChangeMessage();
}
std::function<void(int rowNumber)> onSelectionChanged;
private:
juce::ValueTree presets;
foleys::SharedApplicationSettings settings;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PresetListBox)
};