void Controller::Relayouter::CalculateVerticalOffset(Controller& controller, const Size& controlSize)
{
- Controller::Impl& impl = *controller.mImpl;
- ModelPtr& model = impl.mModel;
- Size layoutSize = model->mVisualModel->GetLayoutSize();
+ Controller::Impl& impl = *controller.mImpl;
+ ModelPtr& model = impl.mModel;
+ VisualModelPtr& visualModel = model->mVisualModel;
+ Size layoutSize = model->mVisualModel->GetLayoutSize();
+ Size oldLayoutSize = layoutSize;
+ float offsetY = 0.f;
+ bool needRecalc = false;
+ float defaultFontLineHeight = impl.GetDefaultFontLineHeight();
if(fabsf(layoutSize.height) < Math::MACHINE_EPSILON_1000)
{
// Get the line height of the default font.
- layoutSize.height = impl.GetDefaultFontLineHeight();
+ layoutSize.height = defaultFontLineHeight;
+ }
+
+ if (layoutSize.height != defaultFontLineHeight)
+ {
+ // This code prevents the wrong positioning of cursor when the layout size is bigger/smaller than defaultFontLineHeight.
+ // This situation occurs when the size of placeholder text is different from the default text.
+ layoutSize.height = defaultFontLineHeight;
+ needRecalc = true;
}
switch(model->mVerticalAlignment)
case VerticalAlignment::TOP:
{
model->mScrollPosition.y = 0.f;
+ offsetY = 0.f;
break;
}
case VerticalAlignment::CENTER:
{
model->mScrollPosition.y = floorf(0.5f * (controlSize.height - layoutSize.height)); // try to avoid pixel alignment.
+ if (needRecalc) offsetY = floorf(0.5f * (layoutSize.height - oldLayoutSize.height));
break;
}
case VerticalAlignment::BOTTOM:
{
model->mScrollPosition.y = controlSize.height - layoutSize.height;
+ if (needRecalc) offsetY = layoutSize.height - oldLayoutSize.height;
break;
}
}
+
+ if (needRecalc)
+ {
+ // Update glyphPositions according to recalculation.
+ const Length positionCount = visualModel->mGlyphPositions.Count();
+ Vector<Vector2>& glyphPositions = visualModel->mGlyphPositions;
+ for(Length index = 0u; index < positionCount; index++)
+ {
+ glyphPositions[index].y += offsetY;
+ }
+ }
+
}
} // namespace Text