From 748d65f75494fb5c774f3b391da0f6d437619b24 Mon Sep 17 00:00:00 2001 From: Shrouq Sabah Date: Sun, 6 Jun 2021 15:51:36 +0300 Subject: [PATCH] Fix the LineCount issue when text is changed. There is an issue with LineCount of TextLabel and TextEditor. The issue is that if you set Text in TextLabel and do GetLineCount, an incorrect LineCount is returned. This issue related to GetHeightForWidth which called in Controller::GetLineCount(float width). Change-Id: Ia0cc5737432080fbd925bc6e655062f023a1c133 --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 43 +++++++++++++++++++++ .../src/dali-toolkit/utc-Dali-TextLabel.cpp | 44 ++++++++++++++++++++++ .../internal/text/text-controller-relayouter.cpp | 5 ++- 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index fa48c76..675e2c7 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -3519,6 +3519,49 @@ int utcDaliTextEditorGetHeightForWidthDoesNotChangeLineCountLineWrapCharCase(voi END_TEST; } +int utcDaliTextEditorGetHeightForWidthChangeLineCountWhenTextChanged(void) +{ + ToolkitTestApplication application; + + tet_infoline(" utcDaliTextEditorGetHeightForWidthChangeLineCountWhenTextChanged "); + + int lineCountBefore =0 ; + int lineCountAfter =0 ; + + // Create a text editor + TextEditor textEditor = TextEditor::New(); + //Set very large font-size using point-size + textEditor.SetProperty( TextEditor::Property::POINT_SIZE, 10) ; + //Specify font-family + textEditor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVu Sans"); + //Specify size + textEditor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 100.f ) ); + //Set text longer than width of textEditor + textEditor.SetProperty( TextEditor::Property::TEXT, "Short text"); + //Set line wrap mode Character + textEditor.SetProperty(TextEditor::Property::LINE_WRAP_MODE, "CHARACTER"); + + application.GetScene().Add( textEditor ); + + application.SendNotification(); + application.Render(); + + + lineCountBefore = textEditor.GetProperty( TextEditor::Property::LINE_COUNT ); + + textEditor.SetProperty( TextEditor::Property::TEXT, "This is very loooooooooooooooooooooooooooooooooooong text for test"); + lineCountAfter = textEditor.GetProperty( TextEditor::Property::LINE_COUNT ); + + // When the text changed, the Line-count should be updated according to new text. + // Because the GetHeightForWidth is called in Controller::GetLineCount(float width) + DALI_TEST_EQUALS( lineCountBefore ,1, TEST_LOCATION ); + DALI_TEST_GREATER( lineCountAfter,1, TEST_LOCATION ); + + + END_TEST; +} + + int utcDaliTextEditorGetNaturalSizeDoesNotChangeLineCountScrollingCase(void) { ToolkitTestApplication application; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index ac7403b..9a187d6 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -1885,3 +1885,47 @@ int UtcDaliTextLabelHyphenWrapMode(void) END_TEST; } + + +int utcDaliTextLabelGetHeightForWidthChangeLineCountWhenTextChanged(void) +{ + ToolkitTestApplication application; + + tet_infoline(" utcDaliTextLabelGetHeightForWidthChangeLineCountWhenTextChanged "); + + int lineCountBefore =0 ; + int lineCountAfter =0 ; + + // Create a text editor + TextLabel textLabel = TextLabel::New(); + //Set very large font-size using point-size + textLabel.SetProperty( TextLabel::Property::POINT_SIZE, 10) ; + //Specify font-family + textLabel.SetProperty( TextLabel::Property::FONT_FAMILY, "DejaVu Sans"); + //Specify size + textLabel.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 100.f ) ); + //Set text longer than width of textLabel + textLabel.SetProperty( TextLabel::Property::TEXT, "Short text"); + //Set line wrap mode Character + textLabel.SetProperty(TextLabel::Property::LINE_WRAP_MODE, "CHARACTER"); + textLabel.SetProperty(TextLabel::Property::MULTI_LINE, true); + + application.GetScene().Add( textLabel ); + + application.SendNotification(); + application.Render(); + + + lineCountBefore = textLabel.GetProperty( TextLabel::Property::LINE_COUNT ); + + textLabel.SetProperty( TextLabel::Property::TEXT, "This is very loooooooooooooooooooooooooooooooooooong text for test"); + lineCountAfter = textLabel.GetProperty( TextLabel::Property::LINE_COUNT ); + + // When the text changed, the Line-count should be updated according to new text. + // Because the GetHeightForWidth is called in Controller::GetLineCount(float width) + DALI_TEST_EQUALS( lineCountBefore ,1, TEST_LOCATION ); + DALI_TEST_GREATER( lineCountAfter,1, TEST_LOCATION ); + + + END_TEST; +} \ No newline at end of file diff --git a/dali-toolkit/internal/text/text-controller-relayouter.cpp b/dali-toolkit/internal/text/text-controller-relayouter.cpp index 78e7331..134a327 100644 --- a/dali-toolkit/internal/text/text-controller-relayouter.cpp +++ b/dali-toolkit/internal/text/text-controller-relayouter.cpp @@ -291,7 +291,10 @@ float Controller::Relayouter::GetHeightForWidth(Controller& controller, float wi // The implementation of Get LineCount property depends on calling GetHeightForWidth then read mLines.Count() from visualModel direct. // If the LineCount property is requested before rendering and layouting then the value will be zero, which is incorrect. // So we will not restore the previously backed-up mLines and mGlyphPositions from visualModel in such case. - bool restoreLinesAndGlyphPositions = visualModel->mControlSize.width>0 && visualModel->mControlSize.height>0; + // Another case to skip restore is when the requested width equals the Control's width which means the caller need to update the old values. + // For example, when the text is changed. + bool restoreLinesAndGlyphPositions = (visualModel->mControlSize.width>0 && visualModel->mControlSize.height>0) + && (visualModel->mControlSize.width != width); layoutSize = CalculateLayoutSizeOnRequiredControllerSize(controller, sizeRequestedWidthAndMaxHeight, requestedOperationsMask, restoreLinesAndGlyphPositions); -- 2.7.4