Request : make CaretComponent width customisable

I agree, a setCaretWidth() or something would be much better.
I actually just needed this again just 2 days ago! Here is the code to put in the lookAndFeel (for an hardcoded width of 1) :

struct ThinnerCaretComponent : public CaretComponent
{
    using CaretComponent::CaretComponent;

    void setCaretPosition (const juce::Rectangle<int>& characterArea) override
    {
        CaretComponent::setCaretPosition (characterArea);
        setBounds (characterArea.withWidth (1));
    }
};

CaretComponent* createCaretComponent (Component* keyFocusOwner) override
{
    return new ThinnerCaretComponent (keyFocusOwner);
}
2 Likes