Added: Table cell independent padding.

--HG--
branch : html-improvements
hg/feature/html-improvements
Nimetu 5 years ago
parent 1a98c83080
commit 0fb06e0ff3

@ -70,6 +70,7 @@ namespace NLGUI
// background // background
BackgroundColor=NLMISC::CRGBA::Black; BackgroundColor=NLMISC::CRGBA::Black;
BackgroundColorOver=NLMISC::CRGBA::Black; BackgroundColorOver=NLMISC::CRGBA::Black;
PaddingTop = PaddingRight = PaddingBottom = PaddingLeft = 0;
} }
bool hasStyle(const std::string &key) const bool hasStyle(const std::string &key) const
@ -103,6 +104,7 @@ namespace NLGUI
NLMISC::CRGBA BorderTopColor, BorderRightColor, BorderBottomColor, BorderLeftColor; NLMISC::CRGBA BorderTopColor, BorderRightColor, BorderBottomColor, BorderLeftColor;
NLMISC::CRGBA BackgroundColor; NLMISC::CRGBA BackgroundColor;
NLMISC::CRGBA BackgroundColorOver; NLMISC::CRGBA BackgroundColorOver;
uint32 PaddingTop, PaddingRight, PaddingBottom, PaddingLeft;
std::string WhiteSpace; std::string WhiteSpace;
std::string TextAlign; std::string TextAlign;
@ -168,10 +170,14 @@ namespace NLGUI
// parse 'background' into 'background-color', 'background-image', etc // parse 'background' into 'background-color', 'background-image', etc
void parseBackgroundShorthand(const std::string &value, CStyleParams &style) const; 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 // parse string value into corresponding value
void applyBorderWidth(const std::string &value, uint32 *dest, const uint32 currentWidth, const uint32 fontSize) const; 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 &currentColor, const NLMISC::CRGBA &textColor) const; void applyBorderColor(const std::string &value, NLMISC::CRGBA *dest, const NLMISC::CRGBA &currentColor, const NLMISC::CRGBA &textColor) const;
void applyLineStyle(const std::string &value, CSSLineStyle *dest, const CSSLineStyle &currentStyle) const; void applyLineStyle(const std::string &value, CSSLineStyle *dest, const CSSLineStyle &currentStyle) const;
void applyPaddingWidth(const std::string &value, uint32 *dest, const uint32 currentPadding, uint32 fontSize) const;
public: public:
void reset(); void reset();
@ -206,6 +212,7 @@ namespace NLGUI
Current.BorderTopWidth = Current.BorderRightWidth = Current.BorderBottomWidth = Current.BorderLeftWidth = CSSLineWidth::MEDIUM; Current.BorderTopWidth = Current.BorderRightWidth = Current.BorderBottomWidth = Current.BorderLeftWidth = CSSLineWidth::MEDIUM;
Current.BorderTopStyle = Current.BorderRightStyle = Current.BorderBottomStyle = Current.BorderLeftStyle = CSSLineStyle::NONE; Current.BorderTopStyle = Current.BorderRightStyle = Current.BorderBottomStyle = Current.BorderLeftStyle = CSSLineStyle::NONE;
Current.BorderTopColor = Current.BorderRightColor = Current.BorderBottomColor = Current.BorderLeftColor = Current.TextColor; Current.BorderTopColor = Current.BorderRightColor = Current.BorderBottomColor = Current.BorderLeftColor = Current.TextColor;
Current.PaddingTop = Current.PaddingRight = Current.PaddingBottom = Current.PaddingLeft = 0;
Current.StyleRules.clear(); Current.StyleRules.clear();
} }

@ -94,6 +94,7 @@ namespace NLGUI
NLMISC::CRGBA BgColor; NLMISC::CRGBA BgColor;
CSSBorderRenderer* Border; CSSBorderRenderer* Border;
uint32 PaddingTop, PaddingRight, PaddingBottom, PaddingLeft;
// Texture // Texture
CViewRenderer::CTextureId _TextureId; CViewRenderer::CTextureId _TextureId;
@ -120,6 +121,9 @@ namespace NLGUI
void setTextureTile(bool tiled); void setTextureTile(bool tiled);
void setTextureScale(bool scaled); void setTextureScale(bool scaled);
uint32 getPaddingLeftRight() const { return PaddingLeft + PaddingRight; };
uint32 getPaddingTopBottom() const { return PaddingTop + PaddingBottom; };
virtual void updateCoords(); virtual void updateCoords();
static void setDebugUICell( bool d ){ DebugUICell = d; } static void setDebugUICell( bool d ){ DebugUICell = d; }

@ -493,6 +493,12 @@ namespace NLGUI
else else
style.DisplayBlock = (it->second == "block" || it->second == "table"); style.DisplayBlock = (it->second == "block" || it->second == "table");
} }
else
if (it->first == "padding")
{
parsePaddingShorthand(it->second, style);
keep = false;
}
if (!keep) if (!keep)
{ {
@ -578,6 +584,33 @@ namespace NLGUI
*dest = CSSLineStyle::SOLID; *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 // apply style rules
void CCssStyle::apply(CStyleParams &style, const CStyleParams &current) const void CCssStyle::apply(CStyleParams &style, const CStyleParams &current) 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-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-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 == "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 else
if (it->first == "font-style") if (it->first == "font-style")
{ {
@ -1507,6 +1544,22 @@ namespace NLGUI
} }
} }
// ***************************************************************************
void CCssStyle::parsePaddingShorthand(const std::string &value, CStyleParams &style) const
{
std::vector<std::string> 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 void CCssStyle::applyCssMinMax(sint32 &width, sint32 &height, sint32 minw, sint32 minh, sint32 maxw, sint32 maxh) const
{ {

@ -6682,14 +6682,6 @@ namespace NLGUI
return; return;
} }
if (_Style.hasStyle("padding"))
{
uint32 a;
// TODO: cssLength
if (fromString(_Style.getStyle("padding"), a))
table->CellPadding = a;
}
_Cells.back() = new CGroupCell(CViewBase::TCtorParam()); _Cells.back() = new CGroupCell(CViewBase::TCtorParam());
if (_Style.checkStyle("background-repeat", "repeat")) 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-bottom-style")) _Cells.back()->Border->BottomStyle = _Style.Current.BorderBottomStyle;
if (_Style.hasStyle("border-left-style")) _Cells.back()->Border->LeftStyle = _Style.Current.BorderLeftStyle; if (_Style.hasStyle("border-left-style")) _Cells.back()->Border->LeftStyle = _Style.Current.BorderLeftStyle;
// padding from <table cellpadding="1">
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()); table->addChild (_Cells.back());
// reusing indent pushed by table // reusing indent pushed by table

@ -55,6 +55,7 @@ namespace NLGUI
Group = new CInterfaceGroup(CViewBase::TCtorParam()); Group = new CInterfaceGroup(CViewBase::TCtorParam());
// TODO: only initialize if border is set // TODO: only initialize if border is set
Border = new CSSBorderRenderer(); Border = new CSSBorderRenderer();
PaddingTop = PaddingRight = PaddingBottom = PaddingLeft = 0;
Align = Left; Align = Left;
VAlign = Middle; VAlign = Middle;
LeftMargin = 0; LeftMargin = 0;

Loading…
Cancel
Save