diff --git a/cstyle/plugins/inline/main.go b/cstyle/plugins/inline/main.go
index ee21694..f750a58 100644
--- a/cstyle/plugins/inline/main.go
+++ b/cstyle/plugins/inline/main.go
@@ -4 +3,0 @@ import (
- "fmt"
@@ -7 +5,0 @@ import (
- "math"
@@ -40 +38 @@ func Init() cstyle.Plugin {
- if sibling.X+sibling.Width+self.Width > (parent.Width)+parent.X {
+ if sibling.X+sibling.Width+self.Width > ((parent.Width)-parent.Padding.Right)+parent.X {
@@ -44 +41,0 @@ func Init() cstyle.Plugin {
- fmt.Println(n.InnerText, sibling.X+sibling.Width, self.Width)
@@ -54,24 +50,0 @@ func Init() cstyle.Plugin {
- // !ISSUE: should prob only tgt elements with text
- baseY := sibling.Y
- var max float32
- for a := i; a >= 0; a-- {
- b := n.Parent.Children[a]
- bStyle := s[b.Properties.Id]
- if bStyle.Y == baseY {
- if bStyle.EM > max {
- max = bStyle.EM
- }
- }
- }
-
- for a := i; a >= 0; a-- {
- b := n.Parent.Children[a]
- bStyle := s[b.Properties.Id]
- if bStyle.Y == baseY {
- bStyle.Y += (float32(math.Ceil(float64((max - (max * 0.3))))) - float32(math.Ceil(float64(bStyle.EM-(bStyle.EM*0.3)))))
- (*state)[b.Properties.Id] = bStyle
- }
- }
- if self.Y == baseY {
- self.Y += (float32(math.Ceil(float64((max - (max * 0.3))))) - float32(math.Ceil(float64(self.EM-(self.EM*0.3)))))
- }
package inline
import (
"fmt"
"gui/cstyle"
"gui/element"
"math"
)
func Init() cstyle.Plugin {
return cstyle.Plugin{
Selector: func(n *element.Node) bool {
styles := map[string]string{
"display": "inline",
}
matches := true
for name, value := range styles {
if n.Style[name] != value && !(value == "*") && n.Style[name] != "" {
matches = false
}
}
return matches
},
Level: 1,
Handler: func(n *element.Node, state *map[string]element.State) {
s := *state
self := s[n.Properties.Id]
parent := s[n.Parent.Properties.Id]
copyOfX := self.X
copyOfY := self.Y
// xCollect := float32(0)
for i, v := range n.Parent.Children {
// vState := s[v.Properties.Id]
if i > 0 {
if v.Style["position"] != "absolute" {
if v.Properties.Id == n.Properties.Id {
sib := n.Parent.Children[i-1]
sibling := s[sib.Properties.Id]
if sibling.X+sibling.Width+self.Width > (parent.Width)+parent.X {
// Break Node.Id
self.Y = sibling.Y + sibling.Height
self.X = copyOfX
fmt.Println(n.InnerText, sibling.X+sibling.Width, self.Width)
} else {
// Node did not break
if sib.Style["display"] != "inline" {
self.Y = sibling.Y + sibling.Height
} else {
self.Y = sibling.Y
self.X = sibling.X + sibling.Width
}
}
// !ISSUE: should prob only tgt elements with text
baseY := sibling.Y
var max float32
for a := i; a >= 0; a-- {
b := n.Parent.Children[a]
bStyle := s[b.Properties.Id]
if bStyle.Y == baseY {
if bStyle.EM > max {
max = bStyle.EM
}
}
}
for a := i; a >= 0; a-- {
b := n.Parent.Children[a]
bStyle := s[b.Properties.Id]
if bStyle.Y == baseY {
bStyle.Y += (float32(math.Ceil(float64((max - (max * 0.3))))) - float32(math.Ceil(float64(bStyle.EM-(bStyle.EM*0.3)))))
(*state)[b.Properties.Id] = bStyle
}
}
if self.Y == baseY {
self.Y += (float32(math.Ceil(float64((max - (max * 0.3))))) - float32(math.Ceil(float64(self.EM-(self.EM*0.3)))))
}
break
}
}
}
}
propagateOffsets(n, copyOfX, copyOfY, self, state)
(*state)[n.Properties.Id] = self
},
}
}
func propagateOffsets(n *element.Node, copyOfX, copyOfY float32, self element.State, state *map[string]element.State) {
s := *state
for _, v := range n.Children {
vState := s[v.Properties.Id]
vState.X += self.X - copyOfX
vState.Y += self.Y - copyOfY
if len(v.Children) > 0 {
propagateOffsets(v, copyOfX, copyOfY, self, state)
}
(*state)[v.Properties.Id] = vState
}
}
// func colliderDetection(s1, s2 element.State) bool {
// s1Min := s1.Y
// s1Max := s1.Y + s1.Height
// s2Min := s2.Y
// s2Max := s2.Y + s2.Height
// return s1Min > s2Min && s1Min < s2Max || s1Max > s2Min && s1Min < s2Max || s2Min > s1Min && s2Min < s1Max || s2Max > s1Min && s2Min < s1Max
// }