StretchableLayout problems


#1

I have a component that shall divide its client area between 2 components (with a resize bar in between):

class ContentAndHelpComponent : public Component
{
    StretchableLayoutManager m_layoutManager;

public:
    ContentAndHelpComponent(ContentWindow* pContentWindow) 
    {
        addAndMakeVisible(pContentWindow);
        addAndMakeVisible(new StretchableLayoutResizerBar(&m_layoutManager, 1, true));
        addAndMakeVisible(new InfoWindow);

        m_layoutManager.setItemLayout (0,          // for item 0
            -.6, -1.,    // must be between 60 and 100 % in size
            -1.);      // and its preferred size is 100% of the total available space

        // The resizer bar
        m_layoutManager.setItemLayout (1,
            8, 8,
            8);

        m_layoutManager.setItemLayout (2,          // for item 2
            -0., -.4, // size must be between 0% and 40% of the available space
            -0.);        // and its preferred size is 0 pixels
    }
    ~ContentAndHelpComponent()
    {
        deleteAllChildren();
    }

    void resized()
    {
        // make a list of our child components that we want to reposition
        Component* comps[] = { getChildComponent(0), getChildComponent(1), getChildComponent(2) };

        // this will position the components, one beside the other, to fit
        // horizontally into the rectangle provided.
        m_layoutManager.layOutComponents (comps, 3,
            0, 0, getWidth(), getHeight(),
            false,
            true);
    }

};

I can see the first component, but I cannot move the resize bar (from the far right) more than a few pixels. What am I doing wrong ?


#2

Damn, I hate that stretchablelayout stuff… Seemed like a good idea at the time, but it’s just a pain to use…


#3

Oh dear… :expressionless:

So what are my options ? I don’t have time to roll my own :frowning:


#4

It does work, I guess it’ll just be one of your number’s that’s wrong, but I can’t see anything obvious.


#5

Ok, maybe this hint will help you in helping me :slight_smile: If I change the layout settings to:

        m_layoutManager.setItemLayout (0,          // for item 0
            -.6, -1.,    // must be between 60 and 100 % in size
            -1.);      // and its preferred size is 100% of the total available space

        // The resizer bar
        m_layoutManager.setItemLayout (1,
            8, 8,
            8);

        m_layoutManager.setItemLayout (2,          // for item 2
            -0., -.4, // size must be between 0% and 40% of the available space
            -1.);        // and its preferred size is 0 pixels

I can see all components, move the resize bar and it works fine. UNTIL I move the resize bar far right, at which time it will get “stuck” there, and there is no way to move it left.


#6

Have you tried using an absolute value for the rhs minimum?


#7

Oohh Jules, I bow before thy almightyness, setting minimum to 1 px it works like a charm. Thanks!! :smiley:


#8

I patched StretchableLayoutManager::fitComponentsIntoSpace, but it always seemed hacky… but it worked for my issue…(which sounds similar)


 while (extraSpace > 0)
    {
        int numWantingMoreSpace = 0;
        int numHavingTakenExtraSpace = 0;

        // first figure out how many comps want a slice of the extra space..
        for (i = startIndex; i < endIndex; ++i)
        {
            ItemLayoutProperties* const layout = items.getUnchecked (i);
			
//===== MINE
if (layout->preferredSize==0)
				layout->preferredSize=1;

//====END MINE