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

Method setColWidth

gui/table.go:1119–1174  ·  view source on GitHub ↗

setColWidth sets the width of the specified column

(c *tableColHeader, width float32)

Source from the content-addressed store, hash-verified

1117
1118// setColWidth sets the width of the specified column
1119func (t *Table) setColWidth(c *tableColHeader, width float32) {
1120
1121 // Sets the column width
1122 if width < c.minWidth {
1123 width = c.minWidth
1124 }
1125 if c.Width() == width {
1126 return
1127 }
1128 dw := width - c.Width()
1129 c.SetWidth(width)
1130
1131 // Find the column index and if any column has expand != 0
1132 hasExpand := false
1133 ci := -1
1134 for i := 0; i < len(t.header.cols); i++ {
1135 current := t.header.cols[i]
1136 if current == c {
1137 ci = i
1138 }
1139 if current.expand > 0 && current.Visible() {
1140 hasExpand = true
1141 }
1142 }
1143 if ci >= len(t.header.cols) {
1144 panic("Internal: column not found")
1145 }
1146 // If no column is expandable, nothing more todo
1147 if !hasExpand {
1148 t.recalc()
1149 return
1150 }
1151 // Calculates the width of the columns at the right
1152 rwidth := float32(0)
1153 for i := ci + 1; i < len(t.header.cols); i++ {
1154 c := t.header.cols[i]
1155 if !c.Visible() {
1156 continue
1157 }
1158 rwidth += c.Width()
1159 }
1160 // Distributes the delta to the columns at the right
1161 for i := ci + 1; i < len(t.header.cols); i++ {
1162 c := t.header.cols[i]
1163 if !c.Visible() {
1164 continue
1165 }
1166 cdelta := -dw * (c.Width() / rwidth)
1167 newWidth := c.Width() + cdelta
1168 if newWidth < c.minWidth {
1169 newWidth = c.minWidth
1170 }
1171 c.SetWidth(newWidth)
1172 }
1173 t.recalc()
1174}
1175
1176// recalcHeader recalculates and sets the position and size of the header panels

Callers 2

SetColWidthMethod · 0.95
onMouseMethod · 0.95

Calls 4

recalcMethod · 0.95
SetWidthMethod · 0.80
WidthMethod · 0.65
VisibleMethod · 0.65

Tested by

no test coverage detected