diff --git a/code/nel/include/nel/gui/group_paragraph.h b/code/nel/include/nel/gui/group_paragraph.h index 6142bc33b..e7baf249b 100644 --- a/code/nel/include/nel/gui/group_paragraph.h +++ b/code/nel/include/nel/gui/group_paragraph.h @@ -54,6 +54,8 @@ namespace NLGUI Right }; + enum TTextAlign { AlignLeft = 0, AlignCenter, AlignRight, AlignJustify }; + ///constructor CGroupParagraph(const TCtorParam ¶m); @@ -97,6 +99,8 @@ namespace NLGUI // the same, but with id taken from the database void addTextChildID (const std::string &dbPath, bool multiLine = true); + void setTextAlign(const TTextAlign align) { _TextAlign = align; } + protected: void delChild (CViewBase* child); @@ -270,6 +274,9 @@ namespace NLGUI // (the element drawn are stored in _views, _contrlos or _childrengroups of cinterfacegroup std::vector _Elements; + // Horizontal align for elements + TTextAlign _TextAlign; + // Last parent width sint32 _LastW; diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index 5651f9496..3ec392113 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -2548,6 +2548,17 @@ namespace NLGUI newParagraph->setResizeFromChildH(true); newParagraph->setMarginLeft(getIndent()); + if (!_Style.Current.TextAlign.empty()) + { + if (_Style.Current.TextAlign == "left") + newParagraph->setTextAlign(CGroupParagraph::AlignLeft); + else if (_Style.Current.TextAlign == "center") + newParagraph->setTextAlign(CGroupParagraph::AlignCenter); + else if (_Style.Current.TextAlign == "right") + newParagraph->setTextAlign(CGroupParagraph::AlignRight); + else if (_Style.Current.TextAlign == "justify") + newParagraph->setTextAlign(CGroupParagraph::AlignJustify); + } // Add to the group addHtmlGroup (newParagraph, beginSpace); @@ -5405,6 +5416,11 @@ namespace NLGUI cellParams.Align = CGroupCell::Center; else if (align == "right") cellParams.Align = CGroupCell::Right; + else if (align != "justify") + align.clear(); + + // copy td align (can be empty) attribute back into css + _Style.Current.TextAlign = align; } { diff --git a/code/nel/src/gui/group_paragraph.cpp b/code/nel/src/gui/group_paragraph.cpp index 9424c0218..f96a3d87a 100644 --- a/code/nel/src/gui/group_paragraph.cpp +++ b/code/nel/src/gui/group_paragraph.cpp @@ -713,6 +713,10 @@ namespace NLGUI CViewText *viewText = dynamic_cast(_Elements[i].Element); if (viewText) { + // FIXME: this does not work with multiple view text on same line + if (_TextAlign == AlignCenter && elmCount == 1) + viewText->setTextMode(CViewText::Centered); + viewText->setFirstLineX(x + ((i==0)?_FirstViewIndentView:0)); viewText->setX(0); viewText->updateTextContext(); @@ -730,6 +734,12 @@ namespace NLGUI // Does we balance the last line height ? if (viewText) { + if (_TextAlign == AlignCenter && elmCount == 1) + { + sint pad = width - viewText->getWReal(); + viewText->setX(pad/2); + } + changeLine = viewText->getNumLine() > 1; if (!viewText->getText().empty() && *(viewText->getText().rbegin()) == (ucchar) '\n') {