Text Component


#1

This is just the TextLayout class wrapped as a Component, for easier implementation of blocks of text in dialogs.

[code]class TextComp : public Component,
public TextLayout
{
public:
TextComp()
: m_Just(Justification::centredLeft), m_Font(15.0f), m_bBalance(false)
{}

TextComp(const TextComp& other)
    : TextLayout(other), m_Just(Justification::centredLeft), m_Font(15.0f), m_bBalance(false)
{}

TextComp(const String& text)
    : TextLayout(text, Font(15.0f)), m_Just(Justification::centredLeft), m_Font(15.0f), m_bBalance(false)
{}

TextComp(const String& text, const Font& font)
    : TextLayout(text, font), m_Just(Justification::centredLeft), m_Font(font), m_bBalance(false)
{}

~TextComp()
{}

public:
void operator= (const String& newText)
{
setText(newText);
}

void operator+= (const String& textToAppend)
{
    appendText(textToAppend);
}

void appendText(const String& textToAppend)
{
    TextLayout::appendText(textToAppend, m_Font);
}

void setText (const String& newText)
{
    TextLayout::setText(newText, m_Font);
}

void paint(Graphics& g)
{
    layout(getWidth() - 6, m_Just, m_bBalance);
    drawWithin(g, 3, 1, getWidth() - 6, getHeight() - 2, Justification::left);
}

void resized()
{
    repaint();
}

void moved()
{
    repaint();
}

int getWidth() const
{
    return Component::getWidth();
}

int getHeight() const
{
    return Component::getHeight();
}

int getTextWidth() const
{
    return TextLayout::getHeight();
}

int getTextHeight() const
{
    return TextLayout::getWidth();
}

void setJustificationType(const Justification &justification)
{
    m_Just = justification;
}

const Justification getJustificationType() const
{
    return m_Just;
}

void setAttemptToBalance(const bool attemptToBalanceLineLengths)
{
    m_bBalance = attemptToBalanceLineLengths;
}

const bool setAttemptToBalance() const
{
    return m_bBalance;
}

//==============================================================================
// (need to put this in to disambiguate the new/delete operators used in the
// two base classes).
juce_UseDebuggingNewOperator

private:
Font m_Font;
Justification m_Just;
bool m_bBalance;
};[/code]


#2