Button Resizing in SB
authorAyush <ayush.sriv@samsung.com>
Sat, 16 Mar 2013 04:34:24 +0000 (10:04 +0530)
committerSyed Khaja Moinuddin <moinuddin.s@samsung.com>
Sat, 16 Mar 2013 07:27:35 +0000 (16:27 +0900)
Change-Id: I5a4742d5ff34798ca0103a5ac78ccca63bee79f4
Signed-off-by: Ayush <ayush.sriv@samsung.com>
Signed-off-by: Syed Khaja Moinuddin <moinuddin.s@samsung.com>
src/ui/controls/FUiCtrl_SearchBar.cpp
src/ui/controls/FUiCtrl_SearchBarPresenter.cpp
src/ui/inc/FUiCtrl_SearchBar.h

index 30b0232..46c1cb3 100644 (file)
@@ -2521,6 +2521,85 @@ _SearchBar::ResizeCancelButton(void)
 
 }
 
+void
+_SearchBar::RecalculateButtonBounds(void)
+{
+       result r = E_SUCCESS;
+
+       Float horizontalMargin = 0;
+       Float verticalMargin = 0;
+       Float buttonLeftMargin = 0;
+       Float buttonRightMargin = 0;
+       Float buttonMinWidth = 0;
+       Float searchFieldMinWidth = 0;
+       Float buttonVerticalMargin = 0;
+       Float searchBarMinHeight = 0;
+       Float buttonWidth = 0;
+       Float buttonHeight = 0;
+
+       FloatRectangle cancelButtonBounds;
+       FloatRectangle searchBarBounds = GetBoundsF();
+
+       _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
+
+       GET_SHAPE_CONFIG(SEARCHBAR::HORIZONTAL_MARGIN, orientation, horizontalMargin);
+       GET_SHAPE_CONFIG(SEARCHBAR::VERTICAL_MARGIN, orientation, verticalMargin);
+       GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_LEFT_MARGIN, orientation, buttonLeftMargin);
+       GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_RIGHT_MARGIN, orientation, buttonRightMargin);
+       GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
+       GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_HEIGHT, orientation, buttonHeight);
+       GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_MIN_WIDTH, orientation, buttonMinWidth);
+       GET_SHAPE_CONFIG(SEARCHBAR::SEARCH_FIELD_MIN_WIDTH, orientation, searchFieldMinWidth);
+       GET_SHAPE_CONFIG(SEARCHBAR::VERTICAL_MARGIN, orientation, buttonVerticalMargin);
+       GET_SHAPE_CONFIG(SEARCHBAR::MIN_HEIGHT, orientation, searchBarMinHeight);
+
+       cancelButtonBounds.height = buttonHeight        ;
+
+       FloatRectangle editBounds;
+
+       float cancelButtonWidth = 0;
+       cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
+       editBounds.x = horizontalMargin;
+       editBounds.y = verticalMargin;
+
+       editBounds.height = searchBarBounds.height - (editBounds.y * 2.0f);
+       editBounds.height = (editBounds.height > searchBarMinHeight) ? editBounds.height : searchBarMinHeight;
+
+       editBounds.width = searchBarBounds.width - cancelButtonWidth - (2 * horizontalMargin) - buttonLeftMargin;
+
+       if (editBounds.width < searchFieldMinWidth)
+       {
+               editBounds.width = searchFieldMinWidth;
+       }
+
+       cancelButtonBounds.x = editBounds.width + horizontalMargin + buttonLeftMargin;
+       cancelButtonBounds.y = (searchBarBounds.height - cancelButtonBounds.height)/2.0f;
+
+       if (searchBarBounds.height < searchBarMinHeight)
+       {
+               cancelButtonBounds.y = buttonVerticalMargin;
+       }
+
+       if (cancelButtonWidth < buttonMinWidth)
+       {
+               cancelButtonBounds.width = buttonMinWidth;
+       }
+       else
+       {
+               cancelButtonBounds.width = searchBarBounds.width - cancelButtonBounds.x - buttonRightMargin;
+       }
+
+       cancelButtonBounds.width = (cancelButtonBounds.width > 0.0f) ? cancelButtonBounds.width : 0.0f;
+       cancelButtonBounds.height = (cancelButtonBounds.height > 0.0f) ? cancelButtonBounds.height : 0.0f;
+
+       r = __pCancelButton->SetBounds(cancelButtonBounds);
+       SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+       r = __pEdit->SetBounds(editBounds);
+       SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       return;
+}
+
 SearchFieldStatus
 _SearchBar::GetCurrentStatus(void)
 {
index 6d17d86..aa2bfe1 100644 (file)
@@ -469,7 +469,19 @@ _SearchBarPresenter::ChangeMode(SearchBarMode mode)
                if (__pEdit)
                {
                        __pEdit->SetCursorDisabled(false);
-                       __pEdit->SetBounds(__searchFieldBounds);
+
+                       float buttonWidth = 0;
+                       _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
+                       GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
+
+                       float cancelButtonWidth = 0.0f;
+                       cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
+
+                       if (cancelButtonWidth <= buttonWidth)
+                       {
+                               __pEdit->SetBounds(__searchFieldBounds);
+                       }
+
                        __pEdit->ShowKeypad();
                }
                __pSearchBar->SetContentsArea();
@@ -523,6 +535,15 @@ _SearchBarPresenter::InitializeInputModeLayout(void)
 
        __searchFieldBounds.width = (__pSearchBar->GetBoundsF().width > searchFieldMinWidth) ? __searchFieldBounds.width : searchFieldMinWidth;
 
+       float cancelButtonWidth = 0.0f;
+       cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
+
+
+       if (cancelButtonWidth > buttonWidth)
+       {
+               __pSearchBar->RecalculateButtonBounds();
+       }
+
        return;
 }
 
@@ -583,6 +604,19 @@ _SearchBarPresenter::OnBoundsChanged(void)
        r = __pEdit->SetBounds(__searchFieldBounds);
        SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.",GetErrorMessage(r));
 
+       if (GetMode() == SEARCH_BAR_MODE_INPUT)
+       {
+               float buttonWidth = 0;
+               _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
+               GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
+               float cancelButtonWidth = 0.0f;
+               cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
+               if (cancelButtonWidth > buttonWidth)
+               {
+                       __pSearchBar->RecalculateButtonBounds();
+               }
+       }
+
        __pSearchBar->SetContentsArea();
 
        return;
index 508b242..c50cc81 100644 (file)
@@ -226,6 +226,7 @@ public:
        void SetContentDimming(void);
        bool IsContentAttachable(const _Control* pContent);
        result ResizeCancelButton(void);
+       void RecalculateButtonBounds(void);
        SearchFieldStatus GetCurrentStatus(void);
        void  SetEditTextFilter(IEditTextFilter* pFilter);
        void SendOpaqueCommand (const Tizen::Base::String& command);