Browse Source

Fixed an issue where JUCE's ScrollBars could not be hidden

tags/2021-05-28
hogliux 7 years ago
parent
commit
be9c776c3c
2 changed files with 23 additions and 3 deletions
  1. +19
    -2
      modules/juce_gui_basics/layout/juce_ScrollBar.cpp
  2. +4
    -1
      modules/juce_gui_basics/layout/juce_ScrollBar.h

+ 19
- 2
modules/juce_gui_basics/layout/juce_ScrollBar.cpp View File

@@ -195,8 +195,7 @@ void ScrollBar::updateThumbPosition()
newThumbStart += roundToInt (((visibleRange.getStart() - totalRange.getStart()) * (thumbAreaSize - newThumbSize)) newThumbStart += roundToInt (((visibleRange.getStart() - totalRange.getStart()) * (thumbAreaSize - newThumbSize))
/ (totalRange.getLength() - visibleRange.getLength())); / (totalRange.getLength() - visibleRange.getLength()));
setVisible ((! autohides) || (totalRange.getLength() > visibleRange.getLength()
&& visibleRange.getLength() > 0.0));
Component::setVisible (getVisibility());
if (thumbStart != newThumbStart || thumbSize != newThumbSize) if (thumbStart != newThumbStart || thumbSize != newThumbSize)
{ {
@@ -422,4 +421,22 @@ bool ScrollBar::keyPressed (const KeyPress& key)
return false; return false;
} }
void ScrollBar::setVisible (bool shouldBeVisible)
{
if (userVisibilityFlag != shouldBeVisible)
{
userVisibilityFlag = shouldBeVisible;
Component::setVisible (getVisibility());
}
}
bool ScrollBar::getVisibility() const noexcept
{
if (! userVisibilityFlag)
return false;
return (! autohides) || (totalRange.getLength() > visibleRange.getLength()
&& visibleRange.getLength() > 0.0);
}
} // namespace juce } // namespace juce

+ 4
- 1
modules/juce_gui_basics/layout/juce_ScrollBar.h View File

@@ -406,6 +406,8 @@ public:
void resized() override; void resized() override;
/** @internal */ /** @internal */
void parentHierarchyChanged() override; void parentHierarchyChanged() override;
/** @internal */
void setVisible (bool) override;
private: private:
//============================================================================== //==============================================================================
@@ -414,7 +416,7 @@ private:
int thumbAreaStart = 0, thumbAreaSize = 0, thumbStart = 0, thumbSize = 0; int thumbAreaStart = 0, thumbAreaSize = 0, thumbStart = 0, thumbSize = 0;
int dragStartMousePos = 0, lastMousePos = 0; int dragStartMousePos = 0, lastMousePos = 0;
int initialDelayInMillisecs = 100, repeatDelayInMillisecs = 50, minimumDelayInMillisecs = 10; int initialDelayInMillisecs = 100, repeatDelayInMillisecs = 50, minimumDelayInMillisecs = 10;
bool vertical, isDraggingThumb = false, autohides = true;
bool vertical, isDraggingThumb = false, autohides = true, userVisibilityFlag = false;
class ScrollbarButton; class ScrollbarButton;
friend struct ContainerDeletePolicy<ScrollbarButton>; friend struct ContainerDeletePolicy<ScrollbarButton>;
ScopedPointer<ScrollbarButton> upButton, downButton; ScopedPointer<ScrollbarButton> upButton, downButton;
@@ -423,6 +425,7 @@ private:
void handleAsyncUpdate() override; void handleAsyncUpdate() override;
void updateThumbPosition(); void updateThumbPosition();
void timerCallback() override; void timerCallback() override;
bool getVisibility() const noexcept;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ScrollBar) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ScrollBar)
}; };


Loading…
Cancel
Save