/* ============================================================================== This file is part of the JUCE library. Copyright (c) 2015 - ROLI Ltd. Permission is granted to use this software under the terms of either: a) the GPL v2 (or any later version) b) the Affero GPL v3 Details of these licenses can be found at: www.gnu.org/licenses JUCE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ------------------------------------------------------------------------------ To release a closed-source product which uses JUCE, commercial licenses are available: visit www.juce.com for more information. ============================================================================== */ #pragma once #include "../Project/jucer_Project.h" //============================================================================== struct ContentViewHeader : public Component { ContentViewHeader (String headerName, Icon headerIcon) : name (headerName), icon (headerIcon) { } void paint (Graphics& g) override { g.fillAll (findColour (contentHeaderBackgroundColourId)); auto bounds = getLocalBounds().reduced (20, 0); icon.withColour (Colours::white).draw (g, bounds.toFloat().removeFromRight (30), false); g.setColour (Colours::white); g.setFont (Font (18.0f)); g.drawFittedText (name, bounds, Justification::centredLeft, 1); } String name; Icon icon; }; //============================================================================== class ListBoxHeader : public Component { public: ListBoxHeader (Array columnHeaders) { for (auto s : columnHeaders) { addAndMakeVisible (headers.add (new Label (s, s))); widths.add (1.0f / columnHeaders.size()); } setSize (200, 40); } ListBoxHeader (Array columnHeaders, Array columnWidths) { jassert (columnHeaders.size() == columnWidths.size()); auto index = 0; for (auto s : columnHeaders) { addAndMakeVisible (headers.add (new Label (s, s))); widths.add (columnWidths.getUnchecked (index++)); } recalculateWidths(); setSize (200, 40); } void resized() override { auto bounds = getLocalBounds(); auto width = bounds.getWidth(); auto index = 0; for (auto h : headers) { auto headerWidth = roundToInt (width * widths.getUnchecked (index)); h->setBounds (bounds.removeFromLeft (headerWidth)); ++index; } } void setColumnHeaderWidth (int index, float proportionOfWidth) { if (! (isPositiveAndBelow (index, headers.size()) && isPositiveAndNotGreaterThan (proportionOfWidth, 1.0f))) { jassertfalse; return; } widths.set (index, proportionOfWidth); recalculateWidths (index); } int getColumnX (int index) { auto prop = 0.0f; for (auto i = 0; i < index; ++i) prop += widths.getUnchecked (i); return roundToInt (prop * getWidth()); } float getProportionAtIndex (int index) { jassert (isPositiveAndBelow (index, widths.size())); return widths.getUnchecked (index); } private: OwnedArray