The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_STRETCHABLEOBJECTRESIZER_H_INCLUDED
  18. #define JUCE_STRETCHABLEOBJECTRESIZER_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A utility class for fitting a set of objects whose sizes can vary between
  22. a minimum and maximum size, into a space.
  23. This is a trickier algorithm than it would first seem, so I've put it in this
  24. class to allow it to be shared by various bits of code.
  25. To use it, create one of these objects, call addItem() to add the list of items
  26. you need, then call resizeToFit(), which will change all their sizes. You can
  27. then retrieve the new sizes with getItemSize() and getNumItems().
  28. It's currently used by the TableHeaderComponent for stretching out the table
  29. headings to fill the table's width.
  30. */
  31. class StretchableObjectResizer
  32. {
  33. public:
  34. //==============================================================================
  35. /** Creates an empty object resizer. */
  36. StretchableObjectResizer();
  37. /** Destructor. */
  38. ~StretchableObjectResizer();
  39. //==============================================================================
  40. /** Adds an item to the list.
  41. The order parameter lets you specify groups of items that are resized first when some
  42. space needs to be found. Those items with an order of 0 will be the first ones to be
  43. resized, and if that doesn't provide enough space to meet the requirements, the algorithm
  44. will then try resizing the items with an order of 1, then 2, and so on.
  45. */
  46. void addItem (double currentSize,
  47. double minSize,
  48. double maxSize,
  49. int order = 0);
  50. /** Resizes all the items to fit this amount of space.
  51. This will attempt to fit them in without exceeding each item's miniumum and
  52. maximum sizes. In cases where none of the items can be expanded or enlarged any
  53. further, the final size may be greater or less than the size passed in.
  54. After calling this method, you can retrieve the new sizes with the getItemSize()
  55. method.
  56. */
  57. void resizeToFit (double targetSize);
  58. /** Returns the number of items that have been added. */
  59. int getNumItems() const noexcept { return items.size(); }
  60. /** Returns the size of one of the items. */
  61. double getItemSize (int index) const noexcept;
  62. private:
  63. //==============================================================================
  64. struct Item
  65. {
  66. double size;
  67. double minSize;
  68. double maxSize;
  69. int order;
  70. };
  71. Array<Item> items;
  72. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (StretchableObjectResizer)
  73. };
  74. #endif // JUCE_STRETCHABLEOBJECTRESIZER_H_INCLUDED