A scrollbar component. More...
Inherits Component, AsyncUpdater, and Timer.
Classes | |
| class | Listener |
| A class for receiving events from a ScrollBar. More... | |
Public Types | |
| enum | ColourIds { backgroundColourId = 0x1000300, thumbColourId = 0x1000400, trackColourId = 0x1000401 } |
A set of colour IDs to use to change the colour of various aspects of the component. More... | |
Public Member Functions | |
| ScrollBar (bool isVertical, bool buttonsAreVisible=true) | |
| Creates a Scrollbar. | |
| ~ScrollBar () | |
| Destructor. | |
| bool | isVertical () const noexcept |
| Returns true if the scrollbar is vertical, false if it's horizontal. | |
| void | setOrientation (bool shouldBeVertical) |
| Changes the scrollbar's direction. | |
| void | setButtonVisibility (bool buttonsAreVisible) |
| Shows or hides the scrollbar's buttons. | |
| void | setAutoHide (bool shouldHideWhenFullRange) |
| Tells the scrollbar whether to make itself invisible when not needed. | |
| bool | autoHides () const noexcept |
| Returns true if this scrollbar is set to auto-hide when its thumb is as big as its maximum range. | |
| void | setRangeLimits (const Range< double > &newRangeLimit) |
| Sets the minimum and maximum values that the bar will move between. | |
| void | setRangeLimits (double minimum, double maximum) |
| Sets the minimum and maximum values that the bar will move between. | |
| const Range< double > | getRangeLimit () const noexcept |
| Returns the current limits on the thumb position. | |
| double | getMinimumRangeLimit () const noexcept |
| Returns the lower value that the thumb can be set to. | |
| double | getMaximumRangeLimit () const noexcept |
| Returns the upper value that the thumb can be set to. | |
| void | setCurrentRange (const Range< double > &newRange) |
| Changes the position of the scrollbar's 'thumb'. | |
| void | setCurrentRange (double newStart, double newSize) |
| Changes the position of the scrollbar's 'thumb'. | |
| void | setCurrentRangeStart (double newStart) |
| Moves the bar's thumb position. | |
| const Range< double > | getCurrentRange () const noexcept |
| Returns the current thumb range. | |
| double | getCurrentRangeStart () const noexcept |
| Returns the position of the top of the thumb. | |
| double | getCurrentRangeSize () const noexcept |
| Returns the current size of the thumb. | |
| void | setSingleStepSize (double newSingleStepSize) |
| Sets the amount by which the up and down buttons will move the bar. | |
| void | moveScrollbarInSteps (int howManySteps) |
| Moves the scrollbar by a number of single-steps. | |
| void | moveScrollbarInPages (int howManyPages) |
| Moves the scroll bar up or down in pages. | |
| void | scrollToTop () |
| Scrolls to the top (or left). | |
| void | scrollToBottom () |
| Scrolls to the bottom (or right). | |
| void | setButtonRepeatSpeed (int initialDelayInMillisecs, int repeatDelayInMillisecs, int minimumDelayInMillisecs=-1) |
| Changes the delay before the up and down buttons autorepeat when they are held down. | |
| void | addListener (Listener *listener) |
| Registers a listener that will be called when the scrollbar is moved. | |
| void | removeListener (Listener *listener) |
| Deregisters a previously-registered listener. | |
| bool | keyPressed (const KeyPress &key) |
| Called when a key is pressed. | |
| void | mouseWheelMove (const MouseEvent &e, float wheelIncrementX, float wheelIncrementY) |
| Called when the mouse-wheel is moved. | |
| void | lookAndFeelChanged () |
| Called to let the component react to a change in the look-and-feel setting. | |
| void | handleAsyncUpdate () |
| Called back to do whatever your class needs to do. | |
| void | mouseDown (const MouseEvent &e) |
| Called when a mouse button is pressed while it's over this component. | |
| void | mouseDrag (const MouseEvent &e) |
| Called when the mouse is moved while a button is held down. | |
| void | mouseUp (const MouseEvent &e) |
| Called when a mouse button is released. | |
| void | paint (Graphics &g) |
| Components can override this method to draw their content. | |
| void | resized () |
| Called when this component's size has been changed. | |
A scrollbar component.
To use a scrollbar, set up its total range using the setRangeLimits() method - this sets the range of values it can represent. Then you can use setCurrentRange() to change the position and size of the scrollbar's 'thumb'.
Registering a ScrollBar::Listener with the scrollbar will allow you to find out when the user moves it, and you can use the getCurrentRangeStart() to find out where they moved it to.
The scrollbar will adjust its own visibility according to whether its thumb size allows it to actually be scrolled.
For most purposes, it's probably easier to use a ViewportContainer or ListBox instead of handling a scrollbar directly.
| enum ScrollBar::ColourIds |
A set of colour IDs to use to change the colour of various aspects of the component.
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour() methods.
| ScrollBar::ScrollBar | ( | bool | isVertical, |
| bool | buttonsAreVisible = true |
||
| ) |
Creates a Scrollbar.
| isVertical | whether it should be a vertical or horizontal bar |
| buttonsAreVisible | whether to show the up/down or left/right buttons |
| ScrollBar::~ScrollBar | ( | ) |
Destructor.
| bool ScrollBar::isVertical | ( | ) | const |
Returns true if the scrollbar is vertical, false if it's horizontal.
| void ScrollBar::setOrientation | ( | bool | shouldBeVertical ) |
Changes the scrollbar's direction.
You'll also need to resize the bar appropriately - this just changes its internal layout.
| shouldBeVertical | true makes it vertical; false makes it horizontal. |
| void ScrollBar::setButtonVisibility | ( | bool | buttonsAreVisible ) |
Shows or hides the scrollbar's buttons.
| void ScrollBar::setAutoHide | ( | bool | shouldHideWhenFullRange ) |
Tells the scrollbar whether to make itself invisible when not needed.
The default behaviour is for a scrollbar to become invisible when the thumb fills the whole of its range (i.e. when it can't be moved). Setting this value to false forces the bar to always be visible.
| bool ScrollBar::autoHides | ( | ) | const |
Returns true if this scrollbar is set to auto-hide when its thumb is as big as its maximum range.
| void ScrollBar::setRangeLimits | ( | const Range< double > & | newRangeLimit ) |
Sets the minimum and maximum values that the bar will move between.
The bar's thumb will always be constrained so that the entire thumb lies within this range.
| void ScrollBar::setRangeLimits | ( | double | minimum, |
| double | maximum | ||
| ) |
Sets the minimum and maximum values that the bar will move between.
The bar's thumb will always be constrained so that the entire thumb lies within this range.
| const Range<double> ScrollBar::getRangeLimit | ( | ) | const |
Returns the current limits on the thumb position.
| double ScrollBar::getMinimumRangeLimit | ( | ) | const |
Returns the lower value that the thumb can be set to.
This is the value set by setRangeLimits().
| double ScrollBar::getMaximumRangeLimit | ( | ) | const |
Returns the upper value that the thumb can be set to.
This is the value set by setRangeLimits().
| void ScrollBar::setCurrentRange | ( | const Range< double > & | newRange ) |
Changes the position of the scrollbar's 'thumb'.
If this method call actually changes the scrollbar's position, it will trigger an asynchronous call to ScrollBar::Listener::scrollBarMoved() for all the listeners that are registered.
| void ScrollBar::setCurrentRange | ( | double | newStart, |
| double | newSize | ||
| ) |
Changes the position of the scrollbar's 'thumb'.
This sets both the position and size of the thumb - to just set the position without changing the size, you can use setCurrentRangeStart().
If this method call actually changes the scrollbar's position, it will trigger an asynchronous call to ScrollBar::Listener::scrollBarMoved() for all the listeners that are registered.
| newStart | the top (or left) of the thumb, in the range getMinimumRangeLimit() <= newStart <= getMaximumRangeLimit(). If the value is beyond these limits, it will be clipped. |
| newSize | the size of the thumb, such that getMinimumRangeLimit() <= newStart + newSize <= getMaximumRangeLimit(). If the size is beyond these limits, it will be clipped. |
| void ScrollBar::setCurrentRangeStart | ( | double | newStart ) |
Moves the bar's thumb position.
This will move the thumb position without changing the thumb size. Note that the maximum thumb start position is (getMaximumRangeLimit() - getCurrentRangeSize()).
If this method call actually changes the scrollbar's position, it will trigger an asynchronous call to ScrollBar::Listener::scrollBarMoved() for all the listeners that are registered.
| const Range<double> ScrollBar::getCurrentRange | ( | ) | const |
Returns the current thumb range.
| double ScrollBar::getCurrentRangeStart | ( | ) | const |
Returns the position of the top of the thumb.
| double ScrollBar::getCurrentRangeSize | ( | ) | const |
Returns the current size of the thumb.
| void ScrollBar::setSingleStepSize | ( | double | newSingleStepSize ) |
Sets the amount by which the up and down buttons will move the bar.
The value here is in terms of the total range, and is added or subtracted from the thumb position when the user clicks an up/down (or left/right) button.
| void ScrollBar::moveScrollbarInSteps | ( | int | howManySteps ) |
Moves the scrollbar by a number of single-steps.
This will move the bar by a multiple of its single-step interval (as specified using the setSingleStepSize() method).
A positive value here will move the bar down or to the right, a negative value moves it up or to the left.
| void ScrollBar::moveScrollbarInPages | ( | int | howManyPages ) |
Moves the scroll bar up or down in pages.
This will move the bar by a multiple of its current thumb size, effectively doing a page-up or down.
A positive value here will move the bar down or to the right, a negative value moves it up or to the left.
| void ScrollBar::scrollToTop | ( | ) |
Scrolls to the top (or left).
This is the same as calling setCurrentRangeStart (getMinimumRangeLimit());
| void ScrollBar::scrollToBottom | ( | ) |
Scrolls to the bottom (or right).
This is the same as calling setCurrentRangeStart (getMaximumRangeLimit() - getCurrentRangeSize());
| void ScrollBar::setButtonRepeatSpeed | ( | int | initialDelayInMillisecs, |
| int | repeatDelayInMillisecs, | ||
| int | minimumDelayInMillisecs = -1 |
||
| ) |
Changes the delay before the up and down buttons autorepeat when they are held down.
For an explanation of what the parameters are for, see Button::setRepeatSpeed().
| void ScrollBar::addListener | ( | Listener * | listener ) |
Registers a listener that will be called when the scrollbar is moved.
| void ScrollBar::removeListener | ( | Listener * | listener ) |
Deregisters a previously-registered listener.
| bool ScrollBar::keyPressed | ( | const KeyPress & | key ) | [virtual] |
Called when a key is pressed.
When a key is pressed, the component that has the keyboard focus will have this method called. Remember that a component will only be given the focus if its setWantsKeyboardFocus() method has been used to enable this.
If your implementation returns true, the event will be consumed and not passed on to any other listeners. If it returns false, the key will be passed to any KeyListeners that have been registered with this component. As soon as one of these returns true, the process will stop, but if they all return false, the event will be passed upwards to this component's parent, and so on.
The default implementation of this method does nothing and returns false.
Reimplemented from Component.
| void ScrollBar::mouseWheelMove | ( | const MouseEvent & | e, |
| float | wheelIncrementX, | ||
| float | wheelIncrementY | ||
| ) | [virtual] |
Called when the mouse-wheel is moved.
This callback is sent to the component that the mouse is over when the wheel is moved.
If not overridden, the component will forward this message to its parent, so that parent components can collect mouse-wheel messages that happen to child components which aren't interested in them.
| e | details about the position and status of the mouse event |
| wheelIncrementX | the speed and direction of the horizontal scroll-wheel - a positive value means the wheel has been pushed to the right, negative means it was pushed to the left |
| wheelIncrementY | the speed and direction of the vertical scroll-wheel - a positive value means the wheel has been pushed upwards, negative means it was pushed downwards |
Reimplemented from Component.
| void ScrollBar::lookAndFeelChanged | ( | ) | [virtual] |
Called to let the component react to a change in the look-and-feel setting.
When the look-and-feel is changed for a component, this will be called in all its child components, recursively.
It can also be triggered manually by the sendLookAndFeelChange() method, in case an application uses a LookAndFeel class that might have changed internally.
Reimplemented from Component.
| void ScrollBar::handleAsyncUpdate | ( | ) | [virtual] |
Called back to do whatever your class needs to do.
This method is called by the message thread at the next convenient time after the triggerAsyncUpdate() method has been called.
Implements AsyncUpdater.
| void ScrollBar::mouseDown | ( | const MouseEvent & | e ) | [virtual] |
Called when a mouse button is pressed while it's over this component.
The MouseEvent object passed in contains lots of methods for finding out which button was pressed, as well as which modifier keys (e.g. shift, ctrl) were held down at the time.
Once a button is held down, the mouseDrag method will be called when the mouse moves, until the button is released.
| e | details about the position and status of the mouse event |
Reimplemented from Component.
| void ScrollBar::mouseDrag | ( | const MouseEvent & | e ) | [virtual] |
Called when the mouse is moved while a button is held down.
When a mouse button is pressed inside a component, that component receives mouseDrag callbacks each time the mouse moves, even if the mouse strays outside the component's bounds.
If you want to be able to drag things off the edge of a component and have the component scroll when you get to the edges, the beginDragAutoRepeat() method might be useful.
| e | details about the position and status of the mouse event |
Reimplemented from Component.
| void ScrollBar::mouseUp | ( | const MouseEvent & | e ) | [virtual] |
Called when a mouse button is released.
A mouseUp callback is sent to the component in which a button was pressed even if the mouse is actually over a different component when the button is released.
The MouseEvent object passed in contains lots of methods for finding out which buttons were down just before they were released.
| e | details about the position and status of the mouse event |
Reimplemented from Component.
| void ScrollBar::paint | ( | Graphics & | g ) | [virtual] |
Components can override this method to draw their content.
The paint() method gets called when a region of a component needs redrawing, either because the component's repaint() method has been called, or because something has happened on the screen that means a section of a window needs to be redrawn.
Any child components will draw themselves over whatever this method draws. If you need to paint over the top of your child components, you can also implement the paintOverChildren() method to do this.
If you want to cause a component to redraw itself, this is done asynchronously - calling the repaint() method marks a region of the component as "dirty", and the paint() method will automatically be called sometime later, by the message thread, to paint any bits that need refreshing. In Juce (and almost all modern UI frameworks), you never redraw something synchronously.
You should never need to call this method directly - to take a snapshot of the component you could use createComponentSnapshot() or paintEntireComponent().
| g | the graphics context that must be used to do the drawing operations. |
Reimplemented from Component.
| void ScrollBar::resized | ( | ) | [virtual] |
Called when this component's size has been changed.
A component can implement this method to do things such as laying out its child components when its width or height changes.
The method is called synchronously as a result of the setBounds or setSize methods, so repeatedly changing a components size will repeatedly call its resized method (unlike things like repainting, where multiple calls to repaint are coalesced together).
If the component is a top-level window on the desktop, its size could also be changed by operating-system factors beyond the application's control.
Reimplemented from Component.