mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-13 00:04:19 +00:00
Added an option for Viewport subclasses to create custom scrollbars. Also modified Viewport::getVerticalScrollBar() and ListBox::getVerticalScrollBar() to return references instead of pointers
This commit is contained in:
parent
533fd23439
commit
a4f5663fce
9 changed files with 138 additions and 121 deletions
|
|
@ -23,15 +23,18 @@
|
|||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#include "../JuceLibraryCode/JuceHeader.h"
|
||||
#include "GraphEditorPanel.h"
|
||||
#include "InternalFilters.h"
|
||||
#include "MainHostWindow.h"
|
||||
|
||||
#include "FilterIOConfiguration.h"
|
||||
|
||||
|
||||
//==============================================================================
|
||||
class NumberedBoxes : public TableListBox, private TableListBoxModel, private Button::Listener
|
||||
class NumberedBoxes : public TableListBox,
|
||||
private TableListBoxModel,
|
||||
private Button::Listener
|
||||
{
|
||||
public:
|
||||
struct Listener
|
||||
|
|
@ -56,21 +59,19 @@ public:
|
|||
canAddColumn (canCurrentlyAddColumn),
|
||||
canRemoveColumn (canCurrentlyRemoveColumn)
|
||||
{
|
||||
TableHeaderComponent& tableHeader = getHeader();
|
||||
auto& tableHeader = getHeader();
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
tableHeader.addColumn (String (i + 1), i + 1, 40);
|
||||
|
||||
setHeaderHeight (0);
|
||||
setRowHeight (40);
|
||||
|
||||
if (ScrollBar* scrollbar = getHorizontalScrollBar())
|
||||
scrollbar->setAutoHide (false);
|
||||
getHorizontalScrollBar().setAutoHide (false);
|
||||
}
|
||||
|
||||
void setSelected (int columnId)
|
||||
{
|
||||
if (TextButton* button = dynamic_cast<TextButton*> (getCellComponent (columnId, 0)))
|
||||
if (auto* button = dynamic_cast<TextButton*> (getCellComponent (columnId, 0)))
|
||||
button->setToggleState (true, NotificationType::dontSendNotification);
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +81,7 @@ public:
|
|||
{
|
||||
canAddColumn = canCurrentlyAdd;
|
||||
|
||||
if (TextButton* button = dynamic_cast<TextButton*> (getCellComponent (plusButtonColumnId, 0)))
|
||||
if (auto* button = dynamic_cast<TextButton*> (getCellComponent (plusButtonColumnId, 0)))
|
||||
button->setEnabled (true);
|
||||
}
|
||||
}
|
||||
|
|
@ -91,7 +92,7 @@ public:
|
|||
{
|
||||
canRemoveColumn = canCurrentlyRemove;
|
||||
|
||||
if (TextButton* button = dynamic_cast<TextButton*> (getCellComponent (minusButtonColumnId, 0)))
|
||||
if (auto* button = dynamic_cast<TextButton*> (getCellComponent (minusButtonColumnId, 0)))
|
||||
button->setEnabled (true);
|
||||
}
|
||||
}
|
||||
|
|
@ -105,9 +106,10 @@ private:
|
|||
Component* refreshComponentForCell (int, int columnId, bool,
|
||||
Component* existingComponentToUpdate) override
|
||||
{
|
||||
TextButton* textButton = dynamic_cast<TextButton*> (existingComponentToUpdate);
|
||||
auto* textButton = dynamic_cast<TextButton*> (existingComponentToUpdate);
|
||||
|
||||
if (textButton == nullptr)
|
||||
textButton = new TextButton ("");
|
||||
textButton = new TextButton();
|
||||
|
||||
textButton->setButtonText (getButtonName (columnId));
|
||||
textButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight |
|
||||
|
|
@ -124,7 +126,7 @@ private:
|
|||
textButton->setRadioGroupId (1, NotificationType::dontSendNotification);
|
||||
textButton->setClickingTogglesState (true);
|
||||
|
||||
Colour busColour = Colours::green.withRotatedHue (static_cast<float> (columnId) / 5.0f);
|
||||
auto busColour = Colours::green.withRotatedHue (static_cast<float> (columnId) / 5.0f);
|
||||
textButton->setColour (TextButton::buttonColourId, busColour);
|
||||
textButton->setColour (TextButton::buttonOnColourId, busColour.withMultipliedBrightness (2.0f));
|
||||
}
|
||||
|
|
@ -145,17 +147,18 @@ private:
|
|||
|
||||
void buttonClicked (Button* btn) override
|
||||
{
|
||||
const String& text = btn->getButtonText();
|
||||
auto text = btn->getButtonText();
|
||||
|
||||
if (text == "+") listener.addColumn();
|
||||
else if (text == "-") listener.removeColumn();
|
||||
if (text == "+") listener.addColumn();
|
||||
if (text == "-") listener.removeColumn();
|
||||
}
|
||||
|
||||
void buttonStateChanged (Button* btn) override
|
||||
{
|
||||
const String& text = btn->getButtonText();
|
||||
auto text = btn->getButtonText();
|
||||
|
||||
if (text == "+" || text == "-") return;
|
||||
if (text == "+" || text == "-")
|
||||
return;
|
||||
|
||||
if (btn->getToggleState())
|
||||
listener.columnSelected (text.getIntValue());
|
||||
|
|
@ -167,8 +170,10 @@ private:
|
|||
};
|
||||
|
||||
//==============================================================================
|
||||
class FilterIOConfigurationWindow::InputOutputConfig
|
||||
: public Component, private ComboBox::Listener, private Button::Listener, private NumberedBoxes::Listener
|
||||
class FilterIOConfigurationWindow::InputOutputConfig : public Component,
|
||||
private ComboBox::Listener,
|
||||
private Button::Listener,
|
||||
private NumberedBoxes::Listener
|
||||
{
|
||||
public:
|
||||
InputOutputConfig (FilterIOConfigurationWindow& parent, bool direction)
|
||||
|
|
@ -208,7 +213,7 @@ public:
|
|||
|
||||
void resized() override
|
||||
{
|
||||
Rectangle<int> r = getLocalBounds().reduced (10);
|
||||
auto r = getLocalBounds().reduced (10);
|
||||
|
||||
ioTitle.setBounds (r.removeFromTop (14));
|
||||
r.reduce (10, 0);
|
||||
|
|
@ -217,7 +222,7 @@ public:
|
|||
ioBuses.setBounds (r.removeFromTop (60));
|
||||
|
||||
{
|
||||
Rectangle<int> label = r.removeFromTop (24);
|
||||
auto label = r.removeFromTop (24);
|
||||
|
||||
nameLabel.setBounds (label.removeFromLeft (100));
|
||||
enabledToggle.setBounds (label.removeFromRight (80));
|
||||
|
|
@ -225,7 +230,7 @@ public:
|
|||
}
|
||||
|
||||
{
|
||||
Rectangle<int> label = r.removeFromTop (24);
|
||||
auto label = r.removeFromTop (24);
|
||||
|
||||
layoutLabel.setBounds (label.removeFromLeft (100));
|
||||
layouts.setBounds (label);
|
||||
|
|
@ -235,12 +240,13 @@ public:
|
|||
private:
|
||||
void updateBusButtons()
|
||||
{
|
||||
if (AudioProcessor* filter = owner.getAudioProcessor())
|
||||
if (auto* filter = owner.getAudioProcessor())
|
||||
{
|
||||
TableHeaderComponent& header = ioBuses.getHeader();
|
||||
auto& header = ioBuses.getHeader();
|
||||
header.removeAllColumns();
|
||||
|
||||
const int n = filter->getBusCount (isInput);
|
||||
|
||||
for (int i = 0; i < n; ++i)
|
||||
header.addColumn ("", i + 1, 40);
|
||||
|
||||
|
|
@ -256,14 +262,13 @@ private:
|
|||
|
||||
void updateBusLayout()
|
||||
{
|
||||
if (AudioProcessor* filter = owner.getAudioProcessor())
|
||||
if (auto* filter = owner.getAudioProcessor())
|
||||
{
|
||||
if (AudioProcessor::Bus* bus = filter->getBus (isInput, currentBus))
|
||||
if (auto* bus = filter->getBus (isInput, currentBus))
|
||||
{
|
||||
name.setText (bus->getName(), NotificationType::dontSendNotification);
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 1; i < AudioChannelSet::maxChannelsOfNamedLayout; ++i)
|
||||
if ((layouts.indexOfItemId(i) == -1) != bus->supportedLayoutWithChannels (i).isDisabled())
|
||||
break;
|
||||
|
|
@ -275,7 +280,8 @@ private:
|
|||
|
||||
for (i = 1; i < AudioChannelSet::maxChannelsOfNamedLayout; ++i)
|
||||
{
|
||||
AudioChannelSet set = bus->supportedLayoutWithChannels (i);
|
||||
auto set = bus->supportedLayoutWithChannels (i);
|
||||
|
||||
if (! set.isDisabled())
|
||||
layouts.addItem (set.getDescription(), i);
|
||||
}
|
||||
|
|
@ -298,18 +304,18 @@ private:
|
|||
{
|
||||
if (combo == &layouts)
|
||||
{
|
||||
if (AudioProcessor* filter = owner.getAudioProcessor())
|
||||
if (auto* processor = owner.getAudioProcessor())
|
||||
{
|
||||
if (AudioProcessor::Bus* bus = filter->getBus (isInput, currentBus))
|
||||
if (auto* bus = processor->getBus (isInput, currentBus))
|
||||
{
|
||||
const int selectedNumChannels = layouts.getSelectedId();
|
||||
auto selectedNumChannels = layouts.getSelectedId();
|
||||
|
||||
if (selectedNumChannels != bus->getLastEnabledLayout().size())
|
||||
{
|
||||
if (isPositiveAndBelow (selectedNumChannels, (int) AudioChannelSet::maxChannelsOfNamedLayout)
|
||||
&& bus->setCurrentLayoutWithoutEnabling (bus->supportedLayoutWithChannels (selectedNumChannels)))
|
||||
&& bus->setCurrentLayoutWithoutEnabling (bus->supportedLayoutWithChannels (selectedNumChannels)))
|
||||
{
|
||||
if (InputOutputConfig* config = owner.getConfig (! isInput))
|
||||
if (auto* config = owner.getConfig (! isInput))
|
||||
config->updateBusLayout();
|
||||
|
||||
owner.update();
|
||||
|
|
@ -326,9 +332,9 @@ private:
|
|||
{
|
||||
if (btn == &enabledToggle && enabledToggle.isEnabled())
|
||||
{
|
||||
if (AudioProcessor* filter = owner.getAudioProcessor())
|
||||
if (auto* processor = owner.getAudioProcessor())
|
||||
{
|
||||
if (AudioProcessor::Bus* bus = filter->getBus (isInput, currentBus))
|
||||
if (auto* bus = processor->getBus (isInput, currentBus))
|
||||
{
|
||||
if (bus->isEnabled() != enabledToggle.getToggleState())
|
||||
{
|
||||
|
|
@ -362,16 +368,16 @@ private:
|
|||
//==============================================================================
|
||||
void addColumn() override
|
||||
{
|
||||
if (AudioProcessor* filter = owner.getAudioProcessor())
|
||||
if (auto* processor = owner.getAudioProcessor())
|
||||
{
|
||||
if (filter->canAddBus (isInput))
|
||||
if (processor->canAddBus (isInput))
|
||||
{
|
||||
if (filter->addBus (isInput))
|
||||
if (processor->addBus (isInput))
|
||||
{
|
||||
updateBusButtons();
|
||||
updateBusLayout();
|
||||
|
||||
if (InputOutputConfig* config = owner.getConfig (! isInput))
|
||||
if (auto* config = owner.getConfig (! isInput))
|
||||
{
|
||||
config->updateBusButtons();
|
||||
config->updateBusLayout();
|
||||
|
|
@ -385,18 +391,18 @@ private:
|
|||
|
||||
void removeColumn() override
|
||||
{
|
||||
if (AudioProcessor* filter = owner.getAudioProcessor())
|
||||
if (auto* processor = owner.getAudioProcessor())
|
||||
{
|
||||
if (filter->getBusCount (isInput) > 1 && filter->canRemoveBus (isInput))
|
||||
if (processor->getBusCount (isInput) > 1 && processor->canRemoveBus (isInput))
|
||||
{
|
||||
if (filter->removeBus (isInput))
|
||||
if (processor->removeBus (isInput))
|
||||
{
|
||||
currentBus = jmin (filter->getBusCount (isInput) - 1, currentBus);
|
||||
currentBus = jmin (processor->getBusCount (isInput) - 1, currentBus);
|
||||
|
||||
updateBusButtons();
|
||||
updateBusLayout();
|
||||
|
||||
if (InputOutputConfig* config = owner.getConfig (! isInput))
|
||||
if (auto* config = owner.getConfig (! isInput))
|
||||
{
|
||||
config->updateBusButtons();
|
||||
config->updateBusLayout();
|
||||
|
|
@ -411,6 +417,7 @@ private:
|
|||
void columnSelected (int columnId) override
|
||||
{
|
||||
const int newBus = columnId - 1;
|
||||
|
||||
if (currentBus != newBus)
|
||||
{
|
||||
currentBus = newBus;
|
||||
|
|
@ -460,9 +467,9 @@ FilterIOConfigurationWindow::FilterIOConfigurationWindow (AudioProcessor* const
|
|||
|
||||
FilterIOConfigurationWindow::~FilterIOConfigurationWindow()
|
||||
{
|
||||
if (AudioProcessorGraph* graph = getGraph())
|
||||
if (auto* graph = getGraph())
|
||||
{
|
||||
if (AudioProcessor* p = getAudioProcessor())
|
||||
if (auto* p = getAudioProcessor())
|
||||
{
|
||||
ScopedLock renderLock (graph->getCallbackLock());
|
||||
|
||||
|
|
@ -485,7 +492,7 @@ void FilterIOConfigurationWindow::paint (Graphics& g)
|
|||
|
||||
void FilterIOConfigurationWindow::resized()
|
||||
{
|
||||
Rectangle<int> r = getLocalBounds().reduced (10);
|
||||
auto r = getLocalBounds().reduced (10);
|
||||
|
||||
title.setBounds (r.removeFromTop (14));
|
||||
r.reduce (10, 0);
|
||||
|
|
@ -499,25 +506,25 @@ void FilterIOConfigurationWindow::resized()
|
|||
|
||||
void FilterIOConfigurationWindow::update()
|
||||
{
|
||||
const int32 nodeId = getNodeId();
|
||||
auto nodeId = getNodeId();
|
||||
|
||||
if (AudioProcessorGraph* graph = getGraph())
|
||||
if (auto* graph = getGraph())
|
||||
if (nodeId != -1)
|
||||
graph->disconnectNode (static_cast<uint32> (nodeId));
|
||||
|
||||
if (GraphDocumentComponent* graphEditor = getGraphEditor())
|
||||
if (GraphEditorPanel* panel = graphEditor->graphPanel)
|
||||
if (auto* graphEditor = getGraphEditor())
|
||||
if (auto* panel = graphEditor->graphPanel)
|
||||
panel->updateComponents();
|
||||
}
|
||||
|
||||
int32 FilterIOConfigurationWindow::getNodeId() const
|
||||
{
|
||||
if (AudioProcessorGraph* graph = getGraph())
|
||||
if (auto* graph = getGraph())
|
||||
{
|
||||
const int n = graph->getNumNodes();
|
||||
|
||||
for (int i = 0; i < n; ++i)
|
||||
if (AudioProcessorGraph::Node* node = graph->getNode (i))
|
||||
if (auto* node = graph->getNode (i))
|
||||
if (node->getProcessor() == getAudioProcessor())
|
||||
return static_cast<int32> (node->nodeId);
|
||||
}
|
||||
|
|
@ -530,7 +537,7 @@ MainHostWindow* FilterIOConfigurationWindow::getMainWindow() const
|
|||
Component* comp;
|
||||
|
||||
for (int idx = 0; (comp = Desktop::getInstance().getComponent(idx)) != nullptr; ++idx)
|
||||
if (MainHostWindow* mainWindow = dynamic_cast<MainHostWindow*> (comp))
|
||||
if (auto* mainWindow = dynamic_cast<MainHostWindow*> (comp))
|
||||
return mainWindow;
|
||||
|
||||
return nullptr;
|
||||
|
|
@ -538,20 +545,18 @@ MainHostWindow* FilterIOConfigurationWindow::getMainWindow() const
|
|||
|
||||
GraphDocumentComponent* FilterIOConfigurationWindow::getGraphEditor() const
|
||||
{
|
||||
if (MainHostWindow* mainWindow = getMainWindow())
|
||||
{
|
||||
if (GraphDocumentComponent* graphEditor = mainWindow->getGraphEditor())
|
||||
if (auto* mainWindow = getMainWindow())
|
||||
if (auto* graphEditor = mainWindow->getGraphEditor())
|
||||
return graphEditor;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AudioProcessorGraph* FilterIOConfigurationWindow::getGraph() const
|
||||
{
|
||||
if (GraphDocumentComponent* graphEditor = getGraphEditor())
|
||||
if (FilterGraph* filterGraph = graphEditor->graph)
|
||||
return &filterGraph->getGraph();
|
||||
if (auto* graphEditor = getGraphEditor())
|
||||
if (auto* graph = graphEditor->graph.get())
|
||||
return &graph->getGraph();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ void FileListComponent::deselectAllFiles()
|
|||
|
||||
void FileListComponent::scrollToTop()
|
||||
{
|
||||
getVerticalScrollBar()->setCurrentRangeStart (0);
|
||||
getVerticalScrollBar().setCurrentRangeStart (0);
|
||||
}
|
||||
|
||||
void FileListComponent::setSelectedFile (const File& f)
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public:
|
|||
{
|
||||
jassert (parentContentsList != nullptr);
|
||||
|
||||
DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
|
||||
auto l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
|
||||
|
||||
l->setDirectory (file,
|
||||
parentContentsList->isFindingDirectories(),
|
||||
|
|
@ -299,7 +299,7 @@ void FileTreeComponent::deselectAllFiles()
|
|||
|
||||
void FileTreeComponent::scrollToTop()
|
||||
{
|
||||
getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
|
||||
getViewport()->getVerticalScrollBar().setCurrentRangeStart (0);
|
||||
}
|
||||
|
||||
void FileTreeComponent::setDragAndDropDescription (const String& description)
|
||||
|
|
|
|||
|
|
@ -35,11 +35,11 @@ Viewport::Viewport (const String& name) : Component (name)
|
|||
|
||||
scrollBarThickness = getLookAndFeel().getDefaultScrollbarWidth();
|
||||
|
||||
addChildComponent (verticalScrollBar);
|
||||
addChildComponent (horizontalScrollBar);
|
||||
addChildComponent (verticalScrollBar = createScrollBarComponent (true));
|
||||
addChildComponent (horizontalScrollBar = createScrollBarComponent (false));
|
||||
|
||||
verticalScrollBar.addListener (this);
|
||||
horizontalScrollBar.addListener (this);
|
||||
getVerticalScrollBar().addListener (this);
|
||||
getHorizontalScrollBar().addListener (this);
|
||||
|
||||
setInterceptsMouseClicks (false, true);
|
||||
setWantsKeyboardFocus (true);
|
||||
|
|
@ -140,7 +140,7 @@ bool Viewport::autoScroll (const int mouseX, const int mouseY, const int activeB
|
|||
{
|
||||
int dx = 0, dy = 0;
|
||||
|
||||
if (horizontalScrollBar.isVisible() || canScrollHorizontally())
|
||||
if (getHorizontalScrollBar().isVisible() || canScrollHorizontally())
|
||||
{
|
||||
if (mouseX < activeBorderThickness)
|
||||
dx = activeBorderThickness - mouseX;
|
||||
|
|
@ -153,7 +153,7 @@ bool Viewport::autoScroll (const int mouseX, const int mouseY, const int activeB
|
|||
dx = jmin (dx, maximumSpeed, -contentComp->getX());
|
||||
}
|
||||
|
||||
if (verticalScrollBar.isVisible() || canScrollVertically())
|
||||
if (getVerticalScrollBar().isVisible() || canScrollVertically())
|
||||
{
|
||||
if (mouseY < activeBorderThickness)
|
||||
dy = activeBorderThickness - mouseY;
|
||||
|
|
@ -223,7 +223,7 @@ struct Viewport::DragToScrollListener : private MouseListener,
|
|||
{
|
||||
if (numTouches == 1 && ! isViewportDragBlocked)
|
||||
{
|
||||
Point<float> totalOffset = e.getOffsetFromDragStart().toFloat();
|
||||
auto totalOffset = e.getOffsetFromDragStart().toFloat();
|
||||
|
||||
if (! isDragging && totalOffset.getDistanceFromOrigin() > 8.0f)
|
||||
{
|
||||
|
|
@ -326,8 +326,8 @@ void Viewport::updateVisibleArea()
|
|||
|
||||
for (int i = 3; --i >= 0;)
|
||||
{
|
||||
hBarVisible = canShowHBar && ! horizontalScrollBar.autoHides();
|
||||
vBarVisible = canShowVBar && ! verticalScrollBar.autoHides();
|
||||
hBarVisible = canShowHBar && ! getHorizontalScrollBar().autoHides();
|
||||
vBarVisible = canShowVBar && ! getVerticalScrollBar().autoHides();
|
||||
contentArea = getLocalBounds();
|
||||
|
||||
if (contentComp != nullptr && ! contentArea.contains (contentComp->getBounds()))
|
||||
|
|
@ -371,27 +371,30 @@ void Viewport::updateVisibleArea()
|
|||
|
||||
auto visibleOrigin = -contentBounds.getPosition();
|
||||
|
||||
horizontalScrollBar.setBounds (0, contentArea.getHeight(), contentArea.getWidth(), scrollbarWidth);
|
||||
horizontalScrollBar.setRangeLimits (0.0, contentBounds.getWidth());
|
||||
horizontalScrollBar.setCurrentRange (visibleOrigin.x, contentArea.getWidth());
|
||||
horizontalScrollBar.setSingleStepSize (singleStepX);
|
||||
horizontalScrollBar.cancelPendingUpdate();
|
||||
auto& hbar = getHorizontalScrollBar();
|
||||
auto& vbar = getVerticalScrollBar();
|
||||
|
||||
hbar.setBounds (0, contentArea.getHeight(), contentArea.getWidth(), scrollbarWidth);
|
||||
hbar.setRangeLimits (0.0, contentBounds.getWidth());
|
||||
hbar.setCurrentRange (visibleOrigin.x, contentArea.getWidth());
|
||||
hbar.setSingleStepSize (singleStepX);
|
||||
hbar.cancelPendingUpdate();
|
||||
|
||||
if (canShowHBar && ! hBarVisible)
|
||||
visibleOrigin.setX (0);
|
||||
|
||||
verticalScrollBar.setBounds (contentArea.getWidth(), 0, scrollbarWidth, contentArea.getHeight());
|
||||
verticalScrollBar.setRangeLimits (0.0, contentBounds.getHeight());
|
||||
verticalScrollBar.setCurrentRange (visibleOrigin.y, contentArea.getHeight());
|
||||
verticalScrollBar.setSingleStepSize (singleStepY);
|
||||
verticalScrollBar.cancelPendingUpdate();
|
||||
vbar.setBounds (contentArea.getWidth(), 0, scrollbarWidth, contentArea.getHeight());
|
||||
vbar.setRangeLimits (0.0, contentBounds.getHeight());
|
||||
vbar.setCurrentRange (visibleOrigin.y, contentArea.getHeight());
|
||||
vbar.setSingleStepSize (singleStepY);
|
||||
vbar.cancelPendingUpdate();
|
||||
|
||||
if (canShowVBar && ! vBarVisible)
|
||||
visibleOrigin.setY (0);
|
||||
|
||||
// Force the visibility *after* setting the ranges to avoid flicker caused by edge conditions in the numbers.
|
||||
horizontalScrollBar.setVisible (hBarVisible);
|
||||
verticalScrollBar.setVisible (vBarVisible);
|
||||
hbar.setVisible (hBarVisible);
|
||||
vbar.setVisible (vBarVisible);
|
||||
|
||||
if (contentComp != nullptr)
|
||||
{
|
||||
|
|
@ -414,8 +417,8 @@ void Viewport::updateVisibleArea()
|
|||
visibleAreaChanged (visibleArea);
|
||||
}
|
||||
|
||||
horizontalScrollBar.handleUpdateNowIfNeeded();
|
||||
verticalScrollBar.handleUpdateNowIfNeeded();
|
||||
hbar.handleUpdateNowIfNeeded();
|
||||
vbar.handleUpdateNowIfNeeded();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -480,11 +483,11 @@ void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRange
|
|||
{
|
||||
const int newRangeStartInt = roundToInt (newRangeStart);
|
||||
|
||||
if (scrollBarThatHasMoved == &horizontalScrollBar)
|
||||
if (scrollBarThatHasMoved == horizontalScrollBar)
|
||||
{
|
||||
setViewPosition (newRangeStartInt, getViewPositionY());
|
||||
}
|
||||
else if (scrollBarThatHasMoved == &verticalScrollBar)
|
||||
else if (scrollBarThatHasMoved == verticalScrollBar)
|
||||
{
|
||||
setViewPosition (getViewPositionX(), newRangeStartInt);
|
||||
}
|
||||
|
|
@ -511,8 +514,8 @@ bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, const MouseWheelD
|
|||
{
|
||||
if (! (e.mods.isAltDown() || e.mods.isCtrlDown() || e.mods.isCommandDown()))
|
||||
{
|
||||
const bool canScrollVert = (allowScrollingWithoutScrollbarV || verticalScrollBar.isVisible());
|
||||
const bool canScrollHorz = (allowScrollingWithoutScrollbarH || horizontalScrollBar.isVisible());
|
||||
const bool canScrollVert = (allowScrollingWithoutScrollbarV || getVerticalScrollBar().isVisible());
|
||||
const bool canScrollHorz = (allowScrollingWithoutScrollbarH || getHorizontalScrollBar().isVisible());
|
||||
|
||||
if (canScrollHorz || canScrollVert)
|
||||
{
|
||||
|
|
@ -566,13 +569,13 @@ bool Viewport::keyPressed (const KeyPress& key)
|
|||
{
|
||||
const bool isUpDownKey = isUpDownKeyPress (key);
|
||||
|
||||
if (verticalScrollBar.isVisible() && isUpDownKey)
|
||||
return verticalScrollBar.keyPressed (key);
|
||||
if (getVerticalScrollBar().isVisible() && isUpDownKey)
|
||||
return getVerticalScrollBar().keyPressed (key);
|
||||
|
||||
const bool isLeftRightKey = isLeftRightKeyPress (key);
|
||||
|
||||
if (horizontalScrollBar.isVisible() && (isUpDownKey || isLeftRightKey))
|
||||
return horizontalScrollBar.keyPressed (key);
|
||||
if (getHorizontalScrollBar().isVisible() && (isUpDownKey || isLeftRightKey))
|
||||
return getHorizontalScrollBar().keyPressed (key);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -582,4 +585,9 @@ bool Viewport::respondsToKey (const KeyPress& key)
|
|||
return isUpDownKeyPress (key) || isLeftRightKeyPress (key);
|
||||
}
|
||||
|
||||
ScrollBar* Viewport::createScrollBarComponent (bool isVertical)
|
||||
{
|
||||
return new ScrollBar (isVertical);
|
||||
}
|
||||
|
||||
} // namespace juce
|
||||
|
|
|
|||
|
|
@ -231,12 +231,12 @@ public:
|
|||
/** Returns a pointer to the scrollbar component being used.
|
||||
Handy if you need to customise the bar somehow.
|
||||
*/
|
||||
ScrollBar* getVerticalScrollBar() noexcept { return &verticalScrollBar; }
|
||||
ScrollBar& getVerticalScrollBar() noexcept { return *verticalScrollBar; }
|
||||
|
||||
/** Returns a pointer to the scrollbar component being used.
|
||||
Handy if you need to customise the bar somehow.
|
||||
*/
|
||||
ScrollBar* getHorizontalScrollBar() noexcept { return &horizontalScrollBar; }
|
||||
ScrollBar& getHorizontalScrollBar() noexcept { return *horizontalScrollBar; }
|
||||
|
||||
/** True if there's any off-screen content that could be scrolled vertically,
|
||||
or false if everything is currently visible.
|
||||
|
|
@ -277,9 +277,16 @@ public:
|
|||
/** @internal */
|
||||
static bool respondsToKey (const KeyPress&);
|
||||
|
||||
protected:
|
||||
//==============================================================================
|
||||
/** Creates the Scrollbar components that will be used for that Viewport.
|
||||
Subclasses can override this if they need to customise the scroolbars in some way.
|
||||
*/
|
||||
virtual ScrollBar* createScrollBarComponent (bool isVertical);
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
ScrollBar verticalScrollBar { true }, horizontalScrollBar { false };
|
||||
ScopedPointer<ScrollBar> verticalScrollBar, horizontalScrollBar;
|
||||
Component contentHolder;
|
||||
WeakReference<Component> contentComp;
|
||||
Rectangle<int> lastVisibleArea;
|
||||
|
|
|
|||
|
|
@ -791,16 +791,16 @@ void ListBox::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& whee
|
|||
{
|
||||
bool eventWasUsed = false;
|
||||
|
||||
if (wheel.deltaX != 0.0f && viewport->getHorizontalScrollBar()->isVisible())
|
||||
if (wheel.deltaX != 0.0f && getHorizontalScrollBar().isVisible())
|
||||
{
|
||||
eventWasUsed = true;
|
||||
viewport->getHorizontalScrollBar()->mouseWheelMove (e, wheel);
|
||||
getHorizontalScrollBar().mouseWheelMove (e, wheel);
|
||||
}
|
||||
|
||||
if (wheel.deltaY != 0.0f && viewport->getVerticalScrollBar()->isVisible())
|
||||
if (wheel.deltaY != 0.0f && getVerticalScrollBar().isVisible())
|
||||
{
|
||||
eventWasUsed = true;
|
||||
viewport->getVerticalScrollBar()->mouseWheelMove (e, wheel);
|
||||
getVerticalScrollBar().mouseWheelMove (e, wheel);
|
||||
}
|
||||
|
||||
if (! eventWasUsed)
|
||||
|
|
@ -834,8 +834,8 @@ void ListBox::setMinimumContentWidth (const int newMinimumWidth)
|
|||
|
||||
int ListBox::getVisibleContentWidth() const noexcept { return viewport->getMaximumVisibleWidth(); }
|
||||
|
||||
ScrollBar* ListBox::getVerticalScrollBar() const noexcept { return viewport->getVerticalScrollBar(); }
|
||||
ScrollBar* ListBox::getHorizontalScrollBar() const noexcept { return viewport->getHorizontalScrollBar(); }
|
||||
ScrollBar& ListBox::getVerticalScrollBar() const noexcept { return viewport->getVerticalScrollBar(); }
|
||||
ScrollBar& ListBox::getHorizontalScrollBar() const noexcept { return viewport->getHorizontalScrollBar(); }
|
||||
|
||||
void ListBox::colourChanged()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -379,11 +379,11 @@ public:
|
|||
/** Scrolls if necessary to make sure that a particular row is visible. */
|
||||
void scrollToEnsureRowIsOnscreen (int row);
|
||||
|
||||
/** Returns a pointer to the vertical scrollbar. */
|
||||
ScrollBar* getVerticalScrollBar() const noexcept;
|
||||
/** Returns a reference to the vertical scrollbar. */
|
||||
ScrollBar& getVerticalScrollBar() const noexcept;
|
||||
|
||||
/** Returns a pointer to the horizontal scrollbar. */
|
||||
ScrollBar* getHorizontalScrollBar() const noexcept;
|
||||
/** Returns a reference to the horizontal scrollbar. */
|
||||
ScrollBar& getHorizontalScrollBar() const noexcept;
|
||||
|
||||
/** Finds the row index that contains a given x,y position.
|
||||
The position is relative to the ListBox's top-left.
|
||||
|
|
|
|||
|
|
@ -357,20 +357,18 @@ Component* TableListBox::getCellComponent (int columnId, int rowNumber) const
|
|||
|
||||
void TableListBox::scrollToEnsureColumnIsOnscreen (int columnId)
|
||||
{
|
||||
if (auto* scrollbar = getHorizontalScrollBar())
|
||||
{
|
||||
auto pos = header->getColumnPosition (header->getIndexOfColumnId (columnId, true));
|
||||
auto& scrollbar = getHorizontalScrollBar();
|
||||
auto pos = header->getColumnPosition (header->getIndexOfColumnId (columnId, true));
|
||||
|
||||
auto x = scrollbar->getCurrentRangeStart();
|
||||
auto w = scrollbar->getCurrentRangeSize();
|
||||
auto x = scrollbar.getCurrentRangeStart();
|
||||
auto w = scrollbar.getCurrentRangeSize();
|
||||
|
||||
if (pos.getX() < x)
|
||||
x = pos.getX();
|
||||
else if (pos.getRight() > x + w)
|
||||
x += jmax (0.0, pos.getRight() - (x + w));
|
||||
if (pos.getX() < x)
|
||||
x = pos.getX();
|
||||
else if (pos.getRight() > x + w)
|
||||
x += jmax (0.0, pos.getRight() - (x + w));
|
||||
|
||||
scrollbar->setCurrentRangeStart (x);
|
||||
}
|
||||
scrollbar.setCurrentRangeStart (x);
|
||||
}
|
||||
|
||||
int TableListBox::getNumRows()
|
||||
|
|
|
|||
|
|
@ -1869,8 +1869,7 @@ bool TextEditor::pageDown (bool selecting)
|
|||
|
||||
void TextEditor::scrollByLines (int deltaLines)
|
||||
{
|
||||
if (auto* scrollbar = viewport->getVerticalScrollBar())
|
||||
scrollbar->moveScrollbarInSteps (deltaLines);
|
||||
viewport->getVerticalScrollBar().moveScrollbarInSteps (deltaLines);
|
||||
}
|
||||
|
||||
bool TextEditor::scrollDown()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue