Quellcode durchsuchen

gridlayout / gui builder dev

leonsal vor 8 Jahren
Ursprung
Commit
e3bda8e2f9
2 geänderte Dateien mit 16 neuen und 7 gelöschten Zeilen
  1. 0 2
      gui/builder.go
  2. 16 5
      gui/gridlayout.go

+ 0 - 2
gui/builder.go

@@ -939,7 +939,6 @@ func (b *Builder) setLayoutParams(dp *descPanel, ipan IPanel) error {
 			AlignH:  AlignNone,
 			AlignV:  AlignNone,
 		}
-		log.Error("colspan:%v", dlp.ColSpan)
 		params.ColSpan = dlp.ColSpan
 		// Sets optional alignh parameter
 		if dlp.AlignH != "" {
@@ -1010,7 +1009,6 @@ func (b *Builder) setLayout(dp *descPanel, ipan IPanel) error {
 
 	// Grid layout
 	if dl.Type == descTypeGridLayout {
-		log.Error("set grid layout")
 		// Number of columns
 		if dl.Cols == 0 {
 			return b.err("cols", "Invalid number of columns:"+dl.AlignH)

+ 16 - 5
gui/gridlayout.go

@@ -168,6 +168,7 @@ func (g *GridLayout) Recalc(ipan IPanel) {
 	// Sets the height of each row to the height of the heightest child
 	// Sets the width of each column to the width of the widest column
 	colWidths := make([]float32, len(g.columns))
+	spanWidths := make([]float32, len(g.columns))
 	for i := 0; i < len(rows); i++ {
 		r := &rows[i]
 		r.height = 0
@@ -178,15 +179,25 @@ func (g *GridLayout) Recalc(ipan IPanel) {
 			if cell.panel.Height() > r.height {
 				r.height = cell.panel.Height()
 			}
-			// If cell span columns, ignore this cell when computing column width
+			// If this cell span columns compare with other span cell widths
 			if cell.params.ColSpan > 0 {
-				continue
-			}
-			if cell.panel.Width() > colWidths[ci] {
-				colWidths[ci] = cell.panel.Width()
+				if cell.panel.Width() > spanWidths[ci] {
+					spanWidths[ci] = cell.panel.Width()
+				}
+			} else {
+				if cell.panel.Width() > colWidths[ci] {
+					colWidths[ci] = cell.panel.Width()
+				}
 			}
 		}
 	}
+	// The final width for each column is the maximum no span column width
+	// but if it is zero, is the maximum span column width
+	for i := 0; i < len(colWidths); i++ {
+		if colWidths[i] == 0 {
+			colWidths[i] = spanWidths[i]
+		}
+	}
 
 	// If expand horizontally set, distribute available space between all columns
 	if g.expandh {