juce_ResizableEdgeComponent.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 resizes its parent component when dragged.
  24. This component forms a bar along one edge of a component, allowing it to
  25. be dragged by that edges to resize it.
  26. To use it, just add it to your component, positioning it along the appropriate
  27. edge. Make sure you reposition the resizer component each time the parent's size
  28. changes, to keep it in the correct position.
  29. @see ResizbleBorderComponent, ResizableCornerComponent
  30. @tags{GUI}
  31. */
  32. class JUCE_API ResizableEdgeComponent : public Component
  33. {
  34. public:
  35. //==============================================================================
  36. enum Edge
  37. {
  38. leftEdge, /**< Indicates a vertical bar that can be dragged left/right to move the component's left-hand edge. */
  39. rightEdge, /**< Indicates a vertical bar that can be dragged left/right to move the component's right-hand edge. */
  40. topEdge, /**< Indicates a horizontal bar that can be dragged up/down to move the top of the component. */
  41. bottomEdge /**< Indicates a horizontal bar that can be dragged up/down to move the bottom of the component. */
  42. };
  43. /** Creates a resizer bar.
  44. Pass in the target component which you want to be resized when this one is
  45. dragged. The target component will usually be this component's parent, but this
  46. isn't mandatory.
  47. Remember that when the target component is resized, it'll need to move and
  48. resize this component to keep it in place, as this won't happen automatically.
  49. If the constrainer parameter is not a nullptr, then this object will be used to
  50. enforce limits on the size and position that the component can be stretched to.
  51. Make sure that the constrainer isn't deleted while still in use by this object.
  52. @see ComponentBoundsConstrainer
  53. */
  54. ResizableEdgeComponent (Component* componentToResize,
  55. ComponentBoundsConstrainer* constrainer,
  56. Edge edgeToResize);
  57. /** Destructor. */
  58. ~ResizableEdgeComponent() override;
  59. bool isVertical() const noexcept;
  60. protected:
  61. //==============================================================================
  62. /** @internal */
  63. void paint (Graphics&) override;
  64. /** @internal */
  65. void mouseDown (const MouseEvent&) override;
  66. /** @internal */
  67. void mouseDrag (const MouseEvent&) override;
  68. /** @internal */
  69. void mouseUp (const MouseEvent&) override;
  70. private:
  71. WeakReference<Component> component;
  72. ComponentBoundsConstrainer* constrainer;
  73. Rectangle<int> originalBounds;
  74. const Edge edge;
  75. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ResizableEdgeComponent)
  76. };
  77. } // namespace juce