Skip to content

Commit

Permalink
implement colour picker toggle and callback in dropdown selector comp…
Browse files Browse the repository at this point in the history
…onent
  • Loading branch information
vsicurella committed Jul 28, 2024
1 parent 28299db commit def673c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
57 changes: 48 additions & 9 deletions Source/components/ColourDropdownSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,33 @@ void ColourDropdownSelector::setShowPicker(bool show)
colourPickerButton->setVisible(show);
}

void ColourDropdownSelector::setSelectedColour(juce::Colour newColour, bool setText)
{
if (!newColour.isOpaque())
return; // Don't allow transparency

if (newColour != lastSetColour)
{
lastSetColour = newColour;
selectorListeners.call(&ColourSelectionListener::colourChangedCallback, this, lastSetColour);
}

if (setText)
{
colourEditorBox->setText(lastSetColour.toDisplayString(false), juce::NotificationType::dontSendNotification);
}

callbackColourChanged();
}

void ColourDropdownSelector::setOnValueChangeCallback(std::function<void()> callbackIn)
{
callback = callbackIn;
callbackColourChanged = callbackIn;
}

void ColourDropdownSelector::setColourPickerChangedCallback(std::function<void()> callback)
{
callbackPickerChanged = callback;
}

juce::Array<juce::Colour> ColourDropdownSelector::getColourOptions() const
Expand All @@ -88,6 +112,18 @@ juce::Array<juce::Colour> ColourDropdownSelector::getColourOptions() const
void ColourDropdownSelector::colourChangedCallback(ColourSelectionBroadcaster* source, juce::Colour newColour)
{
// todo
if (pickerIsListening)
{
setSelectedColour(newColour);

colourPickerButton->setToggleState(false, juce::NotificationType::sendNotification);
pickerIsListening = false;

colourPickerButton->setColour(juce::TextButton::ColourIds::buttonColourId, newColour);
colourPickerButton->setColour(juce::TextButton::ColourIds::buttonOnColourId, newColour);

// callbackPickerChanged();
}
}

juce::Colour ColourDropdownSelector::getSelectedColour()
Expand Down Expand Up @@ -145,16 +181,19 @@ void ColourDropdownSelector::valueChangedCallback()
selectedColour = juce::Colour::fromString("ff" + colourEditorBox->getText());
}

if (selectedColour != lastSetColour)
{
lastSetColour = selectedColour;
selectorListeners.call(&ColourSelectionListener::colourChangedCallback, this, lastSetColour);
}

callback();
setSelectedColour(selectedColour, false);
}

void ColourDropdownSelector::togglePickerListenForColour(bool listening)
{
colourPickerButton->setColour(LumatoneEditorColourIDs::OutlineColourId, juce::Colours::white);
pickerIsListening = listening;
if (pickerIsListening)
{
colourPickerButton->setColour(LumatoneEditorColourIDs::OutlineColourId, juce::Colours::white);
callbackPickerChanged();
}
else
{
colourPickerButton->setColour(LumatoneEditorColourIDs::OutlineColourId, juce::Colour());
}
}
7 changes: 6 additions & 1 deletion Source/components/ColourDropdownSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ class ColourDropdownSelector : public juce::Component
void setShowDropdown(bool show);
void setShowPicker(bool show);

void setSelectedColour(juce::Colour newColour, bool setText=true);

void setOnValueChangeCallback(std::function<void()> callback);
void setColourPickerChangedCallback(std::function<void()> callback);

juce::Array<juce::Colour> getColourOptions() const;

Expand All @@ -55,8 +58,10 @@ class ColourDropdownSelector : public juce::Component
std::unique_ptr<juce::TextButton> colourPickerButton;

juce::Colour lastSetColour;
bool pickerIsListening = false;

std::function<void()> callback = [](){};
std::function<void()> callbackColourChanged = [](){};
std::function<void()> callbackPickerChanged = [](){};

bool showDropdown = true;
bool showPicker = false;
Expand Down
7 changes: 7 additions & 0 deletions Source/mapping_editors/MultiSelectControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ MultiSelectControls::MultiSelectControls(const LumatoneEditorState& stateIn)
auto matchingKeyCoords = getMappingData()->getKeysWithProperties(properties);
performAction(SetKeySelectionAction::NewSetKeySelectionActionByCoords(*this, matchingKeyCoords));
});

addColourSelectionListener(colourDropdown.get());
colourDropdown->setColourPickerChangedCallback([&]()
{
addColourSelectionListener(colourDropdown.get());
});

addAndMakeVisible(colourDropdown.get());
colourDropdown->setShowPicker(true);

Expand Down

0 comments on commit def673c

Please sign in to comment.