/* ============================================================================== This file is part of the JUCE 6 technical preview. Copyright (c) 2017 - ROLI Ltd. You may use this code under the terms of the GPL v3 (see www.gnu.org/licenses). For this technical preview, this file is not subject to commercial licensing. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE DISCLAIMED. ============================================================================== */ #pragma once //============================================================================== 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 (int 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