I know this question was already asked previously, but since it’s been 4 years, maybe things changed in the meantime.
My question is very simple, is there an easy way to make the scrollbar of a viewport component to be on the left instead of the default right position?
It might well have been my question you saw on this, 4 years ago. I solved it this way, in this case with a treeview.
This may not be very pretty but it worked then and I haven’t touched it since…
It most certainly is ugly, but, it saves you from forking juce’s viewport class.
Note that I also wanted stepped scrolling - not smooth, which this implements. The step size is in the cellSize variable.
still I am not sure about the solution you propose, can you please precise what is a treeview, and where in the code you decide of the position of the scrollbar?
You don’t need the treeview, it’s just a component that uses a viewport…
What @onar3d does is to disable the built in scrollbars of the viewport using void Viewport::setScrollBarsShown(…). Instead he creates a new instance of scrollbar which you can place in your resize method like any other component:
Unfortunately you cannot connect direcly to the viewport as listener, because that understands only it’s built in. But you can still get inspiration in the source code (or from onar3d’s post):
Now finally the placement left you do in the riesized() method, like you normally define the placement of your widgets:
void resized() override {
const int w = getWidth();
const int h = getHeight();
const int sw = m_viewport->getScrollBarThickness();
m_scrollBar->setBounds (0, 0, sw, h);
m_viewport->setBounds (sw, 0, w-sw, h);
}