35 : sourceValue (source),
43 auto targetValue = sourceValue.
getValue();
45 for (
auto& map : mappings)
46 if (map.equalsWithSameType (targetValue))
47 return mappings.indexOf (map) + 1;
49 return mappings.indexOf (targetValue) + 1;
54 auto remappedVal = mappings [
static_cast<int> (newValue) - 1];
56 if (! remappedVal.equalsWithSameType (sourceValue))
57 sourceValue = remappedVal;
77 sourceValue (value.getPropertyAsValue()),
87 const auto target = sourceValue.
getValue();
88 const auto equalsWithSameType = [&target] (
const var& map) {
return map.equalsWithSameType (target); };
90 auto iter =
std::find_if (mappings.begin(), mappings.end(), equalsWithSameType);
92 if (iter == mappings.end())
93 iter =
std::find (mappings.begin(), mappings.end(), target);
95 if (iter != mappings.end())
104 auto newValueInt =
static_cast<int> (newValue);
106 if (newValueInt == -1)
112 auto remappedVal = mappings [newValueInt - 1];
114 if (! remappedVal.equalsWithSameType (sourceValue))
122 ValueTreePropertyWithDefault value;
131ChoicePropertyComponent::ChoicePropertyComponent (
const String& name)
137ChoicePropertyComponent::ChoicePropertyComponent (
const String& name,
139 [[maybe_unused]]
const Array<var>& correspondingValues)
148ChoicePropertyComponent::ChoicePropertyComponent (
const Value& valueToControl,
164 value = valueToControl;
166 auto getDefaultString = [
this, correspondingValues] {
return choices [correspondingValues.
indexOf (value.
getDefault())]; };
168 refreshChoices (getDefaultString());
174 refreshChoices (getDefaultString());
182 choices ({
"Enabled",
"Disabled" })
184 value = valueToControl;
186 auto getDefaultString = [
this] {
return value.getDefault() ?
"Enabled" :
"Disabled"; };
188 refreshChoices (getDefaultString());
189 initialiseComboBox (Value (
new ChoiceRemapperValueSourceWithDefault (value, {
true,
false })));
191 value.onDefaultChange = [
this, getDefaultString]
193 auto selectedId = comboBox.getSelectedId();
194 refreshChoices (getDefaultString());
195 comboBox.setSelectedId (selectedId);
200void ChoicePropertyComponent::initialiseComboBox (
const Value& v)
210void ChoicePropertyComponent::refreshChoices()
216 const auto& choice =
choices[i];
218 if (choice.isNotEmpty())
219 comboBox.
addItem (choice, i + 1);
225void ChoicePropertyComponent::refreshChoices (
const String& defaultString)
228 comboBox.
addItem (
"Default" + (defaultString.isNotEmpty() ?
" (" + defaultString +
")" :
""), -1);
256 initialiseComboBox ({});
257 comboBox.
onChange = [
this] { changeIndex(); };
264void ChoicePropertyComponent::changeIndex()
Holds a resizable array of primitive or copy-by-value objects.
int indexOf(ParameterType elementToLookFor) const
Finds the index of the first element which matches the value passed in.
A PropertyComponent that shows its value as a combo box.
StringArray choices
The list of options that will be shown in the combo box.
virtual int getIndex() const
Returns the index of the item that should currently be shown.
void refresh() override
Updates the property component if the item it refers to has changed.
virtual void setIndex(int newIndex)
Called when the user selects an item from the combo box.
const StringArray & getChoices() const
Returns the list of options.
var getValue() const override
Returns the current value of this object.
void setValue(const var &newValue) override
Changes the current value.
void setValue(const var &newValue) override
Changes the current value.
var getValue() const override
Returns the current value of this object.
void valueChanged(Value &) override
Called when a Value object is changed.
void clear(NotificationType notification=sendNotificationAsync)
Removes all the items from the drop-down list.
Value & getSelectedIdAsValue()
Returns a Value object that can be used to get or set the selected item's ID.
void setSelectedId(int newItemId, NotificationType notification=sendNotificationAsync)
Sets one of the items to be the current selection.
std::function< void()> onChange
You can assign a lambda to this callback object to have it called when the selected ID is changed.
void setEditableText(bool isEditable)
Sets whether the text in the combo-box is editable.
void addSeparator()
Adds a separator line to the drop-down list.
int getSelectedId() const noexcept
Returns the ID of the item that's currently shown in the box.
void addItem(const String &newItemText, int newItemId)
Adds an item to be shown in the drop-down list.
bool isVisible() const noexcept
Tests whether the component is visible or not.
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
A base class for a component that goes in a PropertyPanel and displays one of an item's properties.
A special array for holding a list of strings.
int size() const noexcept
Returns the number of strings in the array.
This class acts as a wrapper around a property inside a ValueTree.
bool isUsingDefault() const
Returns true if the property does not exist in the referenced ValueTree.
var getDefault() const
Returns the current default value.
std::function< void()> onDefaultChange
You can assign a lambda to this callback and it will called when the default value is changed.
void resetToDefault() noexcept
Removes the property from the referenced ValueTree.
Receives callbacks when a Value object changes.
Used internally by the Value class as the base class for its shared value objects.
void sendChangeMessage(bool dispatchSynchronously)
Delivers a change message to all the listeners that are registered with this value.
Represents a shared variant value.
void addListener(Listener *listener)
Adds a listener to receive callbacks when the value changes.
void referTo(const Value &valueToReferTo)
Makes this object refer to the same underlying ValueSource as another one.
var getValue() const
Returns the current value.
A variant class, that can be used to hold a range of primitive values.
@ valueChanged
Indicates that the UI element's value has changed.
@ dontSendNotification
No notification message should be sent.