namespace
{
-const Scripting::StringEnum< Toolkit::Text::LayoutEngine::Alignment > ALIGNMENT_STRING_TABLE[] =
+const Scripting::StringEnum< Toolkit::Text::LayoutEngine::HorizontalAlignment > HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
{
- { "BEGIN", Toolkit::Text::LayoutEngine::ALIGN_BEGIN },
- { "CENTER", Toolkit::Text::LayoutEngine::ALIGN_CENTER },
- { "END", Toolkit::Text::LayoutEngine::ALIGN_END },
+ { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
+ { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
+ { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
};
-const unsigned int ALIGNMENT_STRING_TABLE_COUNT = sizeof( ALIGNMENT_STRING_TABLE ) / sizeof( ALIGNMENT_STRING_TABLE[0] );
+const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
+
+const Scripting::StringEnum< Toolkit::Text::LayoutEngine::VerticalAlignment > VERTICAL_ALIGNMENT_STRING_TABLE[] =
+{
+ { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
+ { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
+ { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
+};
+const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
// Type registration
BaseHandle Create()
DALI_PROPERTY_REGISTRATION( TextField, "cursor-blink-interval", FLOAT, CURSOR_BLINK_INTERVAL )
DALI_PROPERTY_REGISTRATION( TextField, "cursor-blink-duration", FLOAT, CURSOR_BLINK_DURATION )
DALI_PROPERTY_REGISTRATION( TextField, "grab-handle-image", STRING, GRAB_HANDLE_IMAGE )
-DALI_PROPERTY_REGISTRATION( TextField, "decoration bounding-box", RECTANGLE, DECORATION_BOUNDING_BOX )
-DALI_PROPERTY_REGISTRATION( TextField, "alignment", STRING, ALIGNMENT )
+DALI_PROPERTY_REGISTRATION( TextField, "decoration-bounding-box", RECTANGLE, DECORATION_BOUNDING_BOX )
+DALI_PROPERTY_REGISTRATION( TextField, "horizontal-alignment", STRING, HORIZONTAL_ALIGNMENT )
+DALI_PROPERTY_REGISTRATION( TextField, "vertical-alignment", STRING, VERTICAL_ALIGNMENT )
DALI_TYPE_REGISTRATION_END()
} // namespace
}
break;
}
- case Toolkit::TextField::Property::ALIGNMENT:
+ case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
{
LayoutEngine& engine = impl.mController->GetLayoutEngine();
- const LayoutEngine::Alignment alignment = Scripting::GetEnumeration< Toolkit::Text::LayoutEngine::Alignment >( value.Get< std::string >().c_str(),
- ALIGNMENT_STRING_TABLE,
- ALIGNMENT_STRING_TABLE_COUNT );
+ const LayoutEngine::HorizontalAlignment alignment = Scripting::GetEnumeration< Toolkit::Text::LayoutEngine::HorizontalAlignment >( value.Get< std::string >().c_str(),
+ HORIZONTAL_ALIGNMENT_STRING_TABLE,
+ HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
- if( engine.GetAlignment() != alignment )
+ if( engine.GetHorizontalAlignment() != alignment )
{
- engine.SetAlignment( alignment );
+ engine.SetHorizontalAlignment( alignment );
+ impl.RequestTextRelayout();
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
+ {
+ LayoutEngine& engine = impl.mController->GetLayoutEngine();
+ const LayoutEngine::VerticalAlignment alignment = Scripting::GetEnumeration< Toolkit::Text::LayoutEngine::VerticalAlignment >( value.Get< std::string >().c_str(),
+ VERTICAL_ALIGNMENT_STRING_TABLE,
+ VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
+
+ if( engine.GetVerticalAlignment() != alignment )
+ {
+ engine.SetVerticalAlignment( alignment );
impl.RequestTextRelayout();
}
break;
}
break;
}
- case Toolkit::TextField::Property::ALIGNMENT:
+ case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
+ {
+ if( impl.mController )
+ {
+ value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
+ HORIZONTAL_ALIGNMENT_STRING_TABLE,
+ HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT ) );
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
{
if( impl.mController )
{
- value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::Alignment >( impl.mController->GetLayoutEngine().GetAlignment(),
- ALIGNMENT_STRING_TABLE,
- ALIGNMENT_STRING_TABLE_COUNT ) );
+ value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
+ VERTICAL_ALIGNMENT_STRING_TABLE,
+ VERTICAL_ALIGNMENT_STRING_TABLE_COUNT ) );
}
break;
}
namespace
{
-const Scripting::StringEnum< Toolkit::Text::LayoutEngine::Alignment > ALIGNMENT_STRING_TABLE[] =
+const Scripting::StringEnum< Toolkit::Text::LayoutEngine::HorizontalAlignment > HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
{
- { "BEGIN", Toolkit::Text::LayoutEngine::ALIGN_BEGIN },
- { "CENTER", Toolkit::Text::LayoutEngine::ALIGN_CENTER },
- { "END", Toolkit::Text::LayoutEngine::ALIGN_END },
+ { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
+ { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
+ { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
};
-const unsigned int ALIGNMENT_STRING_TABLE_COUNT = sizeof( ALIGNMENT_STRING_TABLE ) / sizeof( ALIGNMENT_STRING_TABLE[0] );
+const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
+
+const Scripting::StringEnum< Toolkit::Text::LayoutEngine::VerticalAlignment > VERTICAL_ALIGNMENT_STRING_TABLE[] =
+{
+ { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
+ { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
+ { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
+};
+const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
// Type registration
BaseHandle Create()
// Setup properties, signals and actions using the type-registry.
DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
-DALI_PROPERTY_REGISTRATION( TextLabel, "rendering-backend", INTEGER, RENDERING_BACKEND )
-DALI_PROPERTY_REGISTRATION( TextLabel, "text", STRING, TEXT )
-DALI_PROPERTY_REGISTRATION( TextLabel, "font-family", STRING, FONT_FAMILY )
-DALI_PROPERTY_REGISTRATION( TextLabel, "font-style", STRING, FONT_STYLE )
-DALI_PROPERTY_REGISTRATION( TextLabel, "point-size", FLOAT, POINT_SIZE )
-DALI_PROPERTY_REGISTRATION( TextLabel, "multi-line", BOOLEAN, MULTI_LINE )
-DALI_PROPERTY_REGISTRATION( TextLabel, "alignment", STRING, ALIGNMENT )
+DALI_PROPERTY_REGISTRATION( TextLabel, "rendering-backend", INTEGER, RENDERING_BACKEND )
+DALI_PROPERTY_REGISTRATION( TextLabel, "text", STRING, TEXT )
+DALI_PROPERTY_REGISTRATION( TextLabel, "font-family", STRING, FONT_FAMILY )
+DALI_PROPERTY_REGISTRATION( TextLabel, "font-style", STRING, FONT_STYLE )
+DALI_PROPERTY_REGISTRATION( TextLabel, "point-size", FLOAT, POINT_SIZE )
+DALI_PROPERTY_REGISTRATION( TextLabel, "multi-line", BOOLEAN, MULTI_LINE )
+DALI_PROPERTY_REGISTRATION( TextLabel, "horizontal-alignment", STRING, HORIZONTAL_ALIGNMENT )
+DALI_PROPERTY_REGISTRATION( TextLabel, "vertical-alignment", STRING, VERTICAL_ALIGNMENT )
DALI_TYPE_REGISTRATION_END()
}
break;
}
- case Toolkit::TextLabel::Property::ALIGNMENT:
+ case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
{
LayoutEngine& engine = impl.mController->GetLayoutEngine();
- const LayoutEngine::Alignment alignment = Scripting::GetEnumeration< Toolkit::Text::LayoutEngine::Alignment >( value.Get< std::string >().c_str(),
- ALIGNMENT_STRING_TABLE,
- ALIGNMENT_STRING_TABLE_COUNT );
+ const LayoutEngine::HorizontalAlignment alignment = Scripting::GetEnumeration< Toolkit::Text::LayoutEngine::HorizontalAlignment >( value.Get< std::string >().c_str(),
+ HORIZONTAL_ALIGNMENT_STRING_TABLE,
+ HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
- if( engine.GetAlignment() != alignment )
+ if( engine.GetHorizontalAlignment() != alignment )
{
- engine.SetAlignment( alignment );
+ engine.SetHorizontalAlignment( alignment );
+ impl.RequestTextRelayout();
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
+ {
+ LayoutEngine& engine = impl.mController->GetLayoutEngine();
+ const LayoutEngine::VerticalAlignment alignment = Scripting::GetEnumeration< Toolkit::Text::LayoutEngine::VerticalAlignment >( value.Get< std::string >().c_str(),
+ VERTICAL_ALIGNMENT_STRING_TABLE,
+ VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
+
+ if( engine.GetVerticalAlignment() != alignment )
+ {
+ engine.SetVerticalAlignment( alignment );
impl.RequestTextRelayout();
}
break;
}
break;
}
- case Toolkit::TextLabel::Property::ALIGNMENT:
+ case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
+ {
+ if( impl.mController )
+ {
+ value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
+ HORIZONTAL_ALIGNMENT_STRING_TABLE,
+ HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT ) );
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
{
if( impl.mController )
{
- value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::Alignment >( impl.mController->GetLayoutEngine().GetAlignment(),
- ALIGNMENT_STRING_TABLE,
- ALIGNMENT_STRING_TABLE_COUNT ) );
+ value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
+ VERTICAL_ALIGNMENT_STRING_TABLE,
+ VERTICAL_ALIGNMENT_STRING_TABLE_COUNT ) );
}
break;
}
{
Impl()
: mLayout( LayoutEngine::SINGLE_LINE_BOX ),
- mAlignment( LayoutEngine::ALIGN_BEGIN )
+ mHorizontalAlignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN ),
+ mVerticalAlignment( LayoutEngine::VERTICAL_ALIGN_TOP )
{
mFontClient = TextAbstraction::FontClient::Get();
}
// 2) Calculate the alignment offset accordingly with the align option,
// the box width, line length, and the paragraphs direction.
- float alignOffset = CalculateAlignment( layoutSize.width,
- line.lineSize.width,
- line.extraLength,
- paragraphDirection );
+ float alignOffset = CalculateHorizontalAlignment( layoutSize.width,
+ line.lineSize.width,
+ line.extraLength,
+ paragraphDirection );
// 3) Traverse all glyphs and update the 'x' position.
for( GlyphIndex index = line.glyphIndex,
return true;
}
- float CalculateAlignment( float boxWidth,
- float lineLength,
- float extraLength,
- bool paragraphDirection )
+ float CalculateHorizontalAlignment( float boxWidth,
+ float lineLength,
+ float extraLength,
+ bool paragraphDirection )
{
float offset = 0.f;
- Alignment alignment = mAlignment;
+ HorizontalAlignment alignment = mHorizontalAlignment;
if( paragraphDirection &&
- ( ALIGN_CENTER != alignment ) )
+ ( HORIZONTAL_ALIGN_CENTER != alignment ) )
{
- if( ALIGN_BEGIN == alignment )
+ if( HORIZONTAL_ALIGN_BEGIN == alignment )
{
- alignment = ALIGN_END;
+ alignment = HORIZONTAL_ALIGN_END;
}
else
{
- alignment = ALIGN_BEGIN;
+ alignment = HORIZONTAL_ALIGN_BEGIN;
}
}
switch( alignment )
{
- case ALIGN_BEGIN:
+ case HORIZONTAL_ALIGN_BEGIN:
{
offset = 0.f;
break;
}
- case ALIGN_CENTER:
+ case HORIZONTAL_ALIGN_CENTER:
{
offset = 0.5f * ( boxWidth - lineLength );
const int intOffset = static_cast<int>( offset ); // try to avoid pixel alignment.
offset = static_cast<float>( intOffset );
break;
}
- case ALIGN_END:
+ case HORIZONTAL_ALIGN_END:
{
offset = boxWidth - lineLength;
break;
}
LayoutEngine::Layout mLayout;
- LayoutEngine::Alignment mAlignment;
+ LayoutEngine::HorizontalAlignment mHorizontalAlignment;
+ LayoutEngine::VerticalAlignment mVerticalAlignment;
TextAbstraction::FontClient mFontClient;
};
return mImpl->mLayout;
}
-void LayoutEngine::SetAlignment( Alignment alignment )
+void LayoutEngine::SetHorizontalAlignment( HorizontalAlignment alignment )
{
- mImpl->mAlignment = alignment;
+ mImpl->mHorizontalAlignment = alignment;
}
-LayoutEngine::Alignment LayoutEngine::GetAlignment() const
+LayoutEngine::HorizontalAlignment LayoutEngine::GetHorizontalAlignment() const
{
- return mImpl->mAlignment;
+ return mImpl->mHorizontalAlignment;
+}
+
+void LayoutEngine::SetVerticalAlignment( VerticalAlignment alignment )
+{
+ mImpl->mVerticalAlignment = alignment;
+}
+
+LayoutEngine::VerticalAlignment LayoutEngine::GetVerticalAlignment() const
+{
+ return mImpl->mVerticalAlignment;
}
bool LayoutEngine::LayoutText( const LayoutParameters& layoutParameters,
MULTI_LINE_BOX
};
- enum Alignment
+ enum HorizontalAlignment
{
- ALIGN_BEGIN,
- ALIGN_CENTER,
- ALIGN_END
+ HORIZONTAL_ALIGN_BEGIN,
+ HORIZONTAL_ALIGN_CENTER,
+ HORIZONTAL_ALIGN_END
+ };
+
+ enum VerticalAlignment
+ {
+ VERTICAL_ALIGN_TOP,
+ VERTICAL_ALIGN_CENTER,
+ VERTICAL_ALIGN_BOTTOM
};
/**
unsigned int GetLayout() const;
/**
- * @brief Choose the required line alignment.
+ * @brief Choose the required text horizontal alignment.
+ *
+ * @param[in] alignment The required alignment.
+ */
+ void SetHorizontalAlignment( HorizontalAlignment alignment );
+
+ /**
+ * @brief Query the required text horizontal alignment.
+ *
+ * @return The required alignment.
+ */
+ HorizontalAlignment GetHorizontalAlignment() const;
+
+ /**
+ * @brief Choose the required text vertical alignment.
*
* @param[in] alignment The required alignment.
*/
- void SetAlignment( Alignment alignment );
+ void SetVerticalAlignment( VerticalAlignment alignment );
/**
- * @brief Query the required line alignment.
+ * @brief Query the required text vertical alignment.
*
* @return The required alignment.
*/
- Alignment GetAlignment() const;
+ VerticalAlignment GetVerticalAlignment() const;
/**
* @brief Store the visual position of glyphs in the VisualModel.
void Controller::CalculateTextAlignment( const Size& size )
{
- // TODO : Calculate the vertical offset.
-
// Get the direction of the first character.
const CharacterDirection firstParagraphDirection = mImpl->mLogicalModel->GetCharacterDirection( 0u );
const Size& actualSize = mImpl->mVisualModel->GetActualSize();
// If the first paragraph is right to left swap ALIGN_BEGIN and ALIGN_END;
- LayoutEngine::Alignment alignment = mImpl->mLayoutEngine.GetAlignment();
+ LayoutEngine::HorizontalAlignment horizontalAlignment = mImpl->mLayoutEngine.GetHorizontalAlignment();
if( firstParagraphDirection &&
- ( LayoutEngine::ALIGN_CENTER != alignment ) )
+ ( LayoutEngine::HORIZONTAL_ALIGN_CENTER != horizontalAlignment ) )
{
- if( LayoutEngine::ALIGN_BEGIN == alignment )
+ if( LayoutEngine::HORIZONTAL_ALIGN_BEGIN == horizontalAlignment )
{
- alignment = LayoutEngine::ALIGN_END;
+ horizontalAlignment = LayoutEngine::HORIZONTAL_ALIGN_END;
}
else
{
- alignment = LayoutEngine::ALIGN_BEGIN;
+ horizontalAlignment = LayoutEngine::HORIZONTAL_ALIGN_BEGIN;
}
}
- switch( alignment )
+ switch( horizontalAlignment )
{
- case LayoutEngine::ALIGN_BEGIN:
+ case LayoutEngine::HORIZONTAL_ALIGN_BEGIN:
{
- mImpl->mAlignmentOffset = Vector2::ZERO;
+ mImpl->mAlignmentOffset.x = 0.f;
break;
}
- case LayoutEngine::ALIGN_CENTER:
+ case LayoutEngine::HORIZONTAL_ALIGN_CENTER:
{
- mImpl->mAlignmentOffset.y = 0.f;
const int intOffset = static_cast<int>( 0.5f * ( size.width - actualSize.width ) ); // try to avoid pixel alignment.
mImpl->mAlignmentOffset.x = static_cast<float>( intOffset );
break;
}
- case LayoutEngine::ALIGN_END:
+ case LayoutEngine::HORIZONTAL_ALIGN_END:
{
- mImpl->mAlignmentOffset.y = 0.f;
mImpl->mAlignmentOffset.x = size.width - actualSize.width;
break;
}
}
+
+ const LayoutEngine::VerticalAlignment verticalAlignment = mImpl->mLayoutEngine.GetVerticalAlignment();
+ switch( verticalAlignment )
+ {
+ case LayoutEngine::VERTICAL_ALIGN_TOP:
+ {
+ mImpl->mAlignmentOffset.y = 0.f;
+ break;
+ }
+ case LayoutEngine::VERTICAL_ALIGN_CENTER:
+ {
+ const int intOffset = static_cast<int>( 0.5f * ( size.height - actualSize.height ) ); // try to avoid pixel alignment.
+ mImpl->mAlignmentOffset.y = static_cast<float>( intOffset );
+ break;
+ }
+ case LayoutEngine::VERTICAL_ALIGN_BOTTOM:
+ {
+ mImpl->mAlignmentOffset.y = size.height - actualSize.height;
+ break;
+ }
+ }
}
View& Controller::GetView()
CURSOR_BLINK_DURATION, ///< name "cursor-blink-duration", The cursor will stop blinking after this duration (if non-zero), type FLOAT
GRAB_HANDLE_IMAGE, ///< name "grab-handle-image", The image to display for grab handle, type STRING
DECORATION_BOUNDING_BOX, ///< name "decoration-bounding-box", The decorations (handles etc) will positioned within this area on-screen, type RECTANGLE
- ALIGNMENT, ///< name "alignment", The line alignment, type STRING, values "BEGIN", "CENTER", "END"
+ HORIZONTAL_ALIGNMENT, ///< name "horizontal-alignment", The line horizontal alignment, type STRING, values "BEGIN", "CENTER", "END"
+ VERTICAL_ALIGNMENT ///< name "vertical-alignment", The line vertical alignment, type STRING, values "TOP", "CENTER", "BOTTOM"
};
};
{
enum
{
- RENDERING_BACKEND = PROPERTY_START_INDEX, ///< name "rendering-backend", The type or rendering e.g. bitmap-based, type INT
- TEXT, ///< name "text", The text to display in UTF-8 format, type STRING
- FONT_FAMILY, ///< name "font-family", The requested font family, type STRING
- FONT_STYLE, ///< name "font-style", The requested font style e.g. Regular/Italic, type STRING
- POINT_SIZE, ///< name "point-size", The size of font in points, type FLOAT
- MULTI_LINE, ///< name "multi-line", The single-line or multi-line layout option, type BOOLEAN
- ALIGNMENT, ///< name "alignment", The line alignment, type STRING, values "BEGIN", "CENTER", "END"
+ RENDERING_BACKEND = PROPERTY_START_INDEX, ///< name "rendering-backend", The type or rendering e.g. bitmap-based, type INT
+ TEXT, ///< name "text", The text to display in UTF-8 format, type STRING
+ FONT_FAMILY, ///< name "font-family", The requested font family, type STRING
+ FONT_STYLE, ///< name "font-style", The requested font style e.g. Regular/Italic, type STRING
+ POINT_SIZE, ///< name "point-size", The size of font in points, type FLOAT
+ MULTI_LINE, ///< name "multi-line", The single-line or multi-line layout option, type BOOLEAN
+ HORIZONTAL_ALIGNMENT, ///< name "horizontal-alignment", The line horizontal alignment, type STRING, values "BEGIN", "CENTER", "END"
+ VERTICAL_ALIGNMENT ///< name "vertical-alignment", The line vertical alignment, type STRING, values "TOP", "CENTER", "BOTTOM"
};
};