Skip to content

Commit

Permalink
fix loop children
Browse files Browse the repository at this point in the history
  • Loading branch information
janczer committed Mar 14, 2017
1 parent 3f1c306 commit a87ebcf
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions box.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ func NewLayoutBox(boxType interface{}, style StyleNode) *LayoutBox {

func (s LayoutBox) print(l int) {
tab(l)
fmt.Printf("dimensions %v\n", s.dimensions)
fmt.Printf("dimensions %+v\n", s.dimensions)
tab(l)
fmt.Printf("box type %#v\n", s.box_type)
tab(l)
fmt.Printf("style %v\n", s.style)
tab(l)
fmt.Printf("childrens: \n")
//tab(l)
//fmt.Printf("style %v\n", s.style)
//tab(l)
//fmt.Printf("childrens: \n")
l++
for i := 0; i < len(s.children); i++ {
s.children[i].print(l + 1)
Expand Down Expand Up @@ -151,19 +151,23 @@ func buildLayoutTree(styleNode StyleNode) *LayoutBox {
style: styleNode,
}

for _, child := range styleNode.children {
for i := 0; i < len(styleNode.children); i++ {
child := styleNode.children[i]
display = child.display()
switch display {
case "block":
childLayoutTree := buildLayoutTree(child)
l.children[len(l.children)] = childLayoutTree
case "inline":
boxT := l.getLastContainer().box_type
lastContainer := l.getLastContainer()
boxT := lastContainer.box_type
fmt.Printf("last container %#v\n", boxT)
//add anonymous box
switch boxT.(type) {
case AnonymousBlock, InlineNode:
childLayoutTree := buildLayoutTree(child)
l.children[len(l.children)] = childLayoutTree

lastContainer.children[len(lastContainer.children)] = childLayoutTree
case BlockNode:
//create AnonymousBlock
anonymous := LayoutBox{
Expand Down Expand Up @@ -238,6 +242,8 @@ func (l *LayoutBox) inlineBox(containBlock *Dimensions) {
//l.dimensions.content.y = containBlock.content.height
d := &l.dimensions

//calculate box width

for _, child := range l.children {
child.layout(d)
}
Expand Down

0 comments on commit a87ebcf

Please sign in to comment.