/* ============================================================================== This file is part of the JUCE framework. Copyright (c) Raw Material Software Limited JUCE is an open source framework subject to commercial or open source licensing. By downloading, installing, or using the JUCE framework, or combining the JUCE framework with any other source code, object code, content or any other copyrightable work, you agree to the terms of the JUCE End User Licence Agreement, and all incorporated terms including the JUCE Privacy Policy and the JUCE Website Terms of Service, as applicable, which will bind you. If you do not agree to the terms of these agreements, we will not license the JUCE framework to you, and you must discontinue the installation or download process and cease use of the JUCE framework. JUCE End User Licence Agreement: https://juce.com/legal/juce-8-licence/ JUCE Privacy Policy: https://juce.com/juce-privacy-policy JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/ Or: You may also use this code under the terms of the AGPLv3: https://www.gnu.org/licenses/agpl-3.0.en.html THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. ============================================================================== */ #pragma once #include "../../Utility/UI/PropertyComponents/jucer_LabelPropertyComponent.h" //============================================================================== struct ContentViewHeader final : 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 (FontOptions (18.0f)); g.drawFittedText (name, bounds, Justification::centredLeft, 1); } String name; Icon icon; }; //============================================================================== class ListBoxHeader final : 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()); for (const auto [index, s] : enumerate (columnHeaders)) { addAndMakeVisible (headers.add (new Label (s, s))); widths.add (columnWidths.getUnchecked ((int) 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