fixed bug (fit to Content)
authorChulheon <ch.jeong47@samsung.com>
Mon, 20 May 2013 10:47:04 +0000 (19:47 +0900)
committerChulheon <ch.jeong47@samsung.com>
Mon, 20 May 2013 10:47:04 +0000 (19:47 +0900)
Change-Id: I5c4a7100e5fb30a6740d81c8c74606b23aefa36f

src/ui/controls/FUiCtrl_Edit.cpp

index 766cd0a..c5cb1bf 100644 (file)
@@ -577,8 +577,6 @@ _Edit::GetContentSizeInternalF(bool horizontalMode, bool verticalMode) const
        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);
@@ -597,31 +595,78 @@ _Edit::GetContentSizeInternalF(bool horizontalMode, bool verticalMode) const
        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);
@@ -629,7 +674,14 @@ _Edit::GetContentSizeInternalF(bool horizontalMode, bool verticalMode) const
        pTextObject->SetWrap(previousWrapType);
        pTextObject->Compose();
 
-       dimension.height += textTopMargin + textBottomMargin;
+       if (fitToHorizontal)
+       {
+               dimension.width += textLeftMargin + textRightMargin;
+       }
+       if (fitToVertical)
+       {
+               dimension.height += textTopMargin + textBottomMargin;
+       }
 
        return  dimension;
 }