Browse Source

Removed the Scrollbar's setButtonVisibility method, and instead added LookAndFeel::areScrollbarButtonsVisible()

tags/2021-05-28
jules 13 years ago
parent
commit
cd5893d6e8
8 changed files with 33 additions and 52 deletions
  1. +20
    -20
      modules/juce_gui_basics/layout/juce_ScrollBar.cpp
  2. +6
    -9
      modules/juce_gui_basics/layout/juce_ScrollBar.h
  3. +0
    -6
      modules/juce_gui_basics/layout/juce_Viewport.cpp
  4. +0
    -6
      modules/juce_gui_basics/layout/juce_Viewport.h
  5. +5
    -0
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp
  6. +2
    -0
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h
  7. +0
    -5
      modules/juce_gui_basics/widgets/juce_TextEditor.cpp
  8. +0
    -6
      modules/juce_gui_basics/widgets/juce_TextEditor.h

+ 20
- 20
modules/juce_gui_basics/layout/juce_ScrollBar.cpp View File

@@ -59,8 +59,7 @@ private:
//==============================================================================
ScrollBar::ScrollBar (const bool vertical_,
const bool buttonsAreVisible)
ScrollBar::ScrollBar (const bool vertical_)
: totalRange (0.0, 1.0),
visibleRange (0.0, 0.1),
singleStepSize (0.1),
@@ -75,8 +74,6 @@ ScrollBar::ScrollBar (const bool vertical_,
isDraggingThumb (false),
autohides (true)
{
setButtonVisibility (buttonsAreVisible);
setRepaintsOnMouseActivity (true);
setFocusContainer (true);
}
@@ -235,22 +232,6 @@ void ScrollBar::setOrientation (const bool shouldBeVertical)
}
}
void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
{
upButton = nullptr;
downButton = nullptr;
if (buttonsAreVisible)
{
addAndMakeVisible (upButton = new ScrollbarButton (vertical ? 0 : 3, *this));
addAndMakeVisible (downButton = new ScrollbarButton (vertical ? 2 : 1, *this));
setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
}
updateThumbPosition();
}
void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
{
autohides = shouldHideWhenFullRange;
@@ -296,12 +277,31 @@ void ScrollBar::paint (Graphics& g)
void ScrollBar::lookAndFeelChanged()
{
setComponentEffect (getLookAndFeel().getScrollbarEffect());
resized();
}
void ScrollBar::resized()
{
const int length = vertical ? getHeight() : getWidth();
const bool buttonsVisible = getLookAndFeel().areScrollbarButtonsVisible();
if (buttonsVisible)
{
if (upButton == nullptr)
{
addAndMakeVisible (upButton = new ScrollbarButton (vertical ? 0 : 3, *this));
addAndMakeVisible (downButton = new ScrollbarButton (vertical ? 2 : 1, *this));
setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
}
}
else
{
upButton = nullptr;
downButton = nullptr;
}
const int buttonSize = upButton != nullptr ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), length / 2)
: 0;


+ 6
- 9
modules/juce_gui_basics/layout/juce_ScrollBar.h View File

@@ -27,7 +27,7 @@
#define __JUCE_SCROLLBAR_JUCEHEADER__
#include "../buttons/juce_Button.h"
class Viewport;
//==============================================================================
/**
@@ -50,7 +50,7 @@
@see ScrollBar::Listener
*/
class JUCE_API ScrollBar : public Component,
public AsyncUpdater,
private AsyncUpdater,
private Timer
{
public:
@@ -60,8 +60,7 @@ public:
@param isVertical whether it should be a vertical or horizontal bar
@param buttonsAreVisible whether to show the up/down or left/right buttons
*/
ScrollBar (bool isVertical,
bool buttonsAreVisible = true);
ScrollBar (bool isVertical);
/** Destructor. */
~ScrollBar();
@@ -79,9 +78,6 @@ public:
*/
void setOrientation (bool shouldBeVertical);
/** Shows or hides the scrollbar's buttons. */
void setButtonVisibility (bool buttonsAreVisible);
/** Tells the scrollbar whether to make itself invisible when not needed.
The default behaviour is for a scrollbar to become invisible when the thumb
@@ -295,8 +291,6 @@ public:
/** @internal */
void lookAndFeelChanged();
/** @internal */
void handleAsyncUpdate();
/** @internal */
void mouseDown (const MouseEvent&);
/** @internal */
void mouseDrag (const MouseEvent&);
@@ -320,9 +314,12 @@ private:
ScopedPointer<ScrollbarButton> upButton, downButton;
ListenerList <Listener> listeners;
void handleAsyncUpdate();
void updateThumbPosition();
void timerCallback();
friend class Viewport;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ScrollBar);
};


+ 0
- 6
modules/juce_gui_basics/layout/juce_Viewport.cpp View File

@@ -328,12 +328,6 @@ int Viewport::getScrollBarThickness() const
: getLookAndFeel().getDefaultScrollbarWidth();
}
void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
{
verticalScrollBar.setButtonVisibility (buttonsVisible);
horizontalScrollBar.setButtonVisibility (buttonsVisible);
}
void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
{
const int newRangeStartInt = roundToInt (newRangeStart);


+ 0
- 6
modules/juce_gui_basics/layout/juce_Viewport.h View File

@@ -225,12 +225,6 @@ public:
*/
void setSingleStepSizes (int stepX, int stepY);
/** Shows or hides the buttons on any scrollbars that are used.
@see ScrollBar::setButtonVisibility
*/
void setScrollBarButtonVisibility (bool buttonsVisible);
/** Returns a pointer to the scrollbar component being used.
Handy if you need to customise the bar somehow.
*/


+ 5
- 0
modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp View File

@@ -713,6 +713,11 @@ void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour,
}
}
bool LookAndFeel::areScrollbarButtonsVisible()
{
return true;
}
void LookAndFeel::drawScrollbarButton (Graphics& g,
ScrollBar& scrollbar,
int width, int height,


+ 2
- 0
modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h View File

@@ -229,6 +229,8 @@ public:
int x, int y, int w, int h);
//==============================================================================
virtual bool areScrollbarButtonsVisible();
/** Draws one of the buttons on a scrollbar.
@param g the context to draw into


+ 0
- 5
modules/juce_gui_basics/widgets/juce_TextEditor.cpp View File

@@ -1200,11 +1200,6 @@ void TextEditor::setScrollBarThickness (const int newThicknessPixels)
viewport->setScrollBarThickness (newThicknessPixels);
}
void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
{
viewport->setScrollBarButtonVisibility (buttonsVisible);
}
//==============================================================================
void TextEditor::clear()
{


+ 0
- 6
modules/juce_gui_basics/widgets/juce_TextEditor.h View File

@@ -287,12 +287,6 @@ public:
*/
void setScrollBarThickness (int newThicknessPixels);
/** Shows or hides the buttons on any scrollbars that are used.
@see ScrollBar::setButtonVisibility
*/
void setScrollBarButtonVisibility (bool buttonsVisible);
//==============================================================================
/**
Receives callbacks from a TextEditor component when it changes.


Loading…
Cancel
Save