JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_Viewport.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29using ViewportDragPosition = AnimatedPosition<AnimatedPositionBehaviours::ContinuousWithMomentum>;
30
32 private ViewportDragPosition::Listener
33{
34 DragToScrollListener (Viewport& v) : viewport (v)
35 {
36 viewport.contentHolder.addMouseListener (this, true);
37 offsetX.addListener (this);
38 offsetY.addListener (this);
39 offsetX.behaviour.setMinimumVelocity (60);
40 offsetY.behaviour.setMinimumVelocity (60);
41 }
42
43 ~DragToScrollListener() override
44 {
45 viewport.contentHolder.removeMouseListener (this);
47 }
48
49 void stopOngoingAnimation()
50 {
51 offsetX.setPosition (offsetX.getPosition());
52 offsetY.setPosition (offsetY.getPosition());
53 }
54
55 void positionChanged (ViewportDragPosition&, double) override
56 {
57 viewport.setViewPosition (originalViewPos - Point<int> ((int) offsetX.getPosition(),
58 (int) offsetY.getPosition()));
59 }
60
61 void mouseDown (const MouseEvent& e) override
62 {
63 if (! isGlobalMouseListener && detail::ViewportHelpers::wouldScrollOnEvent (&viewport, e.source))
64 {
65 offsetX.setPosition (offsetX.getPosition());
66 offsetY.setPosition (offsetY.getPosition());
67
68 // switch to a global mouse listener so we still receive mouseUp events
69 // if the original event component is deleted
70 viewport.contentHolder.removeMouseListener (this);
72
73 isGlobalMouseListener = true;
74
75 scrollSource = e.source;
76 }
77 }
78
79 void mouseDrag (const MouseEvent& e) override
80 {
81 if (e.source == scrollSource
82 && ! doesMouseEventComponentBlockViewportDrag (e.eventComponent))
83 {
85
86 if (! isDragging && totalOffset.getDistanceFromOrigin() > 8.0f && detail::ViewportHelpers::wouldScrollOnEvent (&viewport, e.source))
87 {
88 isDragging = true;
89
90 originalViewPos = viewport.getViewPosition();
91 offsetX.setPosition (0.0);
92 offsetX.beginDrag();
93 offsetY.setPosition (0.0);
94 offsetY.beginDrag();
95 }
96
97 if (isDragging)
98 {
99 offsetX.drag (totalOffset.x);
100 offsetY.drag (totalOffset.y);
101 }
102 }
103 }
104
105 void mouseUp (const MouseEvent& e) override
106 {
107 if (isGlobalMouseListener && e.source == scrollSource)
108 endDragAndClearGlobalMouseListener();
109 }
110
111 void endDragAndClearGlobalMouseListener()
112 {
113 if (std::exchange (isDragging, false) == true)
114 {
115 offsetX.endDrag();
116 offsetY.endDrag();
117 }
118
119 viewport.contentHolder.addMouseListener (this, true);
121
122 isGlobalMouseListener = false;
123 }
124
125 bool doesMouseEventComponentBlockViewportDrag (const Component* eventComp)
126 {
127 for (auto c = eventComp; c != nullptr && c != &viewport; c = c->getParentComponent())
128 if (c->getViewportIgnoreDragFlag())
129 return true;
130
131 return false;
132 }
133
134 Viewport& viewport;
135 ViewportDragPosition offsetX, offsetY;
136 Point<int> originalViewPos;
137 MouseInputSource scrollSource = Desktop::getInstance().getMainMouseSource();
138 bool isDragging = false;
139 bool isGlobalMouseListener = false;
140
142};
143
144//==============================================================================
146 : Component (name),
147 dragToScrollListener (std::make_unique<DragToScrollListener> (*this))
148{
149 // content holder is used to clip the contents so they don't overlap the scrollbars
150 addAndMakeVisible (contentHolder);
151 contentHolder.setInterceptsMouseClicks (false, true);
152
153 scrollBarThickness = getLookAndFeel().getDefaultScrollbarWidth();
154
155 setInterceptsMouseClicks (false, true);
157
159}
160
162{
163 deleteOrRemoveContentComp();
164}
165
166//==============================================================================
169
170//==============================================================================
171void Viewport::deleteOrRemoveContentComp()
172{
173 if (contentComp != nullptr)
174 {
175 contentComp->removeComponentListener (this);
176
177 if (deleteContent)
178 {
179 // This sets the content comp to a null pointer before deleting the old one, in case
180 // anything tries to use the old one while it's in mid-deletion..
181 std::unique_ptr<Component> oldCompDeleter (contentComp.get());
182 contentComp = nullptr;
183 }
184 else
185 {
186 contentHolder.removeChildComponent (contentComp);
187 contentComp = nullptr;
188 }
189 }
190}
191
193{
194 if (contentComp.get() != newViewedComponent)
195 {
196 deleteOrRemoveContentComp();
197 contentComp = newViewedComponent;
198 deleteContent = deleteComponentWhenNoLongerNeeded;
199
200 if (contentComp != nullptr)
201 {
202 contentHolder.addAndMakeVisible (contentComp);
204 contentComp->addComponentListener (this);
205 }
206
207 viewedComponentChanged (contentComp);
208 updateVisibleArea();
209 }
210}
211
213{
214 verticalScrollBar.reset();
215 horizontalScrollBar.reset();
216
217 verticalScrollBar .reset (createScrollBarComponent (true));
218 horizontalScrollBar.reset (createScrollBarComponent (false));
219
220 addChildComponent (verticalScrollBar.get());
221 addChildComponent (horizontalScrollBar.get());
222
227
228 resized();
229}
230
231int Viewport::getMaximumVisibleWidth() const { return contentHolder.getWidth(); }
232int Viewport::getMaximumVisibleHeight() const { return contentHolder.getHeight(); }
233
234bool Viewport::canScrollVertically() const noexcept { return contentComp->getY() < 0 || contentComp->getBottom() > getHeight(); }
235bool Viewport::canScrollHorizontally() const noexcept { return contentComp->getX() < 0 || contentComp->getRight() > getWidth(); }
236
237Point<int> Viewport::viewportPosToCompPos (Point<int> pos) const
238{
239 jassert (contentComp != nullptr);
240
241 auto contentBounds = contentHolder.getLocalArea (contentComp.get(), contentComp->getLocalBounds());
242
243 Point<int> p (jmax (jmin (0, contentHolder.getWidth() - contentBounds.getWidth()), jmin (0, -(pos.x))),
244 jmax (jmin (0, contentHolder.getHeight() - contentBounds.getHeight()), jmin (0, -(pos.y))));
245
246 return p.transformedBy (contentComp->getTransform().inverted());
247}
248
253
255{
256 if (contentComp != nullptr)
257 contentComp->setTopLeftPosition (viewportPosToCompPos (newPosition));
258}
259
260void Viewport::setViewPositionProportionately (const double x, const double y)
261{
262 if (contentComp != nullptr)
263 setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
264 jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
265}
266
267bool Viewport::autoScroll (const int mouseX, const int mouseY, const int activeBorderThickness, const int maximumSpeed)
268{
269 if (contentComp != nullptr)
270 {
271 int dx = 0, dy = 0;
272
274 {
277 else if (mouseX >= contentHolder.getWidth() - activeBorderThickness)
278 dx = (contentHolder.getWidth() - activeBorderThickness) - mouseX;
279
280 if (dx < 0)
281 dx = jmax (dx, -maximumSpeed, contentHolder.getWidth() - contentComp->getRight());
282 else
283 dx = jmin (dx, maximumSpeed, -contentComp->getX());
284 }
285
287 {
290 else if (mouseY >= contentHolder.getHeight() - activeBorderThickness)
291 dy = (contentHolder.getHeight() - activeBorderThickness) - mouseY;
292
293 if (dy < 0)
294 dy = jmax (dy, -maximumSpeed, contentHolder.getHeight() - contentComp->getBottom());
295 else
296 dy = jmin (dy, maximumSpeed, -contentComp->getY());
297 }
298
299 if (dx != 0 || dy != 0)
300 {
301 contentComp->setTopLeftPosition (contentComp->getX() + dx,
302 contentComp->getY() + dy);
303
304 return true;
305 }
306 }
307
308 return false;
309}
310
312{
313 updateVisibleArea();
314}
315
316//==============================================================================
318{
319 scrollOnDragMode = mode;
320}
321
323{
324 return dragToScrollListener->isDragging;
325}
326
327//==============================================================================
329{
330 if (! customScrollBarThickness)
331 {
332 scrollBarThickness = getLookAndFeel().getDefaultScrollbarWidth();
333 resized();
334 }
335}
336
338{
339 updateVisibleArea();
340}
341
342//==============================================================================
343void Viewport::updateVisibleArea()
344{
347 const bool canShowHBar = showHScrollbar && canShowAnyBars;
348 const bool canShowVBar = showVScrollbar && canShowAnyBars;
349
350 bool hBarVisible = false, vBarVisible = false;
351 Rectangle<int> contentArea;
352
353 for (int i = 3; --i >= 0;)
354 {
357 contentArea = getLocalBounds();
358
359 if (contentComp != nullptr && ! contentArea.contains (contentComp->getBounds()))
360 {
361 hBarVisible = canShowHBar && (hBarVisible || contentComp->getX() < 0 || contentComp->getRight() > contentArea.getWidth());
362 vBarVisible = canShowVBar && (vBarVisible || contentComp->getY() < 0 || contentComp->getBottom() > contentArea.getHeight());
363
364 if (vBarVisible)
365 contentArea.setWidth (getWidth() - scrollbarWidth);
366
367 if (hBarVisible)
368 contentArea.setHeight (getHeight() - scrollbarWidth);
369
370 if (! contentArea.contains (contentComp->getBounds()))
371 {
372 hBarVisible = canShowHBar && (hBarVisible || contentComp->getRight() > contentArea.getWidth());
373 vBarVisible = canShowVBar && (vBarVisible || contentComp->getBottom() > contentArea.getHeight());
374 }
375 }
376
377 if (vBarVisible) contentArea.setWidth (getWidth() - scrollbarWidth);
378 if (hBarVisible) contentArea.setHeight (getHeight() - scrollbarWidth);
379
380 if (! vScrollbarRight && vBarVisible)
381 contentArea.setX (scrollbarWidth);
382
383 if (! hScrollbarBottom && hBarVisible)
384 contentArea.setY (scrollbarWidth);
385
386 if (contentComp == nullptr)
387 {
388 contentHolder.setBounds (contentArea);
389 break;
390 }
391
392 auto oldContentBounds = contentComp->getBounds();
393 contentHolder.setBounds (contentArea);
394
395 // If the content has changed its size, that might affect our scrollbars, so go round again and re-calculate..
396 if (oldContentBounds == contentComp->getBounds())
397 break;
398 }
399
400 Rectangle<int> contentBounds;
401
402 if (auto cc = contentComp.get())
403 contentBounds = contentHolder.getLocalArea (cc, cc->getLocalBounds());
404
405 auto visibleOrigin = -contentBounds.getPosition();
406
408 auto& vbar = getVerticalScrollBar();
409
410 hbar.setBounds (contentArea.getX(), hScrollbarBottom ? contentArea.getHeight() : 0, contentArea.getWidth(), scrollbarWidth);
411 hbar.setRangeLimits (0.0, contentBounds.getWidth());
412 hbar.setCurrentRange (visibleOrigin.x, contentArea.getWidth());
413 hbar.setSingleStepSize (singleStepX);
414
415 if (canShowHBar && ! hBarVisible)
416 visibleOrigin.setX (0);
417
418 vbar.setBounds (vScrollbarRight ? contentArea.getWidth() : 0, contentArea.getY(), scrollbarWidth, contentArea.getHeight());
419 vbar.setRangeLimits (0.0, contentBounds.getHeight());
420 vbar.setCurrentRange (visibleOrigin.y, contentArea.getHeight());
421 vbar.setSingleStepSize (singleStepY);
422
423 if (canShowVBar && ! vBarVisible)
424 visibleOrigin.setY (0);
425
426 // Force the visibility *after* setting the ranges to avoid flicker caused by edge conditions in the numbers.
427 hbar.setVisible (hBarVisible);
428 vbar.setVisible (vBarVisible);
429
430 if (contentComp != nullptr)
431 {
432 auto newContentCompPos = viewportPosToCompPos (visibleOrigin);
433
434 if (contentComp->getBounds().getPosition() != newContentCompPos)
435 {
436 contentComp->setTopLeftPosition (newContentCompPos); // (this will re-entrantly call updateVisibleArea again)
437 return;
438 }
439 }
440
441 const Rectangle<int> visibleArea (visibleOrigin.x, visibleOrigin.y,
442 jmin (contentBounds.getWidth() - visibleOrigin.x, contentArea.getWidth()),
443 jmin (contentBounds.getHeight() - visibleOrigin.y, contentArea.getHeight()));
444
445 if (lastVisibleArea != visibleArea)
446 {
447 lastVisibleArea = visibleArea;
449 }
450
451 hbar.handleUpdateNowIfNeeded();
452 vbar.handleUpdateNowIfNeeded();
453}
454
455//==============================================================================
456void Viewport::setSingleStepSizes (const int stepX, const int stepY)
457{
458 if (singleStepX != stepX || singleStepY != stepY)
459 {
460 singleStepX = stepX;
461 singleStepY = stepY;
462 updateVisibleArea();
463 }
464}
465
470{
471 allowScrollingWithoutScrollbarV = allowVerticalScrollingWithoutScrollbar;
472 allowScrollingWithoutScrollbarH = allowHorizontalScrollingWithoutScrollbar;
473
474 if (showVScrollbar != showVerticalScrollbarIfNeeded
475 || showHScrollbar != showHorizontalScrollbarIfNeeded)
476 {
477 showVScrollbar = showVerticalScrollbarIfNeeded;
478 showHScrollbar = showHorizontalScrollbarIfNeeded;
479 updateVisibleArea();
480 }
481}
482
483void Viewport::setScrollBarThickness (const int thickness)
484{
485 int newThickness;
486
487 // To stay compatible with the previous code: use the
488 // default thickness if thickness parameter is zero
489 // or negative
490 if (thickness <= 0)
491 {
492 customScrollBarThickness = false;
494 }
495 else
496 {
497 customScrollBarThickness = true;
498 newThickness = thickness;
499 }
500
501 if (scrollBarThickness != newThickness)
502 {
503 scrollBarThickness = newThickness;
504 updateVisibleArea();
505 }
506}
507
509{
510 return scrollBarThickness;
511}
512
514{
516
517 if (scrollBarThatHasMoved == horizontalScrollBar.get())
518 {
520 }
521 else if (scrollBarThatHasMoved == verticalScrollBar.get())
522 {
524 }
525}
526
528{
529 if (e.eventComponent == this)
530 if (! useMouseWheelMoveIfNeeded (e, wheel))
532}
533
535{
536 if (e.eventComponent == horizontalScrollBar.get() || e.eventComponent == verticalScrollBar.get())
537 dragToScrollListener->stopOngoingAnimation();
538}
539
540static int rescaleMouseWheelDistance (float distance, int singleStepSize) noexcept
541{
542 if (approximatelyEqual (distance, 0.0f))
543 return 0;
544
545 distance *= 14.0f * (float) singleStepSize;
546
547 return roundToInt (distance < 0 ? jmin (distance, -1.0f)
548 : jmax (distance, 1.0f));
549}
550
551bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, const MouseWheelDetails& wheel)
552{
553 if (! (e.mods.isAltDown() || e.mods.isCtrlDown() || e.mods.isCommandDown()))
554 {
555 const bool canScrollVert = (allowScrollingWithoutScrollbarV || getVerticalScrollBar().isVisible());
556 const bool canScrollHorz = (allowScrollingWithoutScrollbarH || getHorizontalScrollBar().isVisible());
557
559 {
560 auto deltaX = rescaleMouseWheelDistance (wheel.deltaX, singleStepX);
561 auto deltaY = rescaleMouseWheelDistance (wheel.deltaY, singleStepY);
562
563 auto pos = getViewPosition();
564
565 if (deltaX != 0 && deltaY != 0 && canScrollHorz && canScrollVert)
566 {
567 pos.x -= deltaX;
568 pos.y -= deltaY;
569 }
570 else if (canScrollHorz && (deltaX != 0 || e.mods.isShiftDown() || ! canScrollVert))
571 {
572 pos.x -= deltaX != 0 ? deltaX : deltaY;
573 }
574 else if (canScrollVert && deltaY != 0)
575 {
576 pos.y -= deltaY;
577 }
578
579 if (pos != getViewPosition())
580 {
581 setViewPosition (pos);
582 return true;
583 }
584 }
585 }
586
587 return false;
588}
589
590static bool isUpDownKeyPress (const KeyPress& key)
591{
592 return key == KeyPress::upKey
593 || key == KeyPress::downKey
594 || key == KeyPress::pageUpKey
595 || key == KeyPress::pageDownKey
596 || key == KeyPress::homeKey
597 || key == KeyPress::endKey;
598}
599
600static bool isLeftRightKeyPress (const KeyPress& key)
601{
602 return key == KeyPress::leftKey
603 || key == KeyPress::rightKey;
604}
605
607{
608 const bool isUpDownKey = isUpDownKeyPress (key);
609
611 return getVerticalScrollBar().keyPressed (key);
612
613 const bool isLeftRightKey = isLeftRightKeyPress (key);
614
616 return getHorizontalScrollBar().keyPressed (key);
617
618 return false;
619}
620
621bool Viewport::respondsToKey (const KeyPress& key)
622{
623 return isUpDownKeyPress (key) || isLeftRightKeyPress (key);
624}
625
627{
628 return new ScrollBar (isVertical);
629}
630
631std::unique_ptr<AccessibilityHandler> Viewport::AccessibilityIgnoredComponent::createAccessibilityHandler()
632{
634}
635
638{
639 vScrollbarRight = verticalScrollbarOnRight;
640 hScrollbarBottom = horizontalScrollbarAtBottom;
641
642 resized();
643}
644
645} // namespace juce
Behaviour behaviour
The behaviour object.
void addListener(Listener *listener)
Adds a listener to be called when the value changes.
void endDrag()
Called after beginDrag() and drag() to indicate that the drag operation has now finished.
void setPosition(double newPosition)
Explicitly sets the position and stops any further movement.
double getPosition() const noexcept
Returns the current position.
void beginDrag()
Called to indicate that the object is now being controlled by a mouse-drag or similar operation.
void drag(double deltaFromStartOfDrag)
Called during a mouse-drag operation, to indicate that the mouse has moved.
The base class for all JUCE user-interface objects.
void setInterceptsMouseClicks(bool allowClicksOnThisComponent, bool allowClicksOnChildComponents) noexcept
Changes the default return value for the hitTest() method.
bool isVisible() const noexcept
Tests whether the component is visible or not.
Component * getParentComponent() const noexcept
Returns the component which this component is inside.
int getHeight() const noexcept
Returns the component's height in pixels.
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
void addMouseListener(MouseListener *newListener, bool wantsEventsForAllNestedChildComponents)
Registers a listener to be told when mouse events occur in this component.
Component() noexcept
Creates a component.
int getY() const noexcept
Returns the y coordinate of the top of this component.
void setWantsKeyboardFocus(bool wantsFocus) noexcept
Sets a flag to indicate whether this component wants keyboard focus or not.
int getWidth() const noexcept
Returns the component's width in pixels.
void mouseWheelMove(const MouseEvent &event, const MouseWheelDetails &wheel) override
Called when the mouse-wheel is moved.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
void addChildComponent(Component *child, int zOrder=-1)
Adds a child component to this one.
void addGlobalMouseListener(MouseListener *listener)
Registers a MouseListener that will receive all mouse events that occur on any component.
MouseInputSource getMainMouseSource() const noexcept
Returns the main mouse input device that the system is using.
static Desktop &JUCE_CALLTYPE getInstance()
There's only one desktop object, and this method will return it.
void removeGlobalMouseListener(MouseListener *listener)
Unregisters a MouseListener that was added with addGlobalMouseListener().
Represents a key press, including any modifier keys that are needed.
static const int homeKey
key-code for the home key
static const int upKey
key-code for the cursor-up key
static const int endKey
key-code for the end key
static const int rightKey
key-code for the cursor-right key
static const int downKey
key-code for the cursor-down key
static const int leftKey
key-code for the cursor-left key
static const int pageUpKey
key-code for the page-up key
static const int pageDownKey
key-code for the page-down key
Contains position and status information about a mouse event.
MouseInputSource source
The source device that generated this event.
Point< int > getOffsetFromDragStart() const noexcept
Returns the difference between the mouse's current position and where it was when the button was last...
MouseEvent getEventRelativeTo(Component *newComponent) const noexcept
Creates a version of this event that is relative to a different component.
Component *const eventComponent
The component that this event applies to.
A MouseListener can be registered with a component to receive callbacks about mouse events that happe...
A pair of (x, y) coordinates.
Definition juce_Point.h:42
constexpr Point< float > toFloat() const noexcept
Casts this point to a Point<float> object.
Definition juce_Point.h:239
ValueType y
The point's Y coordinate.
Definition juce_Point.h:252
ValueType x
The point's X coordinate.
Definition juce_Point.h:251
Manages a rectangle and allows geometric operations to be performed on it.
void setY(ValueType newY) noexcept
Changes the rectangle's Y coordinate.
bool contains(ValueType xCoord, ValueType yCoord) const noexcept
Returns true if this coordinate is inside the rectangle.
ValueType getX() const noexcept
Returns the x coordinate of the rectangle's left-hand-side.
void setHeight(ValueType newHeight) noexcept
Changes the rectangle's height.
ValueType getWidth() const noexcept
Returns the width of the rectangle.
void setX(ValueType newX) noexcept
Changes the rectangle's X coordinate.
void setWidth(ValueType newWidth) noexcept
Changes the rectangle's width.
ValueType getHeight() const noexcept
Returns the height of the rectangle.
A scrollbar component.
void addListener(Listener *listener)
Registers a listener that will be called when the scrollbar is moved.
bool keyPressed(const KeyPress &) override
Called when a key is pressed.
bool autoHides() const noexcept
Returns true if this scrollbar is set to auto-hide when its thumb is as big as its maximum range.
The JUCE String class!
Definition juce_String.h:53
A Viewport is used to contain a larger child component, and allows the child to be automatically scro...
void mouseDown(const MouseEvent &e) override
Called when a mouse button is pressed.
void setViewPositionProportionately(double proportionX, double proportionY)
Changes the view position as a proportion of the distance it can move.
void setScrollBarPosition(bool verticalScrollbarOnRight, bool horizontalScrollbarAtBottom)
Changes where the scroll bars are positioned.
virtual void viewedComponentChanged(Component *newComponent)
Callback method that is called when the viewed component is added, removed or swapped.
bool isCurrentlyScrollingOnDrag() const noexcept
Returns true if the user is currently dragging-to-scroll.
int getViewPositionX() const noexcept
Returns the position within the child component of the top-left of its visible area.
int getScrollBarThickness() const
Returns the thickness of the scrollbars.
ScrollBar & getVerticalScrollBar() noexcept
Returns a reference to the scrollbar component being used.
void setScrollOnDragMode(ScrollOnDragMode scrollOnDragMode)
Sets the current scroll-on-drag mode.
bool canScrollVertically() const noexcept
True if there's any off-screen content that could be scrolled vertically, or false if everything is c...
int getMaximumVisibleHeight() const
Returns the height available within this component for the contents.
void componentMovedOrResized(Component &, bool wasMoved, bool wasResized) override
Called when the component's position or size changes.
Point< int > getViewPosition() const noexcept
Returns the position within the child component of the top-left of its visible area.
ScrollBar & getHorizontalScrollBar() noexcept
Returns a reference to the scrollbar component being used.
virtual void visibleAreaChanged(const Rectangle< int > &newVisibleArea)
Callback method that is called when the visible area changes.
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 ...
bool canScrollHorizontally() const noexcept
True if there's any off-screen content that could be scrolled horizontally, or false if everything is...
~Viewport() override
Destructor.
void scrollBarMoved(ScrollBar *, double newRangeStart) override
Called when a ScrollBar is moved.
bool keyPressed(const KeyPress &) override
Called when a key is pressed.
void resized() override
Called when this component's size has been changed.
void setViewPosition(int xPixelsOffset, int yPixelsOffset)
Changes the position of the viewed component.
void setScrollBarsShown(bool showVerticalScrollbarIfNeeded, bool showHorizontalScrollbarIfNeeded, bool allowVerticalScrollingWithoutScrollbar=false, bool allowHorizontalScrollingWithoutScrollbar=false)
Turns scrollbars on or off.
int getViewPositionY() const noexcept
Returns the position within the child component of the top-left of its visible area.
void lookAndFeelChanged() override
Called to let the component react to a change in the look-and-feel setting.
void recreateScrollbars()
Re-instantiates the scrollbars, which is only really useful if you've overridden createScrollBarCompo...
int getMaximumVisibleWidth() const
Returns the width available within this component for the contents.
virtual ScrollBar * createScrollBarComponent(bool isVertical)
Creates the Scrollbar components that will be added to the Viewport.
Viewport(const String &componentName=String())
Creates a Viewport.
void setViewedComponent(Component *newViewedComponent, bool deleteComponentWhenNoLongerNeeded=true)
Sets the component that this viewport will contain and scroll around.
void setSingleStepSizes(int stepX, int stepY)
Changes the distance that a single-step click on a scrollbar button will move the viewport.
void mouseWheelMove(const MouseEvent &, const MouseWheelDetails &) override
Called when the mouse-wheel is moved.
void setScrollBarThickness(int thickness)
Changes the width of the scrollbars.
T exchange(T... args)
#define jassert(expression)
Platform-independent assertion macro.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
typedef float
JUCE Namespace.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.
Contains status information about a mouse wheel event.
void setMinimumVelocity(double newMinimumVelocityToUse) noexcept
Sets the minimum velocity of the movement.
virtual int getDefaultScrollbarWidth()=0
Returns the default thickness to use for a scrollbar.
void mouseUp(const MouseEvent &e) override
Called when a mouse button is released.
void mouseDrag(const MouseEvent &e) override
Called when the mouse is moved while a button is held down.
void mouseDown(const MouseEvent &e) override
Called when a mouse button is pressed.