34 static int compareElements (
var first,
var second)
36 if (first.toString() > second.toString())
38 else if (first.toString() < second.toString())
57 : sourceValue (source),
67 if (
arr->contains (varToControl))
79 if (
static_cast<bool> (newValue))
81 if (temp.addIfNotAlreadyThere (varToControl) && (maxChoices != -1) && (temp.size() > maxChoices))
82 temp.remove (temp.size() - 2);
86 temp.remove (
arr->indexOf (varToControl));
118 sourceValue (value.getPropertyAsValue()),
127 auto v = value.
get();
131 if (
arr->contains (varToControl))
143 auto v = value.
get();
169 if (temp.addIfNotAlreadyThere (varToControl) && (maxChoices != -1) && (temp.size() > maxChoices))
170 temp.
remove (temp.size() - 2);
174 temp.remove (temp.indexOf (varToControl));
182 if (temp.size() == 0)
205int MultiChoicePropertyComponent::getTotalButtonsHeight (
int numButtons)
210MultiChoicePropertyComponent::MultiChoicePropertyComponent (
const String&
propertyName,
211 const StringArray& choices,
213 : PropertyComponent (
propertyName,
jmin (getTotalButtonsHeight (choices.
size()), collapsedHeight))
219 for (
auto choice : choices)
225 maxHeight = getTotalButtonsHeight (choiceButtons.size()) + expandAreaHeight;
232 expandShape.addTriangle ({ 0, 0 }, { 5, 10 }, { 10, 0});
233 expandButton.setShape (
expandShape,
true,
true,
false);
236 expandButton.onClick = [
this] {
setExpanded (! expanded); };
239 lookAndFeelChanged();
253 for (
int i = 0; i < choiceButtons.size(); ++i)
271 for (
int i = 0; i < choiceButtons.size(); ++i)
289 .removeFromBottom (expandAreaHeight).withTrimmedLeft (10),
298 auto bounds =
getLookAndFeel().getPropertyComponentContentPosition (*
this);
311 for (
auto* b : choiceButtons)
313 if (bounds.getHeight() >= buttonHeight)
315 b->setVisible (
true);
316 b->setBounds (bounds.removeFromTop (buttonHeight).reduced (5, 2));
320 b->setVisible (
false);
332 preferredHeight = expanded ? maxHeight : collapsedHeight;
337 NullCheckedInvocation::invoke (onHeightChange);
340 (
float) expandButton.getBounds().getCentreX(),
341 (
float) expandButton.getBounds().getCentreY()));
347void MultiChoicePropertyComponent::lookAndFeelChanged()
354 for (
auto* button : choiceButtons)
Holds a resizable array of primitive or copy-by-value objects.
Colour contrasting(float amount=1.0f) const noexcept
Returns a colour that will be clearly visible against this colour.
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.
void setCentrePosition(int x, int y)
Changes the position of the component's centre.
void repaint()
Marks the whole component as needing to be redrawn.
void setSize(int newWidth, int newHeight)
Changes the size of the component.
Colour findColour(int colourID, bool inheritFromParent=false) const
Looks for a colour that has been registered with the given colour ID number.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
A graphics context, used for drawing a component or image.
void drawFittedText(const String &text, int x, int y, int width, int height, Justification justificationFlags, int maximumNumberOfLines, float minimumHorizontalScale=0.0f) const
Tries to draw a text string inside a given space.
void fillRect(Rectangle< int > rectangle) const
Fills a rectangle with the current colour or brush.
void setColour(Colour newColour)
Changes the current drawing colour.
@ centredLeft
Indicates that the item should be centred vertically but placed on the left hand side.
void setValue(const var &newValue) override
Changes the current value.
var getValue() const override
Returns the current value of this object.
void setValue(const var &newValue) override
Changes the current value.
var getValue() const override
Returns the current value of this object.
A PropertyComponent that shows its value as an expandable list of ToggleButtons.
void resized() override
Called when this component's size has been changed.
void paint(Graphics &g) override
Components can override this method to draw their content.
bool isExpandable() const noexcept
Returns true if the list of options has been truncated and can be expanded.
bool isExpanded() const noexcept
Returns true if the list of options is expanded.
void setExpanded(bool expanded) noexcept
Expands or shrinks the list of options if they are not all visible.
Holds a pointer to an object which can optionally be deleted when this pointer goes out of scope.
void set(ObjectType *newObject, bool takeOwnership)
Makes this OptionalScopedPointer point at a new object, specifying whether the OptionalScopedPointer ...
int preferredHeight
Used by the PropertyPanel to determine how high this component needs to be.
void paint(Graphics &) override
The default paint method fills the background and draws a label for the item's name.
Rectangle removeFromBottom(ValueType amountToRemove) noexcept
Removes a strip from the bottom of this rectangle, reducing this rectangle by the specified amount an...
A special array for holding a list of strings.
@ backgroundColourId
The colour to use for the text component's background - this can be transparent if necessary.
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.
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.
var get() const noexcept
Returns the current value of the property.
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.
var getValue() const
Returns the current value.
A variant class, that can be used to hold a range of primitive values.
Array< var > * getArray() const noexcept
If this variant holds an array, this provides access to it.
void remove(int index)
If the var is an array, this removes one of its elements.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
@ valueChanged
Indicates that the UI element's value has changed.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Commonly used mathematical constants.