Hi all,
I have a screen that has a ScreenComponent is inside a ViewportComponent to make is can be scrolled. I draw some thing on ScreenComponent and the UI has a vertical scroll bar on the right side. How to set UI focuses to some where on the screen?
Viewport::setViewPosition()
https://docs.juce.com/master/classViewport.html#a138c2e06be0437fbeab40542c00bbbe1
Rail
@Rail_Jon_Rogut, do you know how to get current position of vertical scroll bar inside a viewport?
I mean how to do if I want an icon moving follow the vertical scroll bar
double dPos = yourViewport.getVerticalScrollBar().getCurrentRange().getStart();
Rail
If you look at the ViewPort class source…
class JUCE_API Viewport : public Component,
private ComponentListener,
private ScrollBar::Listener
{
Notice that it’s derived from ScrollBar::Listener and has a method:
void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
{
auto newRangeStartInt = roundToInt (newRangeStart);
if (scrollBarThatHasMoved == horizontalScrollBar.get())
{
setViewPosition (newRangeStartInt, getViewPositionY());
}
else if (scrollBarThatHasMoved == verticalScrollBar.get())
{
setViewPosition (getViewPositionX(), newRangeStartInt);
}
}
You can derive a class from ViewPort and override scrollBarMoved() which calls the base class and also does what you need.
Rail
Yes @Rail_Jon_Rogut, and I found that we can also use void visibleAreaChanged(const Rectangle<int>& newVisibleArea) override;
Thank you so much