float textBottomMargin = 0.0f;
_ControlOrientation orientation = GetOrientation();
- GET_SHAPE_CONFIG(EDIT::AREA_LEFT_MARGIN, orientation, leftMargin);
- GET_SHAPE_CONFIG(EDIT::AREA_RIGHT_MARGIN, orientation, rightMargin);
GET_SHAPE_CONFIG(EDIT::AREA_TEXT_LEFT_MARGIN, orientation, textLeftMargin);
GET_SHAPE_CONFIG(EDIT::AREA_TEXT_RIGHT_MARGIN, orientation, textRightMargin);
GET_SHAPE_CONFIG(EDIT::AREA_TEXT_TOP_MARGIN, orientation, textTopMargin);
FloatRectangle previousRect = pTextObject->GetBoundsF();
FloatRectangle newRect = previousRect;
- if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
+ bool fitToHorizontal = horizontalMode;
+ bool fitToVertical = verticalMode;
+
+ if (fitToHorizontal)
{
- newRect.height = _ControlManager::GetInstance()->GetScreenSizeF().height;
+ if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
+ {
+ newRect.width = _ControlManager::GetInstance()->GetScreenSizeF().width;
+ }
+ else
+ {
+ newRect.width = _ControlManager::GetInstance()->GetScreenSizeF().height;
+ }
+ newRect.width -= (GetBoundsF().x + textLeftMargin + textRightMargin);
}
- else
+ if (fitToVertical)
{
- newRect.height = _ControlManager::GetInstance()->GetScreenSizeF().width;
+ if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
+ {
+ newRect.height = _ControlManager::GetInstance()->GetScreenSizeF().height;
+ }
+ else
+ {
+ newRect.height = _ControlManager::GetInstance()->GetScreenSizeF().width;
+ }
+ newRect.height -= (GetBoundsF().y + textTopMargin + textBottomMargin);
}
- newRect.height -= (GetBoundsF().y + textTopMargin + textBottomMargin);
pTextObject->SetBounds(newRect);
pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
pTextObject->Compose();
- float height = pTextObject->GetTotalHeightF();
- if (height < newRect.height)
+ if (fitToHorizontal && fitToVertical)
{
- dimension.height = height;
+ dimension = pTextObject->GetTextExtentF(0, pTextObject->GetTextLength());
+ if (dimension.width > newRect.width)
+ {
+ dimension.width = newRect.width;
+ }
+ float height = pTextObject->GetTotalHeightF();
+ if (height <= newRect.height)
+ {
+ dimension.height = height;
+ }
+ else
+ {
+ dimension.height = newRect.height;
+ }
}
- else
+ else if (fitToHorizontal)
+ {
+ dimension = pTextObject->GetTextExtentF(0, pTextObject->GetTextLength());
+ if (dimension.width > newRect.width)
+ {
+ dimension.width = newRect.width;
+ }
+ dimension.height = GetBoundsF().height;
+ }
+ else if (fitToVertical)
{
- dimension.height = newRect.height;
+ float height = pTextObject->GetTotalHeightF();
+ if (height <= newRect.height)
+ {
+ dimension.height = height;
+ }
+ else
+ {
+ dimension.height = newRect.height;
+ }
+ dimension.width = GetBoundsF().width;
}
- dimension.width = newRect.width;
// restore
pTextObject->SetBounds(previousRect);
pTextObject->SetWrap(previousWrapType);
pTextObject->Compose();
- dimension.height += textTopMargin + textBottomMargin;
+ if (fitToHorizontal)
+ {
+ dimension.width += textLeftMargin + textRightMargin;
+ }
+ if (fitToVertical)
+ {
+ dimension.height += textTopMargin + textBottomMargin;
+ }
return dimension;
}