1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

TableHeaderComponent: Correctly render column headers when graphics context is clipped

This commit is contained in:
reuk 2022-12-01 16:19:17 +00:00
parent 2e16de3501
commit 16b8cbf2b7
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11
2 changed files with 32 additions and 34 deletions

View file

@ -500,6 +500,33 @@ void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*
setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
}
void TableHeaderComponent::drawColumnHeader (Graphics& g, LookAndFeel& lf, const ColumnInfo& ci)
{
// Only paint columns that are visible
if (! ci.isVisible())
return;
// If this column is being dragged, it shouldn't be drawn in the table header
if (ci.id == columnIdBeingDragged && dragOverlayComp != nullptr && dragOverlayComp->isVisible())
return;
// There's no point drawing this column header if no part of it is visible
if (! g.getClipBounds()
.getHorizontalRange()
.intersects (Range<int>::withStartAndLength (ci.getX(), ci.width)))
return;
Graphics::ScopedSaveState ss (g);
g.setOrigin (ci.getX(), ci.getY());
g.reduceClipRegion (0, 0, ci.width, ci.getHeight());
lf.drawTableHeaderColumn (g, *this, ci.getTitle(), ci.id, ci.width, getHeight(),
ci.id == columnIdUnderMouse,
ci.id == columnIdUnderMouse && isMouseButtonDown(),
ci.propertyFlags);
}
void TableHeaderComponent::paint (Graphics& g)
{
auto& lf = getLookAndFeel();
@ -507,48 +534,18 @@ void TableHeaderComponent::paint (Graphics& g)
lf.drawTableHeaderBackground (g, *this);
for (auto* ci : columns)
{
if (ci->isVisible() && ci->getWidth() > 0)
{
Graphics::ScopedSaveState ss (g);
g.setOrigin (ci->getX(), ci->getY());
g.reduceClipRegion (0, 0, ci->getWidth(), ci->getHeight());
lf.drawTableHeaderColumn (g, *this, ci->getTitle(), ci->id, ci->width, getHeight(),
ci->id == columnIdUnderMouse,
ci->id == columnIdUnderMouse && isMouseButtonDown(),
ci->propertyFlags);
}
}
drawColumnHeader (g, lf, *ci);
}
void TableHeaderComponent::resized()
{
auto clip = getBounds();
int x = 0;
for (auto* ci : columns)
ci->setBounds (0, 0, 0, 0);
for (auto* ci : columns)
{
if (ci->isVisible())
{
if (x + ci->width > clip.getX()
&& (ci->id != columnIdBeingDragged
|| dragOverlayComp == nullptr
|| ! dragOverlayComp->isVisible()))
{
ci->setBounds (x, 0, ci->width, getHeight());
}
x += ci->width;
if (x >= clip.getRight())
break;
}
const auto widthToUse = ci->isVisible() ? ci->width : 0;
ci->setBounds (x, 0, widthToUse, getHeight());
x += widthToUse;
}
}