Diff
diff --git a/cstyle/plugins/flex/main.go b/cstyle/plugins/flex/main.go
index e3a40a6..9149f03 100644
--- a/cstyle/plugins/flex/main.go
+++ b/cstyle/plugins/flex/main.go
@@ -8,2 +7,0 @@ import (
- "slices"
- "strings"
@@ -17,2 +14,0 @@ func Init() cstyle.Plugin {
- "flex-wrap": "*",
- "flex-direction": "*",
@@ -25,0 +22 @@ func Init() cstyle.Plugin {
+ siblings := n.Children
@@ -27 +24 @@ func Init() cstyle.Plugin {
- verbs := strings.Split(n.Styles["flex-direction"], "-")
+ fmt.Println(len(siblings))
@@ -29,5 +26,3 @@ func Init() cstyle.Plugin {
- orderedNode := order(*n, n.Children, verbs[0], len(verbs) > 1, n.Styles["flex-wrap"] == "wrap")
-
- fmt.Println("SIASDJAOISJ")
- for i, v := range orderedNode {
- fmt.Println(i, len(v))
+ tW := float32(0)
+ for _, v := range siblings {
+ tW += v.Width + v.Margin.Right + v.Margin.Left
@@ -35,39 +30,6 @@ func Init() cstyle.Plugin {
-
- for _, row := range orderedNode {
- for _, column := range row {
- // add align-content justify-content and align-items logic here
- // the elements are positioned correctly in the ordered array just need to calculate the px positions
- }
- }
- },
- }
-}
-
-func order(p element.Node, elements []element.Node, direction string, reversed, wrap bool) [][]element.Node {
- var dir, marginStart, marginEnd string
- if direction == "column" {
- dir = "Height"
- marginStart = "Top"
- marginEnd = "Bottom"
- } else {
- dir = "Width"
- marginStart = "Left"
- marginEnd = "Right"
- }
- max, _ := utils.GetStructField(&p, dir)
-
- nodes := [][]element.Node{}
-
- if wrap {
- counter := 0
- collector := []element.Node{}
- for _, v := range elements {
- elMax, _ := utils.GetStructField(&v, dir)
- elMS, _ := utils.GetStructField(&v.Margin, marginStart)
- elME, _ := utils.GetStructField(&v.Margin, marginEnd)
- tMax := elMax.(float32) + elMS.(float32) + elME.(float32)
- if counter+int(tMax) < int(max.(float32)) {
- collector = append(collector, v)
- } else {
- if reversed {
- slices.Reverse(collector)
+ if tW > n.Width {
+ fmt.Println("TOO BIG", tW/float32(len(siblings)))
+ newSize := n.Width / float32(len(siblings))
+ tW = n.Width
+ for i := range siblings {
+ n.Children[i].Width = newSize
@@ -75,4 +36,0 @@ func order(p element.Node, elements []element.Node, direction string, reversed,
- nodes = append(nodes, collector)
- collector = []element.Node{}
- collector = append(collector, v)
- counter = 0
@@ -80,37 +38,8 @@ func order(p element.Node, elements []element.Node, direction string, reversed,
- counter += int(tMax)
- }
- if len(collector) > 0 {
- nodes = append(nodes, collector)
- }
- } else {
- var tMax float32
- for _, v := range elements {
- elMax, _ := utils.GetStructField(&v, dir)
- elMS, _ := utils.GetStructField(&v.Margin, marginStart)
- elME, _ := utils.GetStructField(&v.Margin, marginEnd)
- tMax += elMax.(float32) + elMS.(float32) + elME.(float32)
- }
-
- pMax, _ := utils.GetStructField(&p, dir)
-
- // Resize node to fit
- if tMax > pMax.(float32) {
- newSize := pMax.(float32) / float32(len(elements))
-
- if dir == "Width" {
- for _, v := range elements {
- v.Width = newSize
- nodes = append(nodes, []element.Node{v})
- }
- if reversed {
- slices.Reverse(nodes)
- }
- } else {
- nodes = append(nodes, []element.Node{})
- for _, v := range elements {
- v.Height = newSize
- nodes[0] = append(nodes[0], v)
- }
- if reversed {
- slices.Reverse(nodes[0])
- }
+ fmt.Println(n.Width, tW)
+
+ fmt.Println(n.Styles["justify-content"])
+ y := siblings[0].Y
+ for i := range siblings {
+ fmt.Println(n.Children[i].Width)
+ n.Children[i].X += (((n.Width - tW) / float32(len(siblings))) * float32(i)) + (n.Children[i].Width * float32(i))
+ n.Children[i].Y = y
@@ -118 +47 @@ func order(p element.Node, elements []element.Node, direction string, reversed,
- }
+ },
@@ -120,2 +48,0 @@ func order(p element.Node, elements []element.Node, direction string, reversed,
-
- return nodes