A Viewport is used to contain a larger child component, and allows the child to be automatically scrolled around. More...
Inherits Component, ComponentListener, and ScrollBar::Listener.
Classes | |
| struct | Ids |
Public Member Functions | |
| Viewport (const String &componentName=String::empty) | |
| Creates a Viewport. | |
| ~Viewport () | |
| Destructor. | |
| void | setViewedComponent (Component *newViewedComponent, bool deleteComponentWhenNoLongerNeeded=true) |
| Sets the component that this viewport will contain and scroll around. | |
| Component * | getViewedComponent () const noexcept |
| Returns the component that's currently being used inside the Viewport. | |
| void | setViewPosition (int xPixelsOffset, int yPixelsOffset) |
| Changes the position of the viewed component. | |
| void | setViewPosition (const Point< int > &newPosition) |
| Changes the position of the viewed component. | |
| void | setViewPositionProportionately (double proportionX, double proportionY) |
| Changes the view position as a proportion of the distance it can move. | |
| bool | autoScroll (int mouseX, int mouseY, int distanceFromEdge, int maximumSpeed) |
| If the specified position is at the edges of the viewport, this method scrolls the viewport to bring that position nearer to the centre. | |
| const Point< int > & | getViewPosition () const noexcept |
| Returns the position within the child component of the top-left of its visible area. | |
| int | getViewPositionX () const noexcept |
| Returns the position within the child component of the top-left of its visible area. | |
| int | getViewPositionY () const noexcept |
| Returns the position within the child component of the top-left of its visible area. | |
| int | getViewWidth () const noexcept |
| Returns the width of the visible area of the child component. | |
| int | getViewHeight () const noexcept |
| Returns the height of the visible area of the child component. | |
| int | getMaximumVisibleWidth () const |
| Returns the width available within this component for the contents. | |
| int | getMaximumVisibleHeight () const |
| Returns the height available within this component for the contents. | |
| virtual void | visibleAreaChanged (const Rectangle< int > &newVisibleArea) |
| Callback method that is called when the visible area changes. | |
| virtual void | viewedComponentChanged (Component *newComponent) |
| Callback method that is called when the viewed component is added, removed or swapped. | |
| void | setScrollBarsShown (bool showVerticalScrollbarIfNeeded, bool showHorizontalScrollbarIfNeeded) |
| Turns scrollbars on or off. | |
| bool | isVerticalScrollBarShown () const noexcept |
| True if the vertical scrollbar is enabled. | |
| bool | isHorizontalScrollBarShown () const noexcept |
| True if the horizontal scrollbar is enabled. | |
| void | setScrollBarThickness (int thickness) |
| Changes the width of the scrollbars. | |
| int | getScrollBarThickness () const |
| Returns the thickness of the scrollbars. | |
| void | setSingleStepSizes (int stepX, int stepY) |
| Changes the distance that a single-step click on a scrollbar button will move the viewport. | |
| void | setScrollBarButtonVisibility (bool buttonsVisible) |
| Shows or hides the buttons on any scrollbars that are used. | |
| ScrollBar * | getVerticalScrollBar () noexcept |
| Returns a pointer to the scrollbar component being used. | |
| ScrollBar * | getHorizontalScrollBar () noexcept |
| Returns a pointer to the scrollbar component being used. | |
| void | refreshFromValueTree (const ValueTree &, ComponentBuilder &) |
| void | resized () |
| void | scrollBarMoved (ScrollBar *scrollBarThatHasMoved, double newRangeStart) |
| void | mouseWheelMove (const MouseEvent &e, float wheelIncrementX, float wheelIncrementY) |
| bool | keyPressed (const KeyPress &key) |
| void | componentMovedOrResized (Component &component, bool wasMoved, bool wasResized) |
| bool | useMouseWheelMoveIfNeeded (const MouseEvent &e, float wheelIncrementX, float wheelIncrementY) |
A Viewport is used to contain a larger child component, and allows the child to be automatically scrolled around.
To use a Viewport, just create one and set the component that goes inside it using the setViewedComponent() method. When the child component changes size, the Viewport will adjust its scrollbars accordingly.
A subclass of the viewport can be created which will receive calls to its visibleAreaChanged() method when the subcomponent changes position or size.
| Viewport::Viewport | ( | const String & | componentName = String::empty | ) | [explicit] |
Creates a Viewport.
The viewport is initially empty - use the setViewedComponent() method to add a child component for it to manage.
Destructor.
| void Viewport::setViewedComponent | ( | Component * | newViewedComponent, |
| bool | deleteComponentWhenNoLongerNeeded = true |
||
| ) |
Sets the component that this viewport will contain and scroll around.
This will add the given component to this Viewport and position it at (0, 0).
(Don't add or remove any child components directly using the normal Component::addChildComponent() methods).
| newViewedComponent | the component to add to this viewport, or null to remove the current component. |
| deleteComponentWhenNoLongerNeeded | if true, the component will be deleted automatically when the viewport is deleted or when a different component is added. If false, the caller must manage the lifetime of the component |
| Component* Viewport::getViewedComponent | ( | ) | const |
Returns the component that's currently being used inside the Viewport.
| void Viewport::setViewPosition | ( | int | xPixelsOffset, |
| int | yPixelsOffset | ||
| ) |
Changes the position of the viewed component.
The inner component will be moved so that the pixel at the top left of the viewport will be the pixel at position (xPixelsOffset, yPixelsOffset) within the inner component.
This will update the scrollbars and might cause a call to visibleAreaChanged().
| void Viewport::setViewPosition | ( | const Point< int > & | newPosition | ) |
Changes the position of the viewed component.
The inner component will be moved so that the pixel at the top left of the viewport will be the pixel at the specified coordinates within the inner component.
This will update the scrollbars and might cause a call to visibleAreaChanged().
| void Viewport::setViewPositionProportionately | ( | double | proportionX, |
| double | proportionY | ||
| ) |
Changes the view position as a proportion of the distance it can move.
The values here are from 0.0 to 1.0 - where (0, 0) would put the visible area in the top-left, and (1, 1) would put it as far down and to the right as it's possible to go whilst keeping the child component on-screen.
| bool Viewport::autoScroll | ( | int | mouseX, |
| int | mouseY, | ||
| int | distanceFromEdge, | ||
| int | maximumSpeed | ||
| ) |
If the specified position is at the edges of the viewport, this method scrolls the viewport to bring that position nearer to the centre.
Call this if you're dragging an object inside a viewport and want to make it scroll when the user approaches an edge. You might also find Component::beginDragAutoRepeat() useful when auto-scrolling.
| mouseX | the x position, relative to the Viewport's top-left |
| mouseY | the y position, relative to the Viewport's top-left |
| distanceFromEdge | specifies how close to an edge the position needs to be before the viewport should scroll in that direction |
| maximumSpeed | the maximum number of pixels that the viewport is allowed to scroll by. |
| const Point<int>& Viewport::getViewPosition | ( | ) | const |
Returns the position within the child component of the top-left of its visible area.
| int Viewport::getViewPositionX | ( | ) | const |
Returns the position within the child component of the top-left of its visible area.
| int Viewport::getViewPositionY | ( | ) | const |
Returns the position within the child component of the top-left of its visible area.
| int Viewport::getViewWidth | ( | ) | const |
Returns the width of the visible area of the child component.
This may be less than the width of this Viewport if there's a vertical scrollbar or if the child component is itself smaller.
| int Viewport::getViewHeight | ( | ) | const |
Returns the height of the visible area of the child component.
This may be less than the height of this Viewport if there's a horizontal scrollbar or if the child component is itself smaller.
| int Viewport::getMaximumVisibleWidth | ( | ) | const |
Returns the width available within this component for the contents.
This will be the width of the viewport component minus the width of a vertical scrollbar (if visible).
| int Viewport::getMaximumVisibleHeight | ( | ) | const |
Returns the height available within this component for the contents.
This will be the height of the viewport component minus the space taken up by a horizontal scrollbar (if visible).
| virtual void Viewport::visibleAreaChanged | ( | const Rectangle< int > & | newVisibleArea | ) | [virtual] |
Callback method that is called when the visible area changes.
This will be called when the visible area is moved either be scrolling or by calls to setViewPosition(), etc.
| virtual void Viewport::viewedComponentChanged | ( | Component * | newComponent | ) | [virtual] |
Callback method that is called when the viewed component is added, removed or swapped.
| void Viewport::setScrollBarsShown | ( | bool | showVerticalScrollbarIfNeeded, |
| bool | showHorizontalScrollbarIfNeeded | ||
| ) |
Turns scrollbars on or off.
If set to false, the scrollbars won't ever appear. When true (the default) they will appear only when needed.
| bool Viewport::isVerticalScrollBarShown | ( | ) | const |
True if the vertical scrollbar is enabled.
| bool Viewport::isHorizontalScrollBarShown | ( | ) | const |
True if the horizontal scrollbar is enabled.
| void Viewport::setScrollBarThickness | ( | int | thickness | ) |
Changes the width of the scrollbars.
If this isn't specified, the default width from the LookAndFeel class will be used.
| int Viewport::getScrollBarThickness | ( | ) | const |
Returns the thickness of the scrollbars.
| void Viewport::setSingleStepSizes | ( | int | stepX, |
| int | stepY | ||
| ) |
Changes the distance that a single-step click on a scrollbar button will move the viewport.
| void Viewport::setScrollBarButtonVisibility | ( | bool | buttonsVisible | ) |
Shows or hides the buttons on any scrollbars that are used.
Returns a pointer to the scrollbar component being used.
Handy if you need to customise the bar somehow.
Returns a pointer to the scrollbar component being used.
Handy if you need to customise the bar somehow.
| void Viewport::refreshFromValueTree | ( | const ValueTree & | , |
| ComponentBuilder & | |||
| ) |
| void Viewport::resized | ( | ) | [virtual] |
Reimplemented from Component.
| void Viewport::scrollBarMoved | ( | ScrollBar * | scrollBarThatHasMoved, |
| double | newRangeStart | ||
| ) | [virtual] |
Implements ScrollBar::Listener.
| void Viewport::mouseWheelMove | ( | const MouseEvent & | e, |
| float | wheelIncrementX, | ||
| float | wheelIncrementY | ||
| ) | [virtual] |
Reimplemented from Component.
| bool Viewport::keyPressed | ( | const KeyPress & | key | ) | [virtual] |
Reimplemented from Component.
| void Viewport::componentMovedOrResized | ( | Component & | component, |
| bool | wasMoved, | ||
| bool | wasResized | ||
| ) | [virtual] |
Reimplemented from ComponentListener.
| bool Viewport::useMouseWheelMoveIfNeeded | ( | const MouseEvent & | e, |
| float | wheelIncrementX, | ||
| float | wheelIncrementY | ||
| ) |