While trying to create a component with a minimum size I came up with this:
MainContentComponent::MainContentComponent() { setSize (600, 400); slider = new Slider(); addAndMakeVisible(slider); slider->setSliderStyle(juce::Slider::LinearHorizontal); slider->setTextBoxStyle(juce::Slider::NoTextBox, true, 110, 110); slider->setSize(200, 100); slider->setCentreRelative(.5, .5); myLayout.setItemLayout (0, // for item 0 50, 300, // must be between 50 and 100 pixels in size -0.9); // and its preferred size is 60% of the total available space setBounds(0, 0, 300, 300); resized(); } MainContentComponent::~MainContentComponent() { delete slider; } void MainContentComponent::resized() { Component* comps[] = { slider }; myLayout.layOutComponents (comps, 1, 50, 50, getWidth()-100, getHeight()-100, false, true); int w = getWidth(); int h = getHeight(); if (w < 500) w = 500; if (h < 500) h = 500; if (w != getWidth() || h != getHeight()) setSize(w, h); }
A couple of questions:
- On Mac OS X Yosemite it seems the resizing is not at all fluent. When resizing the window a bit bigger, coming from the minimum size, there is a "snap"-effect that is not desired. Any idea where this comes from?
- The size on the left of the slider is not the same as the size on the right of the slider? I would expect it to be perfectly symmetrical since in the layOutComponents I ask it to center from the borders. I suspect there is some border for the scroll bars taken into account in the window of the application.
This is a GUI Application created in the Injuicer, with just one changes: added setResizable(true,false); on line 73 of Main.cpp - Is there another way to do this or overriding the resized() call be the recommended way to do this?
Thanks for any help. Also pointers to documentation of course. In case it wasn't clear already: I am a newbie :)