From 7184df4a1473832426af4f2f4fbac10ebc5ac301 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 4 Dec 2019 04:54:57 +0100 Subject: [PATCH] Add StyleStack.Indent and .With --- style.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/style.go b/style.go index 3bbb19c..59e4546 100644 --- a/style.go +++ b/style.go @@ -70,12 +70,29 @@ func (s *StyleStack) Pop() { *s = stack } +func (s StyleStack) Indent() uint { + var i uint + + for _, v := range s { + if v == nil { + continue + } + i += v.Indent + } + + return i +} + func (s StyleStack) Current() *ElementStyle { if len(s) == 0 { return nil } - return s[len(s)-1] + return cascadeStyles(s[0:len(s)-1], s[len(s)-1]) +} + +func (s StyleStack) With(child *ElementStyle) *ElementStyle { + return cascadeStyles(s, child) } func cascadeStyle(parent *ElementStyle, child *ElementStyle) *ElementStyle {