diff --git a/code/nel/include/nel/gui/css_style.h b/code/nel/include/nel/gui/css_style.h index 94d86bf5d..50dd3180a 100644 --- a/code/nel/include/nel/gui/css_style.h +++ b/code/nel/include/nel/gui/css_style.h @@ -70,6 +70,7 @@ namespace NLGUI // background BackgroundColor=NLMISC::CRGBA::Black; BackgroundColorOver=NLMISC::CRGBA::Black; + PaddingTop = PaddingRight = PaddingBottom = PaddingLeft = 0; } bool hasStyle(const std::string &key) const @@ -103,6 +104,7 @@ namespace NLGUI NLMISC::CRGBA BorderTopColor, BorderRightColor, BorderBottomColor, BorderLeftColor; NLMISC::CRGBA BackgroundColor; NLMISC::CRGBA BackgroundColorOver; + uint32 PaddingTop, PaddingRight, PaddingBottom, PaddingLeft; std::string WhiteSpace; std::string TextAlign; @@ -168,10 +170,14 @@ namespace NLGUI // parse 'background' into 'background-color', 'background-image', etc void parseBackgroundShorthand(const std::string &value, CStyleParams &style) const; + // parse 'padding' into 'padding-top', 'padding-left', etc + void parsePaddingShorthand(const std::string &value, CStyleParams &style) const; + // parse string value into corresponding value void applyBorderWidth(const std::string &value, uint32 *dest, const uint32 currentWidth, const uint32 fontSize) const; void applyBorderColor(const std::string &value, NLMISC::CRGBA *dest, const NLMISC::CRGBA ¤tColor, const NLMISC::CRGBA &textColor) const; void applyLineStyle(const std::string &value, CSSLineStyle *dest, const CSSLineStyle ¤tStyle) const; + void applyPaddingWidth(const std::string &value, uint32 *dest, const uint32 currentPadding, uint32 fontSize) const; public: void reset(); @@ -206,6 +212,7 @@ namespace NLGUI Current.BorderTopWidth = Current.BorderRightWidth = Current.BorderBottomWidth = Current.BorderLeftWidth = CSSLineWidth::MEDIUM; Current.BorderTopStyle = Current.BorderRightStyle = Current.BorderBottomStyle = Current.BorderLeftStyle = CSSLineStyle::NONE; Current.BorderTopColor = Current.BorderRightColor = Current.BorderBottomColor = Current.BorderLeftColor = Current.TextColor; + Current.PaddingTop = Current.PaddingRight = Current.PaddingBottom = Current.PaddingLeft = 0; Current.StyleRules.clear(); } diff --git a/code/nel/include/nel/gui/group_table.h b/code/nel/include/nel/gui/group_table.h index e45575e47..ccc2ce3cf 100644 --- a/code/nel/include/nel/gui/group_table.h +++ b/code/nel/include/nel/gui/group_table.h @@ -94,6 +94,7 @@ namespace NLGUI NLMISC::CRGBA BgColor; CSSBorderRenderer* Border; + uint32 PaddingTop, PaddingRight, PaddingBottom, PaddingLeft; // Texture CViewRenderer::CTextureId _TextureId; @@ -120,6 +121,9 @@ namespace NLGUI void setTextureTile(bool tiled); void setTextureScale(bool scaled); + uint32 getPaddingLeftRight() const { return PaddingLeft + PaddingRight; }; + uint32 getPaddingTopBottom() const { return PaddingTop + PaddingBottom; }; + virtual void updateCoords(); static void setDebugUICell( bool d ){ DebugUICell = d; } diff --git a/code/nel/src/gui/css_style.cpp b/code/nel/src/gui/css_style.cpp index 72c9701df..888044e5c 100644 --- a/code/nel/src/gui/css_style.cpp +++ b/code/nel/src/gui/css_style.cpp @@ -493,6 +493,12 @@ namespace NLGUI else style.DisplayBlock = (it->second == "block" || it->second == "table"); } + else + if (it->first == "padding") + { + parsePaddingShorthand(it->second, style); + keep = false; + } if (!keep) { @@ -578,6 +584,33 @@ namespace NLGUI *dest = CSSLineStyle::SOLID; } + void CCssStyle::applyPaddingWidth(const std::string &value, uint32 *dest, const uint32 currentPadding, uint32 fontSize) const + { + if (!dest) return; + + if (value == "inherit") + { + *dest = currentPadding; + return; + } + + float tmpf; + std::string unit; + if (getCssLength(tmpf, unit, value.c_str())) + { + if (unit == "rem") + *dest = fontSize * tmpf; + else if (unit == "em") + *dest = fontSize * tmpf; + else if (unit == "pt") + *dest = tmpf / 0.75f; + else if (unit == "%") + *dest = 0; // TODO: requires content width, must remember 'unit' type + else + *dest = tmpf; + } + } + // apply style rules void CCssStyle::apply(CStyleParams &style, const CStyleParams ¤t) const { @@ -597,6 +630,10 @@ namespace NLGUI else if (it->first == "border-left-width") applyBorderWidth(it->second, &style.BorderLeftWidth, current.BorderLeftWidth, current.FontSize); else if (it->first == "border-left-color") applyBorderColor(it->second, &style.BorderLeftColor, current.BorderLeftColor, current.TextColor); else if (it->first == "border-left-style") applyLineStyle(it->second, &style.BorderLeftStyle, current.BorderLeftStyle); + else if (it->first == "padding-top") applyPaddingWidth(it->second, &style.PaddingTop, current.PaddingTop, current.FontSize); + else if (it->first == "padding-right") applyPaddingWidth(it->second, &style.PaddingRight, current.PaddingRight, current.FontSize); + else if (it->first == "padding-bottom") applyPaddingWidth(it->second, &style.PaddingBottom, current.PaddingBottom, current.FontSize); + else if (it->first == "padding-left") applyPaddingWidth(it->second, &style.PaddingLeft, current.PaddingLeft, current.FontSize); else if (it->first == "font-style") { @@ -1507,6 +1544,22 @@ namespace NLGUI } } + // *************************************************************************** + void CCssStyle::parsePaddingShorthand(const std::string &value, CStyleParams &style) const + { + std::vector parts; + NLMISC::splitString(toLower(value), " ", parts); + + uint8 t, r, b, l; + if (!getShorthandIndices(parts.size(), t, r, b, l)) + return; + + style.StyleRules["padding-top"] = parts[t]; + style.StyleRules["padding-right"] = parts[r]; + style.StyleRules["padding-bottom"] = parts[b]; + style.StyleRules["padding-left"] = parts[l]; + } + // *************************************************************************** void CCssStyle::applyCssMinMax(sint32 &width, sint32 &height, sint32 minw, sint32 minh, sint32 maxw, sint32 maxh) const { diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index 1a129ebae..5b641647d 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -6682,14 +6682,6 @@ namespace NLGUI return; } - if (_Style.hasStyle("padding")) - { - uint32 a; - // TODO: cssLength - if (fromString(_Style.getStyle("padding"), a)) - table->CellPadding = a; - } - _Cells.back() = new CGroupCell(CViewBase::TCtorParam()); if (_Style.checkStyle("background-repeat", "repeat")) @@ -6757,6 +6749,20 @@ namespace NLGUI if (_Style.hasStyle("border-bottom-style")) _Cells.back()->Border->BottomStyle = _Style.Current.BorderBottomStyle; if (_Style.hasStyle("border-left-style")) _Cells.back()->Border->LeftStyle = _Style.Current.BorderLeftStyle; + // padding from + if (table->CellPadding) + { + _Cells.back()->PaddingTop = table->CellPadding; + _Cells.back()->PaddingRight = table->CellPadding; + _Cells.back()->PaddingBottom = table->CellPadding; + _Cells.back()->PaddingLeft = table->CellPadding; + } + + if (_Style.hasStyle("padding-top")) _Cells.back()->PaddingTop = _Style.Current.PaddingTop; + if (_Style.hasStyle("padding-right")) _Cells.back()->PaddingRight = _Style.Current.PaddingRight; + if (_Style.hasStyle("padding-bottom")) _Cells.back()->PaddingBottom = _Style.Current.PaddingBottom; + if (_Style.hasStyle("padding-left")) _Cells.back()->PaddingLeft = _Style.Current.PaddingLeft; + table->addChild (_Cells.back()); // reusing indent pushed by table diff --git a/code/nel/src/gui/group_table.cpp b/code/nel/src/gui/group_table.cpp index c268e2bfc..98ad6fcfc 100644 --- a/code/nel/src/gui/group_table.cpp +++ b/code/nel/src/gui/group_table.cpp @@ -55,6 +55,7 @@ namespace NLGUI Group = new CInterfaceGroup(CViewBase::TCtorParam()); // TODO: only initialize if border is set Border = new CSSBorderRenderer(); + PaddingTop = PaddingRight = PaddingBottom = PaddingLeft = 0; Align = Left; VAlign = Middle; LeftMargin = 0;