Audio plugin host https://kx.studio/carla
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.

juce_ToolbarItemPalette.cpp 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& tbf, Toolbar& bar)
  18. : factory (tbf), toolbar (bar)
  19. {
  20. Component* const itemHolder = new Component();
  21. viewport.setViewedComponent (itemHolder);
  22. Array <int> allIds;
  23. factory.getAllToolbarItemIds (allIds);
  24. for (int i = 0; i < allIds.size(); ++i)
  25. addComponent (allIds.getUnchecked (i), -1);
  26. addAndMakeVisible (&viewport);
  27. }
  28. ToolbarItemPalette::~ToolbarItemPalette()
  29. {
  30. }
  31. //==============================================================================
  32. void ToolbarItemPalette::addComponent (const int itemId, const int index)
  33. {
  34. if (ToolbarItemComponent* const tc = Toolbar::createItem (factory, itemId))
  35. {
  36. items.insert (index, tc);
  37. viewport.getViewedComponent()->addAndMakeVisible (tc, index);
  38. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  39. }
  40. else
  41. {
  42. jassertfalse;
  43. }
  44. }
  45. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent& comp)
  46. {
  47. const int index = items.indexOf (&comp);
  48. jassert (index >= 0);
  49. items.removeObject (&comp, false);
  50. addComponent (comp.getItemId(), index);
  51. resized();
  52. }
  53. void ToolbarItemPalette::resized()
  54. {
  55. viewport.setBoundsInset (BorderSize<int> (1));
  56. Component* const itemHolder = viewport.getViewedComponent();
  57. const int indent = 8;
  58. const int preferredWidth = viewport.getWidth() - viewport.getScrollBarThickness() - indent;
  59. const int height = toolbar.getThickness();
  60. int x = indent;
  61. int y = indent;
  62. int maxX = 0;
  63. for (int i = 0; i < items.size(); ++i)
  64. {
  65. ToolbarItemComponent* const tc = items.getUnchecked(i);
  66. tc->setStyle (toolbar.getStyle());
  67. int preferredSize = 1, minSize = 1, maxSize = 1;
  68. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  69. {
  70. if (x + preferredSize > preferredWidth && x > indent)
  71. {
  72. x = indent;
  73. y += height;
  74. }
  75. tc->setBounds (x, y, preferredSize, height);
  76. x += preferredSize + 8;
  77. maxX = jmax (maxX, x);
  78. }
  79. }
  80. itemHolder->setSize (maxX, y + height + 8);
  81. }