juce_GroupComponent.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. A component that draws an outline around itself and has an optional title at
  24. the top, for drawing an outline around a group of controls.
  25. @tags{GUI}
  26. */
  27. class JUCE_API GroupComponent : public Component
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates a GroupComponent.
  32. @param componentName the name to give the component
  33. @param labelText the text to show at the top of the outline
  34. */
  35. GroupComponent (const String& componentName = {},
  36. const String& labelText = {});
  37. /** Destructor. */
  38. ~GroupComponent() override;
  39. //==============================================================================
  40. /** Changes the text that's shown at the top of the component. */
  41. void setText (const String& newText);
  42. /** Returns the currently displayed text label. */
  43. String getText() const;
  44. /** Sets the positioning of the text label.
  45. (The default is Justification::left)
  46. @see getTextLabelPosition
  47. */
  48. void setTextLabelPosition (Justification justification);
  49. /** Returns the current text label position.
  50. @see setTextLabelPosition
  51. */
  52. Justification getTextLabelPosition() const noexcept { return justification; }
  53. //==============================================================================
  54. /** A set of colour IDs to use to change the colour of various aspects of the component.
  55. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  56. methods.
  57. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  58. */
  59. enum ColourIds
  60. {
  61. outlineColourId = 0x1005400, /**< The colour to use for drawing the line around the edge. */
  62. textColourId = 0x1005410 /**< The colour to use to draw the text label. */
  63. };
  64. //==============================================================================
  65. /** This abstract base class is implemented by LookAndFeel classes. */
  66. struct JUCE_API LookAndFeelMethods
  67. {
  68. virtual ~LookAndFeelMethods() = default;
  69. virtual void drawGroupComponentOutline (Graphics&, int w, int h, const String& text,
  70. const Justification&, GroupComponent&) = 0;
  71. };
  72. //==============================================================================
  73. /** @internal */
  74. void paint (Graphics&) override;
  75. /** @internal */
  76. void enablementChanged() override;
  77. /** @internal */
  78. void colourChanged() override;
  79. private:
  80. String text;
  81. Justification justification;
  82. JUCE_DECLARE_NON_COPYABLE (GroupComponent)
  83. };
  84. } // namespace juce