/* ============================================================================== This file is part of the JUCE library. Copyright (c) 2020 - Raw Material Software Limited JUCE is an open source library subject to commercial or open-source licensing. By using JUCE, you agree to the terms of both the JUCE 6 End-User License Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). End User License Agreement: www.juce.com/juce-6-licence Privacy Policy: www.juce.com/juce-privacy-policy Or: You may also use this code under the terms of the GPL v3 (see www.gnu.org/licenses). 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 #include "../../Utility/UI/PropertyComponents/jucer_LabelPropertyComponent.h" //============================================================================== struct ContentViewHeader : public Component { ContentViewHeader (String headerName, Icon headerIcon) : name (headerName), icon (headerIcon) { setTitle (name); } 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 / (float) 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 ((float) 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 * (float) getWidth()); } float getProportionAtIndex (int index) { jassert (isPositiveAndBelow (index, widths.size())); return widths.getUnchecked (index); } private: OwnedArray