Changed to use showItemCount for items already added but not to be drawn.
authorclone <ingyou.park@samsung.com>
Thu, 30 May 2013 04:58:48 +0000 (13:58 +0900)
committerclone <ingyou.park@samsung.com>
Tue, 4 Jun 2013 06:40:28 +0000 (15:40 +0900)
Change-Id: I9b5586caa9924dee190f68e8d3c3e04bab6e52a0
Signed-off-by: clone <ingyou.park@samsung.com>
src/ui/controls/FUiCtrl_ContextMenuGridPresenter.cpp
src/ui/inc/FUiCtrl_ContextMenuGridPresenter.h

index 3a362f2..e01f99a 100644 (file)
@@ -40,9 +40,8 @@ using namespace Tizen::Base;
 using namespace Tizen::Base::Runtime;
 using namespace Tizen::Graphics::_Text;
 
-static const int MAX_COUNT_PER_LINE = 5;
-static const int MIN_COUNT_PER_LINE = 3;
 static const int MAX_LINE_COUNT = 32;          // Only for index of array
+static const int MAX_ITEM_COUNT = 35;
 
 namespace Tizen { namespace Ui { namespace Controls
 {
@@ -804,6 +803,7 @@ _ContextMenuGridPresenter::AdjustItemLayout(void)
                return E_SUCCESS;
        }
 
+       // GUI guide word: 5x2
        bool bitmapOnly = IsLayoutBitmapOnly();
 
        if (bitmapOnly == true)
@@ -829,30 +829,37 @@ _ContextMenuGridPresenter::AdjustItemLayoutIconStyle(void)
        int itemCount = __pModel->GetItemCount();
        float itemWidth = __itemWidth + __itemGap;
        float itemHeight = __itemHeight + __itemGap;
+       FloatDimension layoutSize(0.0f, 0.0f);
 
-       if (itemCount <= MAX_COUNT_PER_LINE)
+       if (itemCount > MAX_ITEM_COUNT)
        {
-               countPerLine = itemCount;
-       }
-       else
-       {
-               countPerLine = GetCountPerLine(itemCount, MIN_COUNT_PER_LINE, MAX_COUNT_PER_LINE);
+               SetLastResult(E_MAX_EXCEEDED);
+               return layoutSize;
        }
 
+       countPerLine = GetCountPerLine(itemCount);
+
        int lineCount = itemCount / countPerLine;
        if (itemCount % countPerLine != 0)
        {
                lineCount++;
        }
 
-       FloatDimension layoutSize(0.0f, 0.0f);
-
-       layoutSize.width = countPerLine * __itemWidth + (countPerLine -1) * __itemGap;
-       layoutSize.height = lineCount * __itemHeight + (lineCount - 1) *__itemGap;
+       layoutSize.width = countPerLine * __itemWidth + (countPerLine - 1) * __itemGap;
+       int showLineCount = __pContextMenu->GetShowItemMaxCount();
+       if (lineCount > showLineCount)
+       {
+               SetLastResult(E_MAX_EXCEEDED);
+       }
+       else
+       {
+               showLineCount = lineCount;
+       }
+       layoutSize.height = showLineCount * __itemHeight + (showLineCount - 1) *__itemGap;
 
        _ContextMenuItem* pItem = null;
 
-       for (int line = 0; line < lineCount; line++)
+       for (int line = 0; line < showLineCount; line++)
        {
                float pressedTopMargin = 0.0f, pressedBottomMargin = 0.0f;
                if (line == 0)
@@ -860,7 +867,7 @@ _ContextMenuGridPresenter::AdjustItemLayoutIconStyle(void)
                        pressedTopMargin = __bgPressedMargin;
                }
 
-               if (line == lineCount - 1)
+               if (line == showLineCount - 1)
                {
                        pressedBottomMargin = __bgPressedMargin;
                }
@@ -911,13 +918,11 @@ _ContextMenuGridPresenter::AdjustItemLayoutIconStyle(void)
                        pressedDrawRect.width  -= pressedLeftMargin + pressedRightMargin;
                        pressedDrawRect.height -= pressedTopMargin + pressedBottomMargin;
                        pItem->SetPressedDrawRect(pressedDrawRect);
+                       __showItemCount = index;
                }
        }
 
-       if (lineCount > __pContextMenu->GetShowItemMaxCount())
-       {
-               SetLastResult(E_MAX_EXCEEDED);
-       }
+       __showItemCount++;
 
        return layoutSize;
 
@@ -934,7 +939,7 @@ _ContextMenuGridPresenter::AdjustItemLayoutTabStyle(void)
        int itemCount = __pModel->GetItemCount();
        float maxWidth = __itemWidth;
        float itemHeight = __itemHeight + __itemGap;
-       int lineCount = 1;
+       int lineCount = 1, showLineCount = 0;
        float lineWidth = 0.0f;
        int lineItemCount = 0;
        float x = 0.0f;
@@ -1019,18 +1024,27 @@ _ContextMenuGridPresenter::AdjustItemLayoutTabStyle(void)
 
        FloatDimension layoutSize(__itemWidth, __itemHeight);
        layoutSize.width = maxWidth - __itemGap;
-       layoutSize.height = lineCount * __itemHeight + (lineCount - 1) *__itemGap;
+       showLineCount = __pContextMenu->GetShowItemMaxCount();
+       if (lineCount > showLineCount)
+       {
+               SetLastResult(E_MAX_EXCEEDED);
+       }
+       else
+       {
+               showLineCount = lineCount;
+       }
+       layoutSize.height = showLineCount * __itemHeight + (showLineCount - 1) *__itemGap;
 
        // divide margin
        int itemIndex = 0;
-       for (int line = 0; line < lineCount; line++)
+       for (int line = 0; line < showLineCount; line++)
        {
                FloatRectangle drawRect;
                float width = lineWidthList[line];
                int count = lineItemCountList[line];
                float blank = maxWidth - width;
                float addMargin = blank / count;
-               if (_FloatCompareGE(blank, 100.0f) && line == lineCount - 1)
+               if (_FloatCompareGE(blank, 100.0f) && line == showLineCount - 1)
                {
                        addMargin = 0.0f;
                }
@@ -1041,7 +1055,7 @@ _ContextMenuGridPresenter::AdjustItemLayoutTabStyle(void)
                        pressedTopMargin = __bgPressedMargin;
                }
 
-               if (line == lineCount - 1)
+               if (line == showLineCount - 1)
                {
                        pressedBottomMargin = __bgPressedMargin;
                }
@@ -1079,15 +1093,13 @@ _ContextMenuGridPresenter::AdjustItemLayoutTabStyle(void)
                        pressedDrawRect.width  -= pressedLeftMargin + pressedRightMargin;
                        pressedDrawRect.height -= pressedTopMargin + pressedBottomMargin;
                        pItem->SetPressedDrawRect(pressedDrawRect);
+                       __showItemCount = index;
                }
 
                itemIndex += count;
        }
 
-       if (lineCount > __pContextMenu->GetShowItemMaxCount())
-       {
-               SetLastResult(E_MAX_EXCEEDED);
-       }
+       __showItemCount++;
 
        return layoutSize;
 }
@@ -1129,31 +1141,16 @@ _ContextMenuGridPresenter::AdjustItemPosition(void)
 }
 
 int
-_ContextMenuGridPresenter::GetCountPerLine(int count, int min, int max) const
+_ContextMenuGridPresenter::GetCountPerLine(int count) const
 {
-       int minBlank = max;
-       int countPerLine = max;
-
-       for (int i = max; i >= min; i--)
-       {
-               int remainder = count % i;
-
-               if (remainder == 0)
-               {
-                       countPerLine = i;
-                       break;
-               }
-
-               int blank = i - remainder;
-
-               if (blank < minBlank)
-               {
-                       minBlank = blank;
-                       countPerLine = i;
-               }
-       }
-
-       return countPerLine;
+       static const int countOfX[MAX_ITEM_COUNT + 1] = {0,     // not used
+               1,      2,      3,      4,      5,      3,      4,      4,      5,      5,
+               4,      4,      5,      5,      5,      4,      5,      5,      5,      5,
+               5,      5,      5,      5,      5,      5,      5,      5,      5,      5,
+               5,      5,      5,      5,      5,
+       };
+
+       return countOfX[count];
 }
 
 int
@@ -1250,7 +1247,6 @@ _ContextMenuGridPresenter::DrawBackground(Canvas* pCanvas)
        return r;
 }
 
-
 result
 _ContextMenuGridPresenter::DrawArrow(Canvas* pCanvas)
 {
@@ -1284,7 +1280,7 @@ _ContextMenuGridPresenter::DrawItem(Tizen::Graphics::Canvas* pCanvas)
        result r = E_SUCCESS;
        TextSimple* pSimpleText = null;
 
-       int itemCount = __pModel->GetItemCount();
+       int itemCount = __showItemCount;
 
        if (itemCount <= 0)
        {
index ea5f98c..d3eb659 100644 (file)
@@ -101,7 +101,7 @@ private:
        result DrawLine(Tizen::Graphics::Canvas* pCanvas, Tizen::Graphics::FloatPoint point1, Tizen::Graphics::FloatPoint point2, bool drawVLine);
        void SetItemSize(_ContextMenuItem* pItem);
        int GetItemIndexFromPosition(const Tizen::Graphics::FloatPoint& point) const;
-       int GetCountPerLine(int count, int min, int max) const;
+       int GetCountPerLine(int count) const;
 private:
        _ContextMenuGridPresenter(const _ContextMenuGridPresenter& rhs);
        _ContextMenuGridPresenter& operator =(const _ContextMenuGridPresenter& rhs);
@@ -118,6 +118,7 @@ private:
        bool __touchOutRect;
        int __selectedIndex;
        int __pressedIndex;
+       int __showItemCount;
        float __maxWidth;
        float __minWidth;
        float __topMargin;