diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index b98e355b14..1f2f145a8f 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -928,7 +928,8 @@ void Component::setSize (int w, int h) { setBounds (getX(), get void Component::setTopLeftPosition (int x, int y) { setTopLeftPosition ({ x, y }); } void Component::setTopLeftPosition (Point pos) { setBounds (pos.x, pos.y, getWidth(), getHeight()); } -void Component::setTopRightPosition (int x, int y) { setTopLeftPosition (x - getWidth(), y); } +void Component::setTopRightPosition (int x, int y) { setTopRightPosition ({ x, y }); } +void Component::setTopRightPosition (Point pos) { setTopLeftPosition (pos.x - getWidth(), pos.y); } void Component::setBounds (Rectangle r) { setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight()); } void Component::setCentrePosition (Point p) { setBounds (getBounds().withCentre (p.transformedBy (getTransform().inverted()))); } diff --git a/modules/juce_gui_basics/components/juce_Component.h b/modules/juce_gui_basics/components/juce_Component.h index 620952f538..b9471a560d 100644 --- a/modules/juce_gui_basics/components/juce_Component.h +++ b/modules/juce_gui_basics/components/juce_Component.h @@ -464,6 +464,19 @@ public: */ void setTopRightPosition (int x, int y); + /** Moves the component to a new position. + + Changes the position of the component's top-right corner (keeping it the same size). + The position is relative to the top-left of the component's parent. + + If the component actually moves, this method will make a synchronous call to moved(). + + Note that if you've used setTransform() to apply a transform, then the component's + bounds will no longer be a direct reflection of the position at which it appears within + its parent, as the transform will be applied to whatever bounds you set for it. + */ + void setTopRightPosition (Point); + /** Changes the size of the component. A synchronous call to resized() will occur if the size actually changes.