1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-20 01:14:20 +00:00

Added colour ids to modify the colours of the TableHeaderComponent

This commit is contained in:
hogliux 2017-08-16 12:35:27 +01:00
parent afada01e41
commit e65708eb4c
5 changed files with 49 additions and 15 deletions

View file

@ -173,6 +173,11 @@ LookAndFeel_V2::LookAndFeel_V2()
BubbleComponent::backgroundColourId, 0xeeeeeebb,
BubbleComponent::outlineColourId, 0x77000000,
TableHeaderComponent::textColourId, 0xff000000,
TableHeaderComponent::backgroundColourId, 0xffe8ebf9,
TableHeaderComponent::outlineColourId, 0x33000000,
TableHeaderComponent::highlightColourId, 0x8899aadd,
DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
DirectoryContentsDisplayComponent::textColourId, 0xff000000,
@ -2323,26 +2328,33 @@ void LookAndFeel_V2::drawTableHeaderBackground (Graphics& g, TableHeaderComponen
Rectangle<int> area (header.getLocalBounds());
area.removeFromTop (area.getHeight() / 2);
g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, (float) area.getY(),
Colour (0xfff6f8f9), 0.0f, (float) area.getBottom(),
auto backgroundColour = header.findColour (TableHeaderComponent::backgroundColourId);
g.setGradientFill (ColourGradient (backgroundColour,
0.0f, (float) area.getY(),
backgroundColour.withMultipliedSaturation (.5f),
0.0f, (float) area.getBottom(),
false));
g.fillRect (area);
g.setColour (Colour (0x33000000));
g.setColour (header.findColour (TableHeaderComponent::outlineColourId));
g.fillRect (area.removeFromBottom (1));
for (int i = header.getNumColumns (true); --i >= 0;)
g.fillRect (header.getColumnPosition (i).removeFromRight (1));
}
void LookAndFeel_V2::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
void LookAndFeel_V2::drawTableHeaderColumn (Graphics& g, TableHeaderComponent& header,
const String& columnName, int /*columnId*/,
int width, int height, bool isMouseOver, bool isMouseDown,
int columnFlags)
{
auto highlightColour = header.findColour (TableHeaderComponent::highlightColourId);
if (isMouseDown)
g.fillAll (Colour (0x8899aadd));
g.fillAll (highlightColour);
else if (isMouseOver)
g.fillAll (Colour (0x5599aadd));
g.fillAll (highlightColour.withMultipliedAlpha (0.625f));
Rectangle<int> area (width, height);
area.reduce (4, 0);
@ -2358,7 +2370,7 @@ void LookAndFeel_V2::drawTableHeaderColumn (Graphics& g, const String& columnNam
g.fillPath (sortArrow, sortArrow.getTransformToScaleToFit (area.removeFromRight (height / 2).reduced (2).toFloat(), true));
}
g.setColour (Colours::black);
g.setColour (header.findColour (TableHeaderComponent::textColourId));
g.setFont (Font (height * 0.5f, Font::bold));
g.drawFittedText (columnName, area, Justification::centredLeft, 1);
}

View file

@ -291,9 +291,9 @@ public:
//==============================================================================
void drawTableHeaderBackground (Graphics&, TableHeaderComponent&) override;
void drawTableHeaderColumn (Graphics&, const String& columnName, int columnId,
int width, int height, bool isMouseOver, bool isMouseDown,
int columnFlags) override;
void drawTableHeaderColumn (Graphics&, TableHeaderComponent&, const String& columnName,
int columnId, int width, int height, bool isMouseOver,
bool isMouseDown, int columnFlags) override;
//==============================================================================
void paintToolbarBackground (Graphics&, int width, int height, Toolbar&) override;

View file

@ -39,6 +39,8 @@ LookAndFeel_V3::LookAndFeel_V3()
setColour (Slider::thumbColourId, Colour (0xffddddff));
setColour (BubbleComponent::backgroundColourId, Colour (0xeeeeeedd));
setColour (ScrollBar::thumbColourId, Colour::greyLevel (0.8f).contrasting().withAlpha (0.13f));
setColour (TableHeaderComponent::backgroundColourId, Colours::white.withAlpha (0.6f));
setColour (TableHeaderComponent::outlineColourId, Colours::black.withAlpha (0.5f));
}
LookAndFeel_V3::~LookAndFeel_V3() {}
@ -153,14 +155,15 @@ void LookAndFeel_V3::drawButtonBackground (Graphics& g, Button& button, const Co
void LookAndFeel_V3::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
{
Rectangle<int> r (header.getLocalBounds());
auto outlineColour = header.findColour (TableHeaderComponent::outlineColourId);
g.setColour (Colours::black.withAlpha (0.5f));
g.setColour (outlineColour);
g.fillRect (r.removeFromBottom (1));
g.setColour (Colours::white.withAlpha (0.6f));
g.setColour (header.findColour (TableHeaderComponent::backgroundColourId));
g.fillRect (r);
g.setColour (Colours::black.withAlpha (0.5f));
g.setColour (outlineColour);
for (int i = header.getNumColumns (true); --i >= 0;)
g.fillRect (header.getColumnPosition (i).removeFromRight (1));

View file

@ -537,7 +537,7 @@ void TableHeaderComponent::paint (Graphics& g)
g.setOrigin (x, 0);
g.reduceClipRegion (0, 0, ci->width, getHeight());
lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
lf.drawTableHeaderColumn (g, *this, ci->name, ci->id, ci->width, getHeight(),
ci->id == columnIdUnderMouse,
ci->id == columnIdUnderMouse && isMouseButtonDown(),
ci->propertyFlags);

View file

@ -366,6 +366,24 @@ public:
*/
virtual void reactToMenuItem (int menuReturnId, int columnIdClicked);
//==============================================================================
/** A set of colour IDs to use to change the colour of various aspects of the TableHeaderComponent.
@see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
*/
enum ColourIds
{
textColourId = 0x1003800, /**< The colour for the text in the header. */
backgroundColourId = 0x1003810, /**< The colour of the table header background.
It's up to the LookAndFeel how this is used. */
outlineColourId = 0x1003820, /**< The colour of the table header's outline. */
highlightColourId = 0x1003830, /**< The colour of the table header background when
the mouse is over or down above the the table
header. It's up to the LookAndFeel to use a
variant of this colour to destiuish between
the down and hover state. */
};
//==============================================================================
/** This abstract base class is implemented by LookAndFeel classes. */
struct JUCE_API LookAndFeelMethods
@ -374,7 +392,8 @@ public:
virtual void drawTableHeaderBackground (Graphics&, TableHeaderComponent&) = 0;
virtual void drawTableHeaderColumn (Graphics&, const String& columnName, int columnId,
virtual void drawTableHeaderColumn (Graphics&, TableHeaderComponent&,
const String& columnName, int columnId,
int width, int height,
bool isMouseOver, bool isMouseDown, int columnFlags) = 0;
};