How to make a SplitPanel


#1

article removed


#2

The StretchableLayoutManager class does that.
I didn’t look at your code (yet).
Is it possible with your class to add and remove panels dinamically?
I’m currently struggling with the StretchableLayoutManager way of adding components…


#3

[quote=“masshacker”]The StretchableLayoutManager class does that.
[/quote]

Aaah, I see, thanks for the hint! I think by using the StretchableLayoutManager together with a StretchableLayoutResizerBar you can build a splitwindow.
But there seem to be no ready-to-use split component in juce.
My SplitPanel is just a component with 2 child components . If you remove the built-in demo panels, the actual splitting code is very short :

[code]void SplitPanel::setSplitPos( int pos)
{
float w = getWidth()-border-gap-border;

split = (pos-border-(gap/2)) / w;
if(split < splitmin)
    split=splitmin;
else if(split > splitmax)
    split=splitmax;

resized();

}[/code]

[code]void SplitPanel::resized()
{
int w = getWidth()-border-gap-border;
int h = getHeight()-border-border;

int wa = split*w;
int wb = w-wa;

Component* comp =NULL;
int childcount = getNumChildComponents();
if(childcount==2)
{
    comp = getChildComponent(0);       
    comp->setBounds(border,border,wa,h);
    
    comp = getChildComponent(1);       
    comp->setBounds(border+wa+gap,border,wb,h);
}

}[/code]

That’s all, this should work with any component pair, the code just looks for the 2 first child components.