# StretchableLayout problems

**URL:** <https://forum.juce.com/t/stretchablelayout-problems/7358>\
**Category:** General JUCE discussion\
**Created:** [August 24, 2011, 2:36pm UTC](https://forum.juce.com/t/stretchablelayout-problems/7358 "2011-08-24T14:36:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![robiwan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/robiwan/32/2446_2.png) [@robiwan](https://forum.juce.com/u/robiwan)\
**Post date:** [August 24, 2011, 2:36pm UTC](https://forum.juce.com/t/stretchablelayout-problems/7358/1 "2011-08-24T14:36:26Z")

</div>

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

```auto
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 ?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 24, 2011, 3:16pm UTC](https://forum.juce.com/t/stretchablelayout-problems/7358/2 "2011-08-24T15:16:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![robiwan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/robiwan/32/2446_2.png) [@robiwan](https://forum.juce.com/u/robiwan)\
**Post date:** [August 24, 2011, 3:19pm UTC](https://forum.juce.com/t/stretchablelayout-problems/7358/3 "2011-08-24T15:19:54Z")

</div>

Oh dear… 😑

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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 24, 2011, 3:29pm UTC](https://forum.juce.com/t/stretchablelayout-problems/7358/4 "2011-08-24T15:29:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![robiwan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/robiwan/32/2446_2.png) [@robiwan](https://forum.juce.com/u/robiwan)\
**Post date:** [August 24, 2011, 3:35pm UTC](https://forum.juce.com/t/stretchablelayout-problems/7358/5 "2011-08-24T15:35:54Z")

</div>

> [@jules](#):
>
> It does work, I guess it’ll just be one of your number’s that’s wrong, but I can’t see anything obvious.

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

```auto
        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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 24, 2011, 3:38pm UTC](https://forum.juce.com/t/stretchablelayout-problems/7358/6 "2011-08-24T15:38:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![robiwan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/robiwan/32/2446_2.png) [@robiwan](https://forum.juce.com/u/robiwan)\
**Post date:** [August 24, 2011, 3:45pm UTC](https://forum.juce.com/t/stretchablelayout-problems/7358/7 "2011-08-24T15:45:32Z")

</div>

> [@jules](#):
>
> Have you tried using an absolute value for the rhs minimum?

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

---

<div class="post-metadata">

**Author:** ![jaydee](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jaydee](https://forum.juce.com/u/jaydee)\
**Post date:** [August 24, 2011, 6:00pm UTC](https://forum.juce.com/t/stretchablelayout-problems/7358/8 "2011-08-24T18:00:37Z")

</div>

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

```auto

 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

```
