Added IGNORE_SPACES_AFTER_TEXT property 75/186675/7
authorminho.sun <minho.sun@samsung.com>
Mon, 13 Aug 2018 09:52:28 +0000 (18:52 +0900)
committerminho.sun <minho.sun@samsung.com>
Mon, 27 Aug 2018 01:59:25 +0000 (10:59 +0900)
Currently, DALi doesn't make text to ellipsis when there are spaces
after text.

 "AAA                            " can't be ellipsis.
 "AAA                           A" can be ellipsis.

User wants to choose whether ignoring spaces after text or not.
So, added devel text property for this which is named IGNORE_SPACES_AFTER_TEXT.

Change-Id: Ibad9f70b1f8012dc4e04914e4f98072fc8741ad9
Signed-off-by: minho.sun <minho.sun@samsung.com>
12 files changed:
automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.cpp
automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp
automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp
dali-toolkit/devel-api/controls/text-controls/text-label-devel.h
dali-toolkit/internal/controls/text-controls/text-label-impl.cpp
dali-toolkit/internal/text/layouts/layout-engine.cpp
dali-toolkit/internal/text/layouts/layout-parameters.h
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h
dali-toolkit/internal/text/text-model.cpp
dali-toolkit/internal/text/text-model.h
dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json

index b977ec3..24ff3f7 100755 (executable)
@@ -284,7 +284,8 @@ void CreateTextModel( const std::string& text,
                                        numberOfGlyphs,
                                        Text::HorizontalAlignment::BEGIN,
                                        Text::LineWrap::WORD,
-                                       outlineWidth );
+                                       outlineWidth,
+                                       true );
 
   Vector<LineRun>& lines = visualModel->mLines;
 
index 86edead..dfe1397 100644 (file)
@@ -172,7 +172,8 @@ bool LayoutTextTest( const LayoutTextData& data )
                                        totalNumberOfGlyphs,
                                        Text::HorizontalAlignment::BEGIN,
                                        Text::LineWrap::WORD,
-                                       outlineWidth );
+                                       outlineWidth,
+                                       true );
 
   layoutParameters.isLastNewParagraph = isLastNewParagraph;
 
@@ -390,7 +391,8 @@ bool ReLayoutRightToLeftLinesTest( const ReLayoutRightToLeftLinesData& data )
                                        visualModel->mGlyphs.Count(),
                                        Text::HorizontalAlignment::BEGIN,
                                        Text::LineWrap::WORD,
-                                       outlineWidth );
+                                       outlineWidth,
+                                       true );
 
   layoutParameters.numberOfBidirectionalInfoRuns = logicalModel->mBidirectionalLineInfo.Count();
   layoutParameters.lineBidirectionalInfoRunsBuffer = logicalModel->mBidirectionalLineInfo.Begin();
index b134179..f19cb12 100644 (file)
@@ -1047,6 +1047,21 @@ int UtcDaliToolkitTextlabelEllipsis(void)
     tet_result(TET_FAIL);
   }
 
+  label.SetProperty( TextLabel::Property::TEXT, "Hello world                                        " );
+  label.SetProperty( DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT, false );
+  label.SetSize( 400.0f, 10.f );
+
+  try
+  {
+    // Render the text.
+    application.SendNotification();
+    application.Render();
+  }
+  catch( ... )
+  {
+    tet_result(TET_FAIL);
+  }
+
   END_TEST;
 }
 
index 939c08d..0b16273 100644 (file)
@@ -94,6 +94,13 @@ namespace Property
      * | color                | VECTOR4  | No       | The color of the background (the default value is Color::CYAN)                                                     |
      */
     BACKGROUND,
+
+    /**
+     * @brief Ignore spaces after text.
+     * @details Name "ignoreSpacesAfterText", type (Property::BOLEAN), Read/Write
+     * @note The default value is true
+     */
+    IGNORE_SPACES_AFTER_TEXT,
   };
 
 } // namespace Property
index 7c6ef25..bb40d00 100644 (file)
@@ -131,6 +131,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "lineWrapMode",
 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "textDirection",       INTEGER, TEXT_DIRECTION             )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "verticalLineAlignment",     INTEGER, VERTICAL_LINE_ALIGNMENT    )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "textBackground",            MAP,     BACKGROUND                 )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "ignoreSpacesAfterText",     BOOLEAN, IGNORE_SPACES_AFTER_TEXT   )
 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor",      Color::BLACK,     TEXT_COLOR     )
 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorRed",   TEXT_COLOR_RED,   TEXT_COLOR, 0  )
 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1  )
@@ -533,6 +534,11 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr
         }
         break;
       }
+      case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
+      {
+        impl.mController->SetIgnoreSpacesAfterText(value.Get< bool >());
+        break;
+      }
     }
 
     // Request relayout when text update is needed. It's necessary to call it
@@ -831,6 +837,11 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde
         GetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
         break;
       }
+      case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
+      {
+        value = impl.mController->IsIgnoreSpacesAfterText();
+        break;
+      }
     }
   }
 
index af257ff..4f9a47c 100644 (file)
@@ -397,11 +397,19 @@ struct Engine::Impl
         tmpLineLayout.wsLengthEndOfLine = 0.f;
       }
 
+      // If calculation is end but wsLengthEndOfLine is exist, it means end of text is space.
+      // Merge remained length.
+      if ( !parameters.ignoreSpaceAfterText && glyphIndex == lastGlyphOfParagraphPlusOne-1 && tmpLineLayout.wsLengthEndOfLine > 0 )
+      {
+        tmpLineLayout.length += tmpLineLayout.wsLengthEndOfLine;
+        tmpLineLayout.wsLengthEndOfLine = 0u;
+      }
+
       // Save the current extra width to compare with the next one
       mPreviousCharacterExtraWidth = tmpExtraWidth;
 
       // Check if the accumulated length fits in the width of the box.
-      if( ( completelyFill || isMultiline ) && !isWhiteSpace &&
+      if( ( completelyFill || isMultiline )  && !(parameters.ignoreSpaceAfterText && isWhiteSpace) &&
           ( tmpExtraBearing + lineLayout.length + lineLayout.wsLengthEndOfLine + tmpLineLayout.length + tmpExtraWidth > parameters.boundingBox.width ) )
       {
         // Current word does not fit in the box's width.
index 7f3e169..5a77d86 100644 (file)
@@ -74,7 +74,8 @@ struct Parameters
               Length totalNumberOfGlyphs,
               Text::HorizontalAlignment::Type horizontalAlignment,
               Text::LineWrap::Mode lineWrapMode,
-              float outlineWidth )
+              float outlineWidth,
+              bool ignoreSpaceAfterText )
   : boundingBox( boundingBox ),
     textBuffer( textBuffer ),
     lineBreakInfoBuffer( lineBreakInfoBuffer ),
@@ -94,8 +95,9 @@ struct Parameters
     startLineIndex( 0u ),
     estimatedNumberOfLines( 0u ),
     lineWrapMode( lineWrapMode ),
+    outlineWidth( outlineWidth ),
     isLastNewParagraph( false ),
-    outlineWidth( outlineWidth )
+    ignoreSpaceAfterText( ignoreSpaceAfterText )
   {}
 
   Vector2                         boundingBox;                     ///< The size of the box containing the text.
@@ -117,8 +119,9 @@ struct Parameters
   LineIndex                       startLineIndex;                  ///< The line index where to insert the new lines.
   Length                          estimatedNumberOfLines;          ///< The estimated number of lines.
   Text::LineWrap::Mode            lineWrapMode;                    ///< The line wrap mode for moving to next line.
-  bool                            isLastNewParagraph;              ///< Whether the last character is a new paragraph character.
   float                           outlineWidth;                    ///< The outline width.
+  bool                            isLastNewParagraph:1;            ///< Whether the last character is a new paragraph character.
+  bool                            ignoreSpaceAfterText:1;          ///< Whether ignoring spaces after text or not. Default is true.
 };
 
 } // namespace Layout
index 4ce4b5a..227760f 100755 (executable)
@@ -407,6 +407,16 @@ VerticalAlignment::Type Controller::GetVerticalAlignment() const
   return mImpl->mModel->mVerticalAlignment;
 }
 
+bool Controller::IsIgnoreSpacesAfterText() const
+{
+  return mImpl->mModel->mIgnoreSpacesAfterText;
+}
+
+void Controller::SetIgnoreSpacesAfterText( bool ignore )
+{
+  mImpl->mModel->mIgnoreSpacesAfterText = ignore;
+}
+
 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
 {
   if( lineWrapMode != mImpl->mModel->mLineWrapMode )
@@ -3533,7 +3543,8 @@ bool Controller::DoRelayout( const Size& size,
                                          totalNumberOfGlyphs,
                                          mImpl->mModel->mHorizontalAlignment,
                                          mImpl->mModel->mLineWrapMode,
-                                         outlineWidth );
+                                         outlineWidth,
+                                         mImpl->mModel->mIgnoreSpacesAfterText );
 
     // Resize the vector of positions to have the same size than the vector of glyphs.
     Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
index 92677f2..25bb13b 100755 (executable)
@@ -1231,6 +1231,18 @@ public: // Queries & retrieves.
    */
   void SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment );
 
+  /**
+   * @brief Retrieves ignoreSpaceAfterText value from model
+   * @return The value of ignoreSpaceAfterText
+   */
+  bool IsIgnoreSpacesAfterText() const;
+
+  /**
+   * @brief Sets ignoreSpaceAfterText value to model
+   * @param[in] ignore The value of ignoreSpacesAfterText for the text
+   */
+  void SetIgnoreSpacesAfterText( bool ignore );
+
 public: // Relayout.
 
   /**
index 84b0428..65494e5 100755 (executable)
@@ -187,7 +187,8 @@ Model::Model()
   mVerticalLineAlignment( DevelText::VerticalLineAlignment::TOP ),
   mLineWrapMode( Text::LineWrap::WORD ),
   mAlignmentOffset( 0.0f ),
-  mElideEnabled( false )
+  mElideEnabled( false ),
+  mIgnoreSpacesAfterText( true )
 {
   mLogicalModel = LogicalModel::New();
   mVisualModel = VisualModel::New();
index cb8d77c..1ea725c 100755 (executable)
@@ -230,14 +230,15 @@ public:
    * 0,0 means that the top-left corner of the layout matches the top-left corner of the UI control.
    * Typically this will have a negative value with scrolling occurs.
    */
-  Vector2                                   mScrollPosition;        ///< The text is offset by this position when scrolling.
-  Vector2                                   mScrollPositionLast;    ///< The last offset value of mScrollPosition
-  HorizontalAlignment::Type                 mHorizontalAlignment;   ///< The layout's horizontal alignment.
-  VerticalAlignment::Type                   mVerticalAlignment;     ///< The layout's vertical alignment.
-  DevelText::VerticalLineAlignment::Type    mVerticalLineAlignment; ///< The layout's vertical line alignment.
-  Text::LineWrap::Mode                      mLineWrapMode;          ///< The text wrap mode
-  float                                     mAlignmentOffset;       ///< The alignment offset.
-  bool                                      mElideEnabled:1;        ///< Whether the text's elide is enabled.
+  Vector2                                   mScrollPosition;          ///< The text is offset by this position when scrolling.
+  Vector2                                   mScrollPositionLast;      ///< The last offset value of mScrollPosition
+  HorizontalAlignment::Type                 mHorizontalAlignment;     ///< The layout's horizontal alignment.
+  VerticalAlignment::Type                   mVerticalAlignment;       ///< The layout's vertical alignment.
+  DevelText::VerticalLineAlignment::Type    mVerticalLineAlignment;   ///< The layout's vertical line alignment.
+  Text::LineWrap::Mode                      mLineWrapMode;            ///< The text wrap mode
+  float                                     mAlignmentOffset;         ///< The alignment offset.
+  bool                                      mElideEnabled:1;          ///< Whether the text's elide is enabled.
+  bool                                      mIgnoreSpacesAfterText:1; ///< Whether ignoring spaces after text or not. Default is true.
 };
 
 } // namespace Text
index fa8c6f8..43bd4e5 100644 (file)
@@ -66,7 +66,8 @@
       "enableAutoScroll":false,
       "autoScrollLoopCount":2,
       "autoScrollGap":50,
-      "autoScrollSpeed":80
+      "autoScrollSpeed":80,
+      "ignoreSpacesAfterText":false
     },
 
     "TextLabelFontSize0":