Hey,
I’m trying to create a label component which is draggable.
At first I tried to use composition:
I created a component which has a label and a ComponentDragger. I used addMouseListener(this, true) in my component to get mouseDown and mouseDrag event which happend in the label. But when the label is being edited, the dragger of the parent component avoid text selection (as the component is dragged instead). So I had to use conditional in my component callback: if (mLabel.isBeingEdited() == false).
I also I tried to use inheritance:
class CustomLabel : public Label
{
public:
CustomLabel()
{
setFont(Font (16.0f, Font::bold));
setText("Test", dontSendNotification);
setColour(Label::textColourId, Colours::lightgreen);
setJustificationType(Justification::centred);
setEditable(false, true);
}
void mouseDown(const MouseEvent& event) override
{
mDragger.startDraggingComponent(this, event);
}
void mouseDrag(const MouseEvent& event) override
{
mDragger.dragComponent(this, event, nullptr);
}
private:
ComponentDragger mDragger;
};
This seems to work but I have no Idea why, I expected that I would still need the condition in mousedown and mousedrag listener. But I don’t … Any idea why ?
What is the nicest way to do this ? I’m new to Juce so I’m trying to learn the right way to do things. Thanks for your help and sorry if it sounds like a fake problem.
Best,
