VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / modules / juce_gui_basics / layout / juce_StretchableObjectResizer.h
bloba6b7e3f8cb286a61785af1c390f12b5c6195ea64
1 /*
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
8 licensing.
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
21 DISCLAIMED.
23 ==============================================================================
26 namespace juce
29 //==============================================================================
30 /**
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.
44 @tags{GUI}
46 class StretchableObjectResizer
48 public:
49 //==============================================================================
50 /** Creates an empty object resizer. */
51 StretchableObjectResizer();
53 /** Destructor. */
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,
65 double minSize,
66 double maxSize,
67 int order = 0);
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()
76 method.
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;
87 private:
88 //==============================================================================
89 struct Item
91 double size;
92 double minSize;
93 double maxSize;
94 int order;
97 Array<Item> items;
99 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (StretchableObjectResizer)
102 } // namespace juce