Add initial support for centered multiline text in table

feature/develop-atys
Nimetu 4 years ago
parent aaa699014e
commit acd12c7c37

@ -55,6 +55,8 @@ namespace NLGUI
Right Right
}; };
enum TTextAlign { AlignLeft = 0, AlignCenter, AlignRight, AlignJustify };
///constructor ///constructor
CGroupParagraph(const TCtorParam &param); CGroupParagraph(const TCtorParam &param);
@ -98,6 +100,8 @@ namespace NLGUI
// the same, but with id taken from the database // the same, but with id taken from the database
void addTextChildID (const std::string &dbPath, bool multiLine = true); void addTextChildID (const std::string &dbPath, bool multiLine = true);
void setTextAlign(const TTextAlign align) { _TextAlign = align; }
protected: protected:
void delChild (CViewBase* child); void delChild (CViewBase* child);
@ -271,6 +275,9 @@ namespace NLGUI
// (the element drawn are stored in _views, _contrlos or _childrengroups of cinterfacegroup // (the element drawn are stored in _views, _contrlos or _childrengroups of cinterfacegroup
std::vector<CElementInfo> _Elements; std::vector<CElementInfo> _Elements;
// Horizontal align for elements
TTextAlign _TextAlign;
// Last parent width // Last parent width
sint32 _LastW; sint32 _LastW;

@ -2158,6 +2158,17 @@ namespace NLGUI
newParagraph->setResizeFromChildH(true); newParagraph->setResizeFromChildH(true);
newParagraph->setMarginLeft(getIndent()); 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 // Add to the group
addHtmlGroup (newParagraph, beginSpace); addHtmlGroup (newParagraph, beginSpace);
@ -4986,6 +4997,11 @@ namespace NLGUI
cellParams.Align = CGroupCell::Center; cellParams.Align = CGroupCell::Center;
else if (align == "right") else if (align == "right")
cellParams.Align = CGroupCell::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;
} }
{ {

@ -65,6 +65,7 @@ namespace NLGUI
_Indent = 0; _Indent = 0;
_FirstViewIndentView = false; _FirstViewIndentView = false;
_TextId = 0; _TextId = 0;
_TextAlign = AlignLeft;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -713,6 +714,10 @@ namespace NLGUI
CViewText *viewText = dynamic_cast<CViewText*>(_Elements[i].Element); CViewText *viewText = dynamic_cast<CViewText*>(_Elements[i].Element);
if (viewText) 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->setFirstLineX(x + ((i==0)?_FirstViewIndentView:0));
viewText->setX(0); viewText->setX(0);
viewText->updateTextContext(); viewText->updateTextContext();
@ -730,6 +735,12 @@ namespace NLGUI
// Does we balance the last line height ? // Does we balance the last line height ?
if (viewText) if (viewText)
{ {
if (_TextAlign == AlignCenter && elmCount == 1)
{
sint pad = width - viewText->getWReal();
viewText->setX(pad/2);
}
changeLine = viewText->getNumLine() > 1; changeLine = viewText->getNumLine() > 1;
if (!viewText->getText().empty() && *(viewText->getText().rbegin()) == '\n') if (!viewText->getText().empty() && *(viewText->getText().rbegin()) == '\n')
{ {

Loading…
Cancel
Save