From acd12c7c37f8deb35c847f0395f955dba008f242 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Tue, 4 May 2021 21:45:47 +0300 Subject: [PATCH] Add initial support for centered multiline text in table --- nel/include/nel/gui/group_paragraph.h | 7 +++++++ nel/src/gui/group_html.cpp | 16 ++++++++++++++++ nel/src/gui/group_paragraph.cpp | 11 +++++++++++ 3 files changed, 34 insertions(+) diff --git a/nel/include/nel/gui/group_paragraph.h b/nel/include/nel/gui/group_paragraph.h index 20bc50585..b05d4e12e 100644 --- a/nel/include/nel/gui/group_paragraph.h +++ b/nel/include/nel/gui/group_paragraph.h @@ -55,6 +55,8 @@ namespace NLGUI Right }; + enum TTextAlign { AlignLeft = 0, AlignCenter, AlignRight, AlignJustify }; + ///constructor CGroupParagraph(const TCtorParam ¶m); @@ -98,6 +100,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); @@ -271,6 +275,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/nel/src/gui/group_html.cpp b/nel/src/gui/group_html.cpp index 179232566..a95914ef6 100644 --- a/nel/src/gui/group_html.cpp +++ b/nel/src/gui/group_html.cpp @@ -2158,6 +2158,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); @@ -4986,6 +4997,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/nel/src/gui/group_paragraph.cpp b/nel/src/gui/group_paragraph.cpp index 4ca13c8ae..623975b98 100644 --- a/nel/src/gui/group_paragraph.cpp +++ b/nel/src/gui/group_paragraph.cpp @@ -65,6 +65,7 @@ namespace NLGUI _Indent = 0; _FirstViewIndentView = false; _TextId = 0; + _TextAlign = AlignLeft; } // ---------------------------------------------------------------------------- @@ -713,6 +714,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 +735,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()) == '\n') {