mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
Small fixes for Viewport and Identifier.
This commit is contained in:
parent
c3a9c504d6
commit
c65c07312d
8 changed files with 55 additions and 21 deletions
|
|
@ -47,7 +47,7 @@
|
|||
|
||||
If you need to get a pointer out of a ScopedPointer without it being deleted, you
|
||||
can use the release() method.
|
||||
|
||||
|
||||
Something to note is the main difference between this class and the std::auto_ptr class,
|
||||
which is that ScopedPointer provides a cast-to-object operator, wheras std::auto_ptr
|
||||
requires that you always call get() to retrieve the pointer. The advantages of providing
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ Identifier::~Identifier()
|
|||
bool Identifier::isValidIdentifier (const String& possibleIdentifier) noexcept
|
||||
{
|
||||
return possibleIdentifier.isNotEmpty()
|
||||
&& possibleIdentifier.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-:");
|
||||
&& possibleIdentifier.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-:#@$%");
|
||||
}
|
||||
|
||||
END_JUCE_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -593,7 +593,7 @@ void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
|
|||
|
||||
removeFromDesktop();
|
||||
|
||||
setTopLeftPosition (topLeft.getX(), topLeft.getY());
|
||||
setTopLeftPosition (topLeft);
|
||||
}
|
||||
|
||||
if (parentComponent != nullptr)
|
||||
|
|
@ -1063,6 +1063,11 @@ void Component::setTopLeftPosition (const int x, const int y)
|
|||
setBounds (x, y, getWidth(), getHeight());
|
||||
}
|
||||
|
||||
void Component::setTopLeftPosition (const Point<int>& pos)
|
||||
{
|
||||
setBounds (pos.getX(), pos.getY(), getWidth(), getHeight());
|
||||
}
|
||||
|
||||
void Component::setTopRightPosition (const int x, const int y)
|
||||
{
|
||||
setTopLeftPosition (x - getWidth(), y);
|
||||
|
|
|
|||
|
|
@ -415,6 +415,21 @@ public:
|
|||
*/
|
||||
void setTopLeftPosition (int x, int y);
|
||||
|
||||
/** Moves the component to a new position.
|
||||
|
||||
Changes the component's top-left position (without changing its 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.
|
||||
|
||||
@see setBounds, ComponentListener::componentMovedOrResized
|
||||
*/
|
||||
void setTopLeftPosition (const Point<int>& newTopLeftPosition);
|
||||
|
||||
/** Moves the component to a new position.
|
||||
|
||||
Changes the position of the component's top-right corner (keeping it the same size).
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ void Viewport::setViewedComponent (Component* const newViewedComponent, const bo
|
|||
if (contentComp != nullptr)
|
||||
{
|
||||
contentHolder.addAndMakeVisible (contentComp);
|
||||
setViewPosition (0, 0);
|
||||
setViewPosition (Point<int>());
|
||||
contentComp->addComponentListener (this);
|
||||
}
|
||||
|
||||
|
|
@ -99,22 +99,28 @@ void Viewport::setViewedComponent (Component* const newViewedComponent, const bo
|
|||
int Viewport::getMaximumVisibleWidth() const { return contentHolder.getWidth(); }
|
||||
int Viewport::getMaximumVisibleHeight() const { return contentHolder.getHeight(); }
|
||||
|
||||
Point<int> Viewport::viewportPosToCompPos (const Point<int>& pos) const
|
||||
{
|
||||
jassert (contentComp != nullptr);
|
||||
return Point<int> (jmax (jmin (0, contentHolder.getWidth() - contentComp->getWidth()), jmin (0, -pos.getX())),
|
||||
jmax (jmin (0, contentHolder.getHeight() - contentComp->getHeight()), jmin (0, -pos.getY())));
|
||||
}
|
||||
|
||||
void Viewport::setViewPosition (const int xPixelsOffset, const int yPixelsOffset)
|
||||
{
|
||||
if (contentComp != nullptr)
|
||||
contentComp->setTopLeftPosition (jmax (jmin (0, contentHolder.getWidth() - contentComp->getWidth()), jmin (0, -xPixelsOffset)),
|
||||
jmax (jmin (0, contentHolder.getHeight() - contentComp->getHeight()), jmin (0, -yPixelsOffset)));
|
||||
setViewPosition (Point<int> (xPixelsOffset, yPixelsOffset));
|
||||
}
|
||||
|
||||
void Viewport::setViewPosition (const Point<int>& newPosition)
|
||||
{
|
||||
setViewPosition (newPosition.getX(), newPosition.getY());
|
||||
if (contentComp != nullptr)
|
||||
contentComp->setTopLeftPosition (viewportPosToCompPos (newPosition));
|
||||
}
|
||||
|
||||
void Viewport::setViewPositionProportionately (const double x, const double y)
|
||||
{
|
||||
if (contentComp != nullptr)
|
||||
setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
|
||||
setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
|
||||
jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
|
||||
}
|
||||
|
||||
|
|
@ -247,20 +253,27 @@ void Viewport::updateVisibleArea()
|
|||
horizontalScrollBar.setVisible (hBarVisible);
|
||||
verticalScrollBar.setVisible (vBarVisible);
|
||||
|
||||
setViewPosition (visibleOrigin);
|
||||
const Point<int> newContentCompPos (viewportPosToCompPos (visibleOrigin));
|
||||
|
||||
const Rectangle<int> visibleArea (visibleOrigin.getX(), visibleOrigin.getY(),
|
||||
jmin (contentBounds.getWidth() - visibleOrigin.getX(), contentArea.getWidth()),
|
||||
jmin (contentBounds.getHeight() - visibleOrigin.getY(), contentArea.getHeight()));
|
||||
|
||||
if (lastVisibleArea != visibleArea)
|
||||
if (contentComp != nullptr && contentComp->getBounds().getPosition() != newContentCompPos)
|
||||
{
|
||||
lastVisibleArea = visibleArea;
|
||||
visibleAreaChanged (visibleArea);
|
||||
contentComp->setTopLeftPosition (newContentCompPos); // (this will re-entrantly call updateVisibleArea again)
|
||||
}
|
||||
else
|
||||
{
|
||||
const Rectangle<int> visibleArea (visibleOrigin.getX(), visibleOrigin.getY(),
|
||||
jmin (contentBounds.getWidth() - visibleOrigin.getX(), contentArea.getWidth()),
|
||||
jmin (contentBounds.getHeight() - visibleOrigin.getY(), contentArea.getHeight()));
|
||||
|
||||
horizontalScrollBar.handleUpdateNowIfNeeded();
|
||||
verticalScrollBar.handleUpdateNowIfNeeded();
|
||||
if (lastVisibleArea != visibleArea)
|
||||
{
|
||||
lastVisibleArea = visibleArea;
|
||||
visibleAreaChanged (visibleArea);
|
||||
}
|
||||
|
||||
horizontalScrollBar.handleUpdateNowIfNeeded();
|
||||
verticalScrollBar.handleUpdateNowIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -263,6 +263,7 @@ private:
|
|||
Component contentHolder;
|
||||
ScrollBar verticalScrollBar;
|
||||
ScrollBar horizontalScrollBar;
|
||||
Point<int> viewportPosToCompPos (const Point<int>&) const;
|
||||
|
||||
void updateVisibleArea();
|
||||
void deleteContentComp();
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ public:
|
|||
items.add (new PopupMenu::ItemComponent (*menu.items.getUnchecked(i), standardItemHeight, this));
|
||||
|
||||
calculateWindowPos (target, alignToRectangle);
|
||||
setTopLeftPosition (windowPos.getX(), windowPos.getY());
|
||||
setTopLeftPosition (windowPos.getPosition());
|
||||
updateYPositions();
|
||||
|
||||
if (itemIdThatMustBeVisible != 0)
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ public:
|
|||
|
||||
//if (newX != getX() || newY != getY())
|
||||
{
|
||||
setTopLeftPosition (newPos.getX(), newPos.getY());
|
||||
setTopLeftPosition (newPos);
|
||||
|
||||
Point<int> relPos;
|
||||
DragAndDropTarget* const newTarget = findTarget (screenPos, relPos);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue