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_BurgerMenuComponent.h 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. A component which lists all menu items and groups them into categories
  23. by their respective parent menus. This kind of component is often used
  24. for so-called "burger" menus in mobile apps.
  25. @see MenuBarModel
  26. @tags{GUI}
  27. */
  28. class BurgerMenuComponent : public Component,
  29. private ListBoxModel,
  30. private MenuBarModel::Listener
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates a burger menu component.
  35. @param model the model object to use to control this burger menu. You can
  36. set the parameter or pass nullptr into this if you like,
  37. and set the model later using the setModel() method.
  38. @see setModel
  39. */
  40. BurgerMenuComponent (MenuBarModel* model = nullptr);
  41. /** Destructor. */
  42. ~BurgerMenuComponent() override;
  43. //==============================================================================
  44. /** Changes the model object to use to control the burger menu.
  45. This can be a nullptr, in which case the bar will be empty. This object will not be
  46. owned by the BurgerMenuComponent so it is up to you to manage its lifetime.
  47. Don't delete the object that is passed-in while it's still being used by this MenuBar.
  48. Any submenus in your MenuBarModel will be recursively flattened and added to the
  49. top-level burger menu section.
  50. */
  51. void setModel (MenuBarModel* newModel);
  52. /** Returns the current burger menu model being used. */
  53. MenuBarModel* getModel() const noexcept;
  54. /** @internal */
  55. void lookAndFeelChanged() override;
  56. private:
  57. //==============================================================================
  58. struct Row
  59. {
  60. bool isMenuHeader;
  61. int topLevelMenuIndex;
  62. PopupMenu::Item item;
  63. };
  64. void refresh();
  65. void paint (Graphics&) override;
  66. int getNumRows() override;
  67. void paintListBoxItem (int, Graphics&, int, int, bool) override;
  68. void listBoxItemClicked (int, const MouseEvent&) override;
  69. Component* refreshComponentForRow (int, bool, Component*) override;
  70. void resized() override;
  71. void menuBarItemsChanged (MenuBarModel*) override;
  72. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo&) override;
  73. void mouseUp (const MouseEvent&) override;
  74. void handleCommandMessage (int) override;
  75. void addMenuBarItemsForMenu (PopupMenu&, int);
  76. static bool hasSubMenu (const PopupMenu::Item&);
  77. //==============================================================================
  78. MenuBarModel* model = nullptr;
  79. ListBox listBox {"BurgerMenuListBox", this};
  80. Array<Row> rows;
  81. int lastRowClicked = -1, inputSourceIndexOfLastClick = -1, topLevelIndexClicked = -1;
  82. //==============================================================================
  83. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BurgerMenuComponent)
  84. };
  85. } // namespace juce