From: Victor Cebollada Date: Thu, 17 Dec 2015 09:26:09 +0000 (+0000) Subject: Enable markup processor in text controls. X-Git-Tag: dali_1.1.16~3 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=b26723c419d9a091f14c7bb2e9955380b06a6348 Enable markup processor in text controls. Property added to enable and disable the markup processor. Change-Id: I0c5e237ed235774a5cbcbbb393de7200385575d8 Signed-off-by: Victor Cebollada --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 0afc098..9fe5e53 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -75,6 +75,7 @@ const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR = "selectio const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX = "decorationBoundingBox"; const char* const PROPERTY_NAME_INPUT_METHOD_SETTINGS = "inputMethodSettings"; const char* const PROPERTY_NAME_INPUT_COLOR = "inputColor"; +const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup"; const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; @@ -264,6 +265,7 @@ int UtcDaliTextFieldGetPropertyP(void) DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextField::Property::DECORATION_BOUNDING_BOX ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_METHOD_SETTINGS ) == TextField::Property::INPUT_METHOD_SETTINGS ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextField::Property::INPUT_COLOR ); + DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextField::Property::ENABLE_MARKUP ); END_TEST; } @@ -395,6 +397,11 @@ int UtcDaliTextFieldSetPropertyP(void) field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW ); DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION ); + // Check the enable markup property. + DALI_TEST_CHECK( !field.GetProperty( TextField::Property::ENABLE_MARKUP ) ); + field.SetProperty( TextField::Property::ENABLE_MARKUP, true ); + DALI_TEST_CHECK( field.GetProperty( TextField::Property::ENABLE_MARKUP ) ); + END_TEST; } diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index 370fde0..5e77ebb 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -50,6 +50,7 @@ const char* const PROPERTY_NAME_SHADOW_COLOR = "shadowColor"; const char* const PROPERTY_NAME_UNDERLINE_ENABLED = "underlineEnabled"; const char* const PROPERTY_NAME_UNDERLINE_COLOR = "underlineColor"; const char* const PROPERTY_NAME_UNDERLINE_HEIGHT = "underlineHeight"; +const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup"; const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; @@ -150,6 +151,7 @@ int UtcDaliToolkitTextLabelGetPropertyP(void) DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_UNDERLINE_ENABLED ) == TextLabel::Property::UNDERLINE_ENABLED ); DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_UNDERLINE_COLOR ) == TextLabel::Property::UNDERLINE_COLOR ); DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_UNDERLINE_HEIGHT) == TextLabel::Property::UNDERLINE_HEIGHT ); + DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP) == TextLabel::Property::ENABLE_MARKUP ); END_TEST; } @@ -211,6 +213,11 @@ int UtcDaliToolkitTextLabelSetPropertyP(void) DALI_TEST_CHECK( label2 ); DALI_TEST_EQUALS( label2.GetProperty( TextLabel::Property::TEXT ), std::string("New text"), TEST_LOCATION ); + // Check the enable markup property. + DALI_TEST_CHECK( !label.GetProperty( TextLabel::Property::ENABLE_MARKUP ) ); + label.SetProperty( TextLabel::Property::ENABLE_MARKUP, true ); + DALI_TEST_CHECK( label.GetProperty( TextLabel::Property::ENABLE_MARKUP ) ); + END_TEST; } diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index e31213e..8b7ea1d 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -119,6 +119,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR ) +DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP ) DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED ) @@ -566,6 +567,17 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr } break; } + case Toolkit::TextField::Property::ENABLE_MARKUP: + { + if( impl.mController ) + { + const bool enableMarkup = value.Get(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup ); + + impl.mController->SetMarkupProcessorEnabled( enableMarkup ); + } + break; + } } // switch } // textfield } @@ -857,6 +869,14 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde { break; } + case Toolkit::TextField::Property::ENABLE_MARKUP: + { + if( impl.mController ) + { + value = impl.mController->IsMarkupProcessorEnabled(); + } + 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 11364d0..0094c9b 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -93,6 +93,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowColor", VECTOR4, DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineEnabled", BOOLEAN, UNDERLINE_ENABLED ) DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineColor", VECTOR4, UNDERLINE_COLOR ) DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineHeight", FLOAT, UNDERLINE_HEIGHT ) +DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP ) DALI_TYPE_REGISTRATION_END() @@ -290,6 +291,15 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr } break; } + case Toolkit::TextLabel::Property::ENABLE_MARKUP: + { + if( impl.mController ) + { + const bool enableMarkup = value.Get(); + impl.mController->SetMarkupProcessorEnabled( enableMarkup ); + } + break; + } } } } @@ -425,6 +435,14 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde } break; } + case Toolkit::TextLabel::Property::ENABLE_MARKUP: + { + if( impl.mController ) + { + value = impl.mController->IsMarkupProcessorEnabled(); + } + break; + } } } diff --git a/dali-toolkit/public-api/controls/text-controls/text-field.h b/dali-toolkit/public-api/controls/text-controls/text-field.h index 9b6453d..e222f99 100644 --- a/dali-toolkit/public-api/controls/text-controls/text-field.h +++ b/dali-toolkit/public-api/controls/text-controls/text-field.h @@ -76,7 +76,7 @@ public: MAX_LENGTH, ///< name "maxLength" The maximum number of characters that can be inserted, type INTEGER EXCEED_POLICY, ///< name "exceedPolicy" Specifies how the text is truncated when it does not fit, type INTEGER HORIZONTAL_ALIGNMENT, ///< name "horizontalAlignment", The line horizontal alignment, type STRING, values "BEGIN", "CENTER", "END" - VERTICAL_ALIGNMENT, ///< name "verticalAlignment", The line vertical alignment, type STRING, values "TOP", "CENTER", "BOTTOM" + VERTICAL_ALIGNMENT, ///< name "verticalAlignment", The line vertical alignment, type STRING, values "TOP", "CENTER", "BOTTOM" TEXT_COLOR, ///< name "textColor", The text color, type VECTOR4 PLACEHOLDER_TEXT_COLOR, ///< name "placeholderTextColor", The placeholder-text color, type VECTOR4 SHADOW_OFFSET, ///< name "shadowOffset", The drop shadow offset 0 indicates no shadow, type VECTOR2 @@ -101,6 +101,7 @@ public: DECORATION_BOUNDING_BOX, ///< name "decorationBoundingBox", The decorations (handles etc) will positioned within this area on-screen, type RECTANGLE INPUT_METHOD_SETTINGS, ///< name "inputMethodSettings", The settings to relating to the System's Input Method, Key and Value type MAP INPUT_COLOR, ///< name "inputColor", The color of the new input text, type VECTOR4 + ENABLE_MARKUP ///< name "enableMarkup", Whether the mark-up processing is enabled. type BOOLEAN }; }; diff --git a/dali-toolkit/public-api/controls/text-controls/text-label.h b/dali-toolkit/public-api/controls/text-controls/text-label.h index 190d25c..6abc9fd 100644 --- a/dali-toolkit/public-api/controls/text-controls/text-label.h +++ b/dali-toolkit/public-api/controls/text-controls/text-label.h @@ -68,13 +68,14 @@ public: POINT_SIZE, ///< name "pointSize", The size of font in points, type FLOAT MULTI_LINE, ///< name "multiLine", The single-line or multi-line layout option, type BOOLEAN HORIZONTAL_ALIGNMENT, ///< name "horizontalAlignment", The line horizontal alignment, type STRING, values "BEGIN", "CENTER", "END" - VERTICAL_ALIGNMENT, ///< name "verticalAlignment", The line vertical alignment, type STRING, values "TOP", "CENTER", "BOTTOM" + VERTICAL_ALIGNMENT, ///< name "verticalAlignment", The line vertical alignment, type STRING, values "TOP", "CENTER", "BOTTOM" TEXT_COLOR, ///< name "textColor", The text color, type VECTOR4 SHADOW_OFFSET, ///< name "shadowOffset", The drop shadow offset 0 indicates no shadow, type VECTOR2 SHADOW_COLOR, ///< name "shadowColor", The color of a drop shadow, type VECTOR4 UNDERLINE_ENABLED, ///< name "underlineEnabled", The underline enabled flag, type BOOLEAN UNDERLINE_COLOR, ///< name "underlineColor", The color of the underline, type VECTOR4 - UNDERLINE_HEIGHT ///< name "underlineHeight", Overrides the underline height from font metrics, type FLOAT + UNDERLINE_HEIGHT, ///< name "underlineHeight", Overrides the underline height from font metrics, type FLOAT + ENABLE_MARKUP ///< name "enableMarkup", Whether the mark-up processing is enabled. type BOOLEAN }; }; diff --git a/docs/content/shared-javascript-and-cpp-documentation/markup-style.md b/docs/content/shared-javascript-and-cpp-documentation/markup-style.md new file mode 100644 index 0000000..7c73868 --- /dev/null +++ b/docs/content/shared-javascript-and-cpp-documentation/markup-style.md @@ -0,0 +1,90 @@ + + +# Mark-up Style {#markup-style} + +Mark-up tags can be used within the text to set styles. + +By default the text controls don't process the mark-up string. To enable the mark-up string processing the property *ENABLE_MARKUP* must be set to *true*. + +~~~{.cpp} +// C++ + +TextField field = TextField::New(); +field.SetProperty( TextField::Property::ENABLE_MARKUP, true ); + +Stage::GetCurrent().Add( field ); +~~~ + +~~~{.js} +// JavaScript + +var field = new dali.TextField(); +field.enableMarkup = true; + +dali.stage.add( field ); +~~~ + +Note the mark-up processor doesn't check the correctness of the mark-up string. This may cause the text to be badly rendered. + +The table below describes the priorities when styles are applied while rendering text. +| | | | | +|--|--|--|--| +| Priority 1 | Style set by markup string. | Will override the style set through the control properties. | i.e The \ tag will override the *TEXT_COLOR* property. | +| Priority 2 | Style set through the control properties. | Will override the default platform style. | | +| Priority 3 | Default platform style. | | | + +Current supported tags are: + +## \ + +Sets the color of the characters inside the tag. The *color* tag has a *value* attribute used to set the color. Possible values are: 'red', 'green', 'blue', 'yellow', 'magenta', + 'cyan', 'white', 'black' and 'transparent'. Web color and 32 bits hexadecimal 0xAARRGGBB formats are also supported. + +Examples below are equivalent, render the text in red. Second example codes the color in 0xAARRGGBB, third and fourth in web color with 3 and 6 characters. + +~~~{.cpp} +// C++ +field.SetProperty( TextLabel::Property::TEXT, "Red Text" ); // Color coded with a text constant. +~~~ + +~~~{.js} +// JavaScript + +field.text = "Red Text"; // Color coded with a text constant. +~~~ + +~~~{.cpp} +// C++ +field.SetProperty( TextLabel::Property::TEXT, "Red Text" ); // Color packed inside an ARGB hexadecimal value. +~~~ + +~~~{.js} +// JavaScript + +field.text = "Red Text"; // Color packed inside an ARGB hexadecimal value. +~~~ + +~~~{.cpp} +// C++ +field.SetProperty( TextLabel::Property::TEXT, "Red Text" ); // Color packed with the web color format (3 characters). +~~~ + +~~~{.js} +// JavaScript + +field.text = "Red Text"; // Color packed with the web color format (3 characters). +~~~ + +~~~{.cpp} +// C++ +field.SetProperty( TextLabel::Property::TEXT, "Red Text" ); // Color packed with the web color format (6 characters). +~~~ + +~~~{.js} +// JavaScript + +field.text = "Red Text"; // Color packed with the web color format (6 characters). +~~~ + +*/ diff --git a/docs/content/shared-javascript-and-cpp-documentation/text-field.md b/docs/content/shared-javascript-and-cpp-documentation/text-field.md index e42d14a..dbe468f 100644 --- a/docs/content/shared-javascript-and-cpp-documentation/text-field.md +++ b/docs/content/shared-javascript-and-cpp-documentation/text-field.md @@ -53,6 +53,20 @@ console.log( field.text ); By default TextField will automatically select a suitable font from the platform. However, a different font could be selected. See the [Font Selection](@ref font-selection) section for more details. +### Mark-up Style + +Mark-up tags can be used to change the style of the text. See the [Mark-up Style](@ref markup-style) section for more details. + +### Input Style + +The input style can be changed through the control properties. Current supported input style properties are: + +#### INPUT_COLOR + +Sets the input color. All subsequent characters added will be rendered with the input color. + +Note the input color may change if the cursor is updated by tapping in a new position. + ### Text Alignment TextField displays a single-line of text, which will scroll if there is not enough room for the text displayed. @@ -129,6 +143,7 @@ field.placeholderTextColor = dali.COLOR_BLACK; horizontalAlignment | HORIZONTAL_ALIGNMENT | STRING | O | X verticalAlignment | VERTICAL_ALIGNMENT | STRING | O | X textColor | TEXT_COLOR | VECTOR4 | O | X + placeholderTextColor | PLACEHOLDER_TEXT_COLOR | VECTOR4 | O | X shadowOffset | SHADOW_OFFSET | VECTOR2 | O | X shadowColor | SHADOW_COLOR | VECTOR4 | O | X primaryCursorColor | PRIMARY_CURSOR_COLOR | VECTOR4 | O | X @@ -136,6 +151,7 @@ field.placeholderTextColor = dali.COLOR_BLACK; enableCursorBlink | ENABLE_CURSOR_BLINK | BOOLEAN | O | X cursorBlinkInterval | CURSOR_BLINK_INTERVAL | FLOAT | O | X cursorBlinkDuration | CURSOR_BLINK_DURATION | FLOAT | O | X + cursorWidth | CURSOR_WIDTH | INTEGER | O | X grabHandleImage | GRAB_HANDLE_IMAGE | STRING | O | X grabHandlePressedImage | GRAB_HANDLE_PRESSED_IMAGE | STRING | O | X scrollThreshold | SCROLL_THRESHOLD | FLOAT | O | X @@ -144,9 +160,13 @@ field.placeholderTextColor = dali.COLOR_BLACK; selectionHandleImageRight | SELECTION_HANDLE_IMAGE_RIGHT | STRING | O | X selectionHandlePressedImageLeft | SELECTION_HANDLE_PRESSED_IMAGE_LEFT | STRING | O | X selectionHandlePressedImageRight | SELECTION_HANDLE_PRESSED_IMAGE_RIGHT | STRING | O | X + selectionHandleMarkerImageLeft | SELECTION_HANDLE_MARKER_IMAGE_LEFT | MAP | O | X + selectionHandleMarkerImageRight | SELECTION_HANDLE_MARKER_IMAGE_RIGHT | MAP | O | X selectionHighlightColor | SELECTION_HIGHLIGHT_COLOR | VECTOR4 | O | X decorationBoundingBox | DECORATION_BOUNDING_BOX | RECTANGLE | O | X inputMethodSettings | INPUT_METHOD_SETTINGS | MAP | O | X + inputColor | INPUT_COLOR | VECTOR4 | O | X + enableMarkup | ENABLE_MARKUP | BOOLEAN | O | X @class TextField diff --git a/docs/content/shared-javascript-and-cpp-documentation/text-label.md b/docs/content/shared-javascript-and-cpp-documentation/text-label.md index 5986eee..13d2ab0 100644 --- a/docs/content/shared-javascript-and-cpp-documentation/text-label.md +++ b/docs/content/shared-javascript-and-cpp-documentation/text-label.md @@ -43,6 +43,10 @@ The position of the label on-screen is dependent on the parentOrigin and anchorP By default TextLabel will automatically select a suitable font from the platform. However, a different font could be selected. See the [Font Selection](@ref font-selection) section for more details. +### Mark-up Style + +Mark-up tags can be used to change the style of the text. See the [Mark-up Style](@ref markup-style) section for more details. + ### Text Alignment Wrapping can be enabled using the MULTI_LINE property: @@ -312,22 +316,23 @@ label1.underlineHeight = 1; ### Text Label Properties - Name (JavaScript) | Name (C++) | Type | Writable | Animatable ----------------------|---------------------|--------------|--------------|----------- - renderingBackend | RENDERING_BACKEND | INTEGER | O | X - text | TEXT | STRING | O | X - fontFamily | FONT_FAMILY | STRING | O | X - fontStyle | FONT_STYLE | STRING | O | X - pointSize | POINT_SIZE | FLOAT | O | X - multiLine | MULTI_LINE | BOOLEAN | O | X - horizontalAlignment | HORIZONTAL_ALIGNMENT| STRING | O | X - verticalAlignment | VERTICAL_ALIGNMENT | STRING | O | X - textColor | TEXT_COLOR | VECTOR4 | O | X - shadowOffset | SHADOW_OFFSET | VECTOR2 | O | X - shadowColor | SHADOW_COLOR | VECTOR4 | O | X - underlineEnabled | UNDERLINE_ENABLED | BOOLEAN | O | X - underlineColor | UNDERLINE_COLOR | VECTOR4 | O | X - underlineHeight | UNDERLINE_HEIGHT | FLOAT | O | X + Name (JavaScript) | Name (C++) | Type | Writable | Animatable +---------------------|----------------------|--------------|--------------|----------- + renderingBackend | RENDERING_BACKEND | INTEGER | O | X + text | TEXT | STRING | O | X + fontFamily | FONT_FAMILY | STRING | O | X + fontStyle | FONT_STYLE | STRING | O | X + pointSize | POINT_SIZE | FLOAT | O | X + multiLine | MULTI_LINE | BOOLEAN | O | X + horizontalAlignment | HORIZONTAL_ALIGNMENT | STRING | O | X + verticalAlignment | VERTICAL_ALIGNMENT | STRING | O | X + textColor | TEXT_COLOR | VECTOR4 | O | X + shadowOffset | SHADOW_OFFSET | VECTOR2 | O | X + shadowColor | SHADOW_COLOR | VECTOR4 | O | X + underlineEnabled | UNDERLINE_ENABLED | BOOLEAN | O | X + underlineColor | UNDERLINE_COLOR | VECTOR4 | O | X + underlineHeight | UNDERLINE_HEIGHT | FLOAT | O | X + enableMarkup | ENABLE_MARKUP | BOOLEAN | O | X