Diff
diff --git a/cstyle/plugins/flex/main.go b/cstyle/plugins/flex/main.go
index 5a2613c..a151c54 100644
--- a/cstyle/plugins/flex/main.go
+++ b/cstyle/plugins/flex/main.go
@@ -4 +3,0 @@ import (
- "fmt"
@@ -16,6 +15,6 @@ func Init() cstyle.Plugin {
- "display": "flex",
- // "justify-content": "*",
- // "align-content": "*",
- // "align-items": "*",
- // "flex-wrap": "*",
- // "flex-direction": "*",
+ "display": "flex",
+ "justify-content": "*",
+ "align-content": "*",
+ "align-items": "*",
+ "flex-wrap": "*",
+ "flex-direction": "*",
@@ -34 +32,0 @@ func Init() cstyle.Plugin {
- // + issues with the width when notaspans are included
@@ -42,6 +39,0 @@ func Init() cstyle.Plugin {
- // fmt.Println(orderedNode)
- fmt.Println("######")
- for y := range orderedNode[0] {
- fmt.Print(y, " ")
- }
- fmt.Print("\n")
@@ -49,4 +41,19 @@ func Init() cstyle.Plugin {
- for x, row := range orderedNode {
- fmt.Print(x, " ")
- for _, col := range row {
- fmt.Print(col.Properties.Id, " ")
+ // var i int
+
+ colWidth := self.Width / float32(len(orderedNode))
+
+ var xOffset, yOffset float32
+ // if n.Style["justify-content"] == "space-evenly" {
+ // b, _ := utils.ConvertToPixels(n.Children[i].Properties.Border.Width, n.Children[i].Properties.EM, n.Properties.Computed["width"])
+ // cwV := utils.Max((colWidth-(n.Children[i].Properties.Computed["width"]+(b*2)))/2, 0)
+ // xOffset = cwV
+ // }
+
+ posTrack := map[int]int{}
+ p := 0
+
+ for a, column := range orderedNode {
+ var maxColumnHeight float32
+ for _, item := range column {
+ itemState := s[item.Properties.Id]
+ maxColumnHeight = utils.Max(itemState.Height, maxColumnHeight)
@@ -54 +61,46 @@ func Init() cstyle.Plugin {
- fmt.Print("\n")
+
+ yOffset = s[n.Children[0].Properties.Id].Y
+ for _, item := range column {
+ var i int
+ for c, v := range n.Children {
+ if v.Properties.Id == item.Properties.Id {
+ i = c
+ }
+ }
+ posTrack[p] = i
+ p++
+ itemState := s[item.Properties.Id]
+ cState := s[n.Children[i].Properties.Id]
+ // n.Children[i] = item
+ if n.Style["justify-content"] == "space-between" {
+ cwV := utils.Max((colWidth - (itemState.Width)), 0)
+ // fmt.Println(colWidth, (itemState.Width), cwV, xOffset)
+ if a == 0 {
+ cState.X += 0
+ } else if a == len(orderedNode)-1 {
+ cState.X += cwV
+ } else {
+ cState.X += cwV / 2
+ }
+ } else if n.Style["justify-content"] == "flex-end" || n.Style["justify-content"] == "center" {
+ dif := self.Width - (xOffset)
+ if n.Style["justify-content"] == "center" {
+ dif = dif / 2
+ }
+ cState.X += dif
+ } else if n.Style["justify-content"] == "flex-start" || n.Style["justify-content"] == "" {
+ cState.X += xOffset
+ } else {
+ cwV := utils.Max((colWidth-(itemState.Width))/2, 0)
+ var offset float32
+ if n.Style["justify-content"] == "space-evenly" {
+ offset = ((cwV * 2) / float32(len(orderedNode))) * float32(a)
+ }
+ cState.X += xOffset + (cwV - offset)
+ }
+ cState.Y = yOffset
+ yOffset += maxColumnHeight
+ (*state)[n.Children[i].Properties.Id] = cState
+ i++
+ }
+ xOffset += colWidth
@@ -57,3 +109,18 @@ func Init() cstyle.Plugin {
- // c := s[n.Children[0].Properties.Id]
- // c.Width = 100
- // (*state)[n.Children[0].Properties.Id] = c
+ content := n.Style["align-content"]
+
+ if n.Style["flex-direction"] == "column" {
+ content = n.Style["justify-content"]
+ }
+
+ if content != "" && content != "flex-start" {
+ var min, max, rows, col, currY float32
+ min = 1000000000000
+ for _, v := range n.Children {
+ vState := s[v.Properties.Id]
+ min = utils.Min(min, vState.Y)
+ max = utils.Max(max, vState.Height+vState.Y)
+ if vState.Y > currY {
+ rows++
+ currY = vState.Y
+ }
+ }
@@ -60,0 +128,34 @@ func Init() cstyle.Plugin {
+ height := max - min
+ rowHeight := ((self.Height - height) / rows)
+ for e := range n.Children {
+ i := posTrack[e]
+ cState := s[n.Children[i].Properties.Id]
+ row := float32(int(e % int(rows)))
+ if row == 0 {
+ col++
+ }
+ if len(orderedNode[int(col)-1]) <= int(row) {
+ row = 0
+ }
+
+ if content == "center" {
+ cState.Y += (self.Height - height) / 2
+ } else if content == "flex-end" {
+ cState.Y += (self.Height - height)
+ } else if content == "space-around" {
+ cState.Y += (rowHeight * row) + (rowHeight / 2)
+ } else if content == "space-evenly" {
+ cState.Y += (rowHeight * row) + (rowHeight / 2)
+ } else if content == "space-between" {
+ cState.Y += (((self.Height - height) / (rows - 1)) * row)
+ } else if content == "stretch" {
+ cState.Y += (rowHeight * row)
+ if n.Children[i].Style["height"] == "" {
+ cState.Height = self.Height / rows
+ }
+ }
+ (*state)[n.Children[i].Properties.Id] = cState
+
+ }
+
+ }
@@ -67 +167,0 @@ func order(p element.Node, state *map[string]element.State, elements []element.N
- // Get the state of the parent node
@@ -70,2 +169,0 @@ func order(p element.Node, state *map[string]element.State, elements []element.N
-
- // Variables for handling direction and margins
@@ -82,2 +179,0 @@ func order(p element.Node, state *map[string]element.State, elements []element.N
-
- // Get the maximum size in the specified direction
@@ -86 +181,0 @@ func order(p element.Node, state *map[string]element.State, elements []element.N
- // Container for the ordered nodes
@@ -90 +184,0 @@ func order(p element.Node, state *map[string]element.State, elements []element.N
- // If wrapping is enabled
@@ -93 +186,0 @@ func order(p element.Node, state *map[string]element.State, elements []element.N
- // Collect nodes for column direction
@@ -101,2 +193,0 @@ func order(p element.Node, state *map[string]element.State, elements []element.N
-
- // Check if the current element can fit in the current row/column
@@ -120 +210,0 @@ func order(p element.Node, state *map[string]element.State, elements []element.N
- // Collect nodes for row direction
@@ -128,2 +217,0 @@ func order(p element.Node, state *map[string]element.State, elements []element.N
-
- // Check if the current element can fit in the current row/column
@@ -153 +240,0 @@ func order(p element.Node, state *map[string]element.State, elements []element.N
- // If wrapping is not enabled
@@ -165 +252 @@ func order(p element.Node, state *map[string]element.State, elements []element.N
- // Resize nodes to fit
+ // Resize node to fit
@@ -194 +280,0 @@ func order(p element.Node, state *map[string]element.State, elements []element.N
- }
@@ -196 +282 @@ func order(p element.Node, state *map[string]element.State, elements []element.N
- // Update the state of the parent node
+ }