position of tick labels fixed
This commit is contained in:
parent
7ed3841166
commit
d59d31ceff
|
@ -118,7 +118,7 @@ QSGNode* QskScaleRenderer::updateScaleNode(
|
||||||
|
|
||||||
if ( !labelsRect.isEmpty() )
|
if ( !labelsRect.isEmpty() )
|
||||||
{
|
{
|
||||||
newNode = updateLabelsNode( skinnable, labelsRect, oldNode );
|
newNode = updateLabelsNode( skinnable, tickmarksRect, labelsRect, oldNode );
|
||||||
if ( newNode )
|
if ( newNode )
|
||||||
QskSGNode::setNodeRole( newNode, Labels );
|
QskSGNode::setNodeRole( newNode, Labels );
|
||||||
}
|
}
|
||||||
|
@ -147,9 +147,10 @@ QSGNode* QskScaleRenderer::updateTicksNode(
|
||||||
}
|
}
|
||||||
|
|
||||||
QSGNode* QskScaleRenderer::updateLabelsNode(
|
QSGNode* QskScaleRenderer::updateLabelsNode(
|
||||||
const QskSkinnable* skinnable, const QRectF& rect, QSGNode* node ) const
|
const QskSkinnable* skinnable, const QRectF& tickmarksRect,
|
||||||
|
const QRectF& labelsRect, QSGNode* node ) const
|
||||||
{
|
{
|
||||||
if ( rect.isEmpty() )
|
if ( labelsRect.isEmpty() || tickmarksRect.isEmpty() )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
const auto ticks = m_tickmarks.majorTicks();
|
const auto ticks = m_tickmarks.majorTicks();
|
||||||
|
@ -161,7 +162,8 @@ QSGNode* QskScaleRenderer::updateLabelsNode(
|
||||||
|
|
||||||
const QFontMetricsF fm( m_font );
|
const QFontMetricsF fm( m_font );
|
||||||
|
|
||||||
const qreal length = ( m_orientation == Qt::Horizontal ) ? rect.width() : rect.height();
|
const qreal length = ( m_orientation == Qt::Horizontal )
|
||||||
|
? tickmarksRect.width() : tickmarksRect.height();
|
||||||
const qreal ratio = length / m_boundaries.width();
|
const qreal ratio = length / m_boundaries.width();
|
||||||
|
|
||||||
auto nextNode = node->firstChild();
|
auto nextNode = node->firstChild();
|
||||||
|
@ -193,10 +195,10 @@ QSGNode* QskScaleRenderer::updateLabelsNode(
|
||||||
{
|
{
|
||||||
const auto w = qskHorizontalAdvance( fm, text );
|
const auto w = qskHorizontalAdvance( fm, text );
|
||||||
|
|
||||||
auto pos = tickPos - 0.5 * w;
|
auto pos = tickmarksRect.x() + tickPos - 0.5 * w;
|
||||||
pos = qBound( 0.0, pos, rect.width() - w );
|
pos = qBound( labelsRect.left(), pos, labelsRect.right() - w );
|
||||||
|
|
||||||
r = QRectF( rect.x() + pos, rect.y(), w, rect.height() );
|
r = QRectF( pos, labelsRect.y(), w, labelsRect.height() );
|
||||||
|
|
||||||
alignment = Qt::AlignLeft;
|
alignment = Qt::AlignLeft;
|
||||||
}
|
}
|
||||||
|
@ -204,18 +206,18 @@ QSGNode* QskScaleRenderer::updateLabelsNode(
|
||||||
{
|
{
|
||||||
const auto h = fm.height();
|
const auto h = fm.height();
|
||||||
|
|
||||||
|
auto pos = tickmarksRect.bottom() - ( tickPos + 0.5 * h );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
when clipping the label we can expand the clip rectangle
|
when clipping the label we can expand the clip rectangle
|
||||||
by the ascent/descent margins, as nothing gets painted there
|
by the ascent/descent margins, as nothing gets painted there
|
||||||
anyway.
|
anyway.
|
||||||
*/
|
*/
|
||||||
const qreal distTop = h - fm.ascent();
|
const qreal min = labelsRect.top() - ( h - fm.ascent() );
|
||||||
const qreal distBottom = fm.descent();
|
const qreal max = labelsRect.bottom() + fm.descent();
|
||||||
|
pos = qBound( min, pos, max );
|
||||||
|
|
||||||
auto pos = rect.height() - ( tickPos + 0.5 * h );
|
r = QRectF( labelsRect.x(), pos, labelsRect.width(), h );
|
||||||
pos = qBound( -distTop, pos, rect.height() - h + distBottom );
|
|
||||||
|
|
||||||
r = QRectF( rect.x(), rect.y() + pos, rect.width(), rect.height() );
|
|
||||||
|
|
||||||
alignment = Qt::AlignRight;
|
alignment = Qt::AlignRight;
|
||||||
}
|
}
|
||||||
|
@ -253,18 +255,18 @@ QSGNode* QskScaleRenderer::updateLabelsNode(
|
||||||
|
|
||||||
if( m_orientation == Qt::Horizontal )
|
if( m_orientation == Qt::Horizontal )
|
||||||
{
|
{
|
||||||
auto pos = tickPos - 0.5 * w;
|
auto pos = tickmarksRect.x() + tickPos - 0.5 * w;
|
||||||
pos = qBound( 0.0, pos, rect.width() - w );
|
pos = qBound( labelsRect.left(), pos, labelsRect.right() - w );
|
||||||
|
|
||||||
r = QRectF( rect.x() + pos, rect.y(), w, h );
|
r = QRectF( pos, labelsRect.y(), w, h );
|
||||||
alignment = Qt::AlignHCenter | Qt::AlignBottom;
|
alignment = Qt::AlignHCenter | Qt::AlignBottom;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto pos = rect.height() - ( tickPos + 0.5 * h );
|
auto pos = tickmarksRect.bottom() - ( tickPos + 0.5 * h );
|
||||||
pos = qBound( 0.0, pos, rect.height() - h );
|
pos = qBound( labelsRect.top(), pos, labelsRect.bottom() - h );
|
||||||
|
|
||||||
r = QRectF( rect.right() - w, rect.y() + pos, w, h );
|
r = QRectF( labelsRect.right() - w, pos, w, h );
|
||||||
alignment = Qt::AlignRight | Qt::AlignVCenter;
|
alignment = Qt::AlignRight | Qt::AlignVCenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,8 @@ class QSK_EXPORT QskScaleRenderer
|
||||||
const QskSkinnable*, const QRectF&, QSGNode* ) const;
|
const QskSkinnable*, const QRectF&, QSGNode* ) const;
|
||||||
|
|
||||||
virtual QSGNode* updateLabelsNode(
|
virtual QSGNode* updateLabelsNode(
|
||||||
const QskSkinnable*, const QRectF&, QSGNode* node ) const;
|
const QskSkinnable*, const QRectF& ticksRect,
|
||||||
|
const QRectF& labelsRect, QSGNode* node ) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Qt::Orientation m_orientation = Qt::Horizontal;
|
Qt::Orientation m_orientation = Qt::Horizontal;
|
||||||
|
|
Loading…
Reference in New Issue