MCPcopy
hub / github.com/g3n/engine / recalcHeader

Method recalcHeader

gui/table.go:1177–1289  ·  view source on GitHub ↗

recalcHeader recalculates and sets the position and size of the header panels

()

Source from the content-addressed store, hash-verified

1175
1176// recalcHeader recalculates and sets the position and size of the header panels
1177func (t *Table) recalcHeader() {
1178
1179 // Calculates total width, height, expansion and available width space
1180 hwidth := float32(0)
1181 height := float32(0)
1182 wspace := float32(0)
1183 totalExpand := float32(0)
1184 for ci := 0; ci < len(t.header.cols); ci++ {
1185 // If column is invisible, ignore
1186 c := t.header.cols[ci]
1187 if !c.Visible() {
1188 continue
1189 }
1190 if c.Height() > height {
1191 height = c.Height()
1192 }
1193 if c.expand > 0 {
1194 totalExpand += c.expand
1195 }
1196 hwidth += c.Width()
1197 }
1198 // Total table width
1199 twidth := t.ContentWidth()
1200 if t.vscroll != nil && t.vscroll.Visible() {
1201 twidth -= t.vscroll.Width()
1202 }
1203 // Available space for columns: may be negative
1204 wspace = twidth - hwidth
1205
1206 // If no expandable column, keeps the columns widths
1207 if totalExpand == 0 {
1208 } else if wspace >= 0 {
1209 for ci := 0; ci < len(t.header.cols); ci++ {
1210 // If column is invisible, ignore
1211 c := t.header.cols[ci]
1212 if !c.Visible() {
1213 continue
1214 }
1215 // There is space available and if column is expandable,
1216 // expands it proportionally to the other expandable columns
1217 factor := c.expand / totalExpand
1218 w := factor * wspace
1219 c.SetWidth(c.Width() + w)
1220 }
1221 } else {
1222 acols := make([]*tableColHeader, 0)
1223 awidth := float32(0)
1224 widthAvail := twidth
1225 // Sets the widths of the columns
1226 for ci := 0; ci < len(t.header.cols); ci++ {
1227 // If column is invisible, ignore
1228 c := t.header.cols[ci]
1229 if !c.Visible() {
1230 continue
1231 }
1232 // The table was reduced so shrinks this column proportionally to its current width
1233 factor := c.Width() / hwidth
1234 newWidth := factor * twidth

Callers 1

recalcMethod · 0.95

Calls 9

ContentWidthMethod · 0.80
SetWidthMethod · 0.80
SetContentHeightMethod · 0.80
VisibleMethod · 0.65
HeightMethod · 0.65
WidthMethod · 0.65
SetPositionMethod · 0.65
SetVisibleMethod · 0.65
SetSizeMethod · 0.45

Tested by

no test coverage detected