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.h
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
29//==============================================================================
44class JUCE_API Viewport : public Component,
45 private ComponentListener,
47{
48public:
49 //==============================================================================
55 explicit Viewport (const String& componentName = String());
56
58 ~Viewport() override;
59
60 //==============================================================================
76 void setViewedComponent (Component* newViewedComponent,
77 bool deleteComponentWhenNoLongerNeeded = true);
78
83 Component* getViewedComponent() const noexcept { return contentComp.get(); }
84
85 //==============================================================================
96 void setViewPosition (int xPixelsOffset, int yPixelsOffset);
97
108 void setViewPosition (Point<int> newPosition);
109
117 void setViewPositionProportionately (double proportionX, double proportionY);
118
134 bool autoScroll (int mouseX, int mouseY, int distanceFromEdge, int maximumSpeed);
135
137 Point<int> getViewPosition() const noexcept { return lastVisibleArea.getPosition(); }
138
140 Rectangle<int> getViewArea() const noexcept { return lastVisibleArea; }
141
145 int getViewPositionX() const noexcept { return lastVisibleArea.getX(); }
146
150 int getViewPositionY() const noexcept { return lastVisibleArea.getY(); }
151
157 int getViewWidth() const noexcept { return lastVisibleArea.getWidth(); }
158
164 int getViewHeight() const noexcept { return lastVisibleArea.getHeight(); }
165
171 int getMaximumVisibleWidth() const;
172
178 int getMaximumVisibleHeight() const;
179
180 //==============================================================================
186 virtual void visibleAreaChanged (const Rectangle<int>& newVisibleArea);
187
189 virtual void viewedComponentChanged (Component* newComponent);
190
191 //==============================================================================
201 void setScrollBarsShown (bool showVerticalScrollbarIfNeeded,
202 bool showHorizontalScrollbarIfNeeded,
203 bool allowVerticalScrollingWithoutScrollbar = false,
204 bool allowHorizontalScrollingWithoutScrollbar = false);
205
216 void setScrollBarPosition (bool verticalScrollbarOnRight,
217 bool horizontalScrollbarAtBottom);
218
220 bool isVerticalScrollbarOnTheRight() const noexcept { return vScrollbarRight; }
221
223 bool isHorizontalScrollbarAtBottom() const noexcept { return hScrollbarBottom; }
224
228 bool isVerticalScrollBarShown() const noexcept { return showVScrollbar; }
229
233 bool isHorizontalScrollBarShown() const noexcept { return showHScrollbar; }
234
239 void setScrollBarThickness (int thickness);
240
244 int getScrollBarThickness() const;
245
249 void setSingleStepSizes (int stepX, int stepY);
250
254 ScrollBar& getVerticalScrollBar() noexcept { return *verticalScrollBar; }
255
259 ScrollBar& getHorizontalScrollBar() noexcept { return *horizontalScrollBar; }
260
262 void recreateScrollbars();
263
267 bool canScrollVertically() const noexcept;
268
272 bool canScrollHorizontally() const noexcept;
273
280 [[deprecated ("Use setScrollOnDragMode instead.")]]
281 void setScrollOnDragEnabled (bool shouldScrollOnDrag)
282 {
283 setScrollOnDragMode (shouldScrollOnDrag ? ScrollOnDragMode::all : ScrollOnDragMode::never);
284 }
285
287 [[deprecated ("Use getScrollOnDragMode instead.")]]
288 bool isScrollOnDragEnabled() const noexcept { return getScrollOnDragMode() == ScrollOnDragMode::all; }
289
291 {
292 never,
293 nonHover,
294 all
295 };
296
303 void setScrollOnDragMode (ScrollOnDragMode scrollOnDragMode);
304
306 ScrollOnDragMode getScrollOnDragMode() const { return scrollOnDragMode; }
307
311 bool isCurrentlyScrollingOnDrag() const noexcept;
312
313 //==============================================================================
315 void resized() override;
317 void scrollBarMoved (ScrollBar*, double newRangeStart) override;
319 void mouseWheelMove (const MouseEvent&, const MouseWheelDetails&) override;
321 void mouseDown (const MouseEvent& e) override;
323 bool keyPressed (const KeyPress&) override;
325 void componentMovedOrResized (Component&, bool wasMoved, bool wasResized) override;
327 void lookAndFeelChanged() override;
329 bool useMouseWheelMoveIfNeeded (const MouseEvent&, const MouseWheelDetails&);
331 static bool respondsToKey (const KeyPress&);
332
333protected:
334 //==============================================================================
338 virtual ScrollBar* createScrollBarComponent (bool isVertical);
339
340private:
341 //==============================================================================
342 class AccessibilityIgnoredComponent : public Component
343 {
344 public:
345 std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
346 };
347
348 std::unique_ptr<ScrollBar> verticalScrollBar, horizontalScrollBar;
349 AccessibilityIgnoredComponent contentHolder;
350 WeakReference<Component> contentComp;
351 Rectangle<int> lastVisibleArea;
352 int scrollBarThickness = 0;
353 int singleStepX = 16, singleStepY = 16;
354 ScrollOnDragMode scrollOnDragMode = ScrollOnDragMode::nonHover;
355 bool showHScrollbar = true, showVScrollbar = true, deleteContent = true;
356 bool customScrollBarThickness = false;
357 bool allowScrollingWithoutScrollbarV = false, allowScrollingWithoutScrollbarH = false;
358 bool vScrollbarRight = true, hScrollbarBottom = true;
359
360 struct DragToScrollListener;
361 std::unique_ptr<DragToScrollListener> dragToScrollListener;
362
363 Point<int> viewportPosToCompPos (Point<int>) const;
364
365 void updateVisibleArea();
366 void deleteOrRemoveContentComp();
367
369};
370
371} // namespace juce
Gets informed about changes to a component's hierarchy or position.
The base class for all JUCE user-interface objects.
Represents a key press, including any modifier keys that are needed.
Contains position and status information about a mouse event.
A pair of (x, y) coordinates.
Definition juce_Point.h:42
Manages a rectangle and allows geometric operations to be performed on it.
A class for receiving events from a ScrollBar.
A scrollbar component.
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...
bool isHorizontalScrollbarAtBottom() const noexcept
True if the horizontal scrollbar will appear at the bottom of the content.
int getViewWidth() const noexcept
Returns the width of the visible area of the child component.
Component * getViewedComponent() const noexcept
Returns the component that's currently being used inside the Viewport.
bool isVerticalScrollbarOnTheRight() const noexcept
True if the vertical scrollbar will appear on the right side of the content.
int getViewPositionX() const noexcept
Returns the position within the child component of the top-left of its visible area.
ScrollBar & getVerticalScrollBar() noexcept
Returns a reference to the scrollbar component being used.
ScrollOnDragMode getScrollOnDragMode() const
Returns the current scroll-on-drag mode.
Point< int > getViewPosition() const noexcept
Returns the position within the child component of the top-left of its visible area.
int getViewHeight() const noexcept
Returns the height of the visible area of the child component.
ScrollBar & getHorizontalScrollBar() noexcept
Returns a reference to the scrollbar component being used.
bool isHorizontalScrollBarShown() const noexcept
True if the horizontal scrollbar is enabled.
Rectangle< int > getViewArea() const noexcept
Returns the visible area of the child component, relative to its top-left.
int getViewPositionY() const noexcept
Returns the position within the child component of the top-left of its visible area.
bool isVerticalScrollBarShown() const noexcept
True if the vertical scrollbar is enabled.
bool isScrollOnDragEnabled() const noexcept
Returns true if drag-to-scroll functionality is enabled for mouse input sources.
#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 ...
JUCE Namespace.
Contains status information about a mouse wheel event.