From: Jinho, Lee Date: Thu, 11 May 2017 14:24:53 +0000 (+0900) Subject: Add read-only property for getting text line count X-Git-Tag: dali_1.2.43~13^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=448bcfa1ab294f28eb9252e2c736c83bc043f9ef Add read-only property for getting text line count Change-Id: I316752b0a8b77187d2995b7c8a2ad4be7650b371 --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 5cacd19..b1ffcff 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -93,6 +93,7 @@ const char* const PROPERTY_NAME_ENABLE_SCROLL_BAR = "enableSc const char* const PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION = "scrollBarShowDuration"; const char* const PROPERTY_NAME_SCROLL_BAR_FADE_DURATION = "scrollBarFadeDuration"; const char* const PROPERTY_NAME_PIXEL_SIZE = "pixelSize"; +const char* const PROPERTY_NAME_LINE_COUNT = "lineCount"; const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; @@ -433,6 +434,7 @@ int UtcDaliTextEditorGetPropertyP(void) DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_FADE_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PIXEL_SIZE ) == DevelTextEditor::Property::PIXEL_SIZE ); + DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_COUNT) == DevelTextEditor::Property::LINE_COUNT ); END_TEST; } @@ -1935,3 +1937,28 @@ int utcDaliTextEditorFontStylePropertyStringP(void) END_TEST; } +int utcDaliTextEditorGetPropertyLinecountP(void) +{ + ToolkitTestApplication application; + + tet_infoline(" utcDaliTextEditorGetPropertyLinecount getting line count property"); + + int lineCount =0 ; + + TextEditor editor = TextEditor::New(); + editor.SetProperty( TextEditor::Property::POINT_SIZE, 10) ; + editor.SetProperty( TextEditor::Property::TEXT, + "TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST "); + + Stage::GetCurrent().Add( editor ); + + editor.SetSize( 100.0f, 100.0f ); + lineCount = editor.GetProperty( DevelTextEditor::Property::LINE_COUNT ); + DALI_TEST_EQUALS( lineCount, 14, TEST_LOCATION ); + + editor.SetSize( 50.0f, 100.0f ); + lineCount = editor.GetProperty( DevelTextEditor::Property::LINE_COUNT ); + DALI_TEST_EQUALS( lineCount, 28, TEST_LOCATION ); + + END_TEST; +} diff --git a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h index cff3a39..5bc2654 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h @@ -109,7 +109,14 @@ namespace Property * @brief The size of font in pixels. * @details name "pixelSize", type float */ - PIXEL_SIZE + PIXEL_SIZE, + + /** + * @brief The line count of text. + * @details name "lineCount", type int + * @note this property is read-only. + */ + LINE_COUNT }; } // namespace Property diff --git a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h index 40c6c70..12e9c75 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h @@ -83,6 +83,13 @@ namespace Property * values FINISH_LOOP, IMMEDIATE, defualt FINISH_LOOP */ AUTO_SCROLL_STOP_MODE = OUTLINE + 4, + + /* + * @brief The line count of text. + * @details name "lineCount", type int + * @node this property is read-only. + */ + LINE_COUNT = OUTLINE + 5 }; } // namespace Property diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp index 5be99a6..47ee359 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -134,6 +134,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableScrollBar", DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollBarShowDuration", FLOAT, SCROLL_BAR_SHOW_DURATION ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollBarFadeDuration", FLOAT, SCROLL_BAR_FADE_DURATION ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "pixelSize", FLOAT, PIXEL_SIZE ) +DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextEditor, "lineCount", INTEGER, LINE_COUNT ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED ) @@ -994,6 +995,15 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind } break; } + case Toolkit::DevelTextEditor::Property::LINE_COUNT: + { + if( impl.mController ) + { + float width = textEditor.GetProperty( Actor::Property::SIZE_WIDTH ).Get(); + value = impl.mController->GetLineCount( width ); + } + break; + } } //switch } diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp index b1c031c..5187b25 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -117,7 +117,8 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY ) -DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE ) +DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT ) DALI_TYPE_REGISTRATION_END() @@ -736,6 +737,15 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde } break; } + case Toolkit::DevelTextLabel::Property::LINE_COUNT: + { + if( impl.mController ) + { + float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get(); + value = impl.mController->GetLineCount( width ); + } + break; + } } } diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index a502200..7596b51 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -1599,6 +1599,13 @@ float Controller::GetHeightForWidth( float width ) return layoutSize.height; } +int Controller::GetLineCount( float width ) +{ + GetHeightForWidth( width ); + int numberofLines = mImpl->mModel->GetNumberOfLines(); + return numberofLines; +} + const ModelInterface* const Controller::GetTextModel() const { return mImpl->mModel.Get(); diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 7562394..e3a7427 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -910,6 +910,13 @@ public: // Queries & retrieves. float GetHeightForWidth( float width ); /** + * @brief Retrieves the text's number of lines for a given width. + * @param[in] width The width of the text's area. + * @ return The number of lines. + */ + int GetLineCount( float width ); + + /** * @brief Retrieves the text's model. * * @return A pointer to the text's model.