2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
23 ==============================================================================
29 //==============================================================================
31 A utility class for fitting a set of objects whose sizes can vary between
32 a minimum and maximum size, into a space.
34 This is a trickier algorithm than it would first seem, so I've put it in this
35 class to allow it to be shared by various bits of code.
37 To use it, create one of these objects, call addItem() to add the list of items
38 you need, then call resizeToFit(), which will change all their sizes. You can
39 then retrieve the new sizes with getItemSize() and getNumItems().
41 It's currently used by the TableHeaderComponent for stretching out the table
42 headings to fill the table's width.
46 class StretchableObjectResizer
49 //==============================================================================
50 /** Creates an empty object resizer. */
51 StretchableObjectResizer();
54 ~StretchableObjectResizer();
56 //==============================================================================
57 /** Adds an item to the list.
59 The order parameter lets you specify groups of items that are resized first when some
60 space needs to be found. Those items with an order of 0 will be the first ones to be
61 resized, and if that doesn't provide enough space to meet the requirements, the algorithm
62 will then try resizing the items with an order of 1, then 2, and so on.
64 void addItem (double currentSize
,
69 /** Resizes all the items to fit this amount of space.
71 This will attempt to fit them in without exceeding each item's minimum and
72 maximum sizes. In cases where none of the items can be expanded or enlarged any
73 further, the final size may be greater or less than the size passed in.
75 After calling this method, you can retrieve the new sizes with the getItemSize()
78 void resizeToFit (double targetSize
);
80 /** Returns the number of items that have been added. */
81 int getNumItems() const noexcept
{ return items
.size(); }
83 /** Returns the size of one of the items. */
84 double getItemSize (int index
) const noexcept
;
88 //==============================================================================
99 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (StretchableObjectResizer
)