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

Method findClick

gui/table.go:938–984  ·  view source on GitHub ↗

findClick finds where in the table the specified mouse click event occurred updating the specified TableClickEvent with the click coordinates.

(ev *TableClickEvent)

Source from the content-addressed store, hash-verified

936// findClick finds where in the table the specified mouse click event
937// occurred updating the specified TableClickEvent with the click coordinates.
938func (t *Table) findClick(ev *TableClickEvent) {
939
940 x, y := t.ContentCoords(ev.Xpos, ev.Ypos)
941 ev.X = x
942 ev.Y = y
943 ev.Row = -1
944 // Find column id
945 colx := float32(0)
946 for ci := 0; ci < len(t.header.cols); ci++ {
947 c := t.header.cols[ci]
948 if !c.Visible() {
949 continue
950 }
951 colx += t.header.cols[ci].Width()
952 if x < colx {
953 ev.Col = c.id
954 ev.ColOrder = ci
955 break
956 }
957 }
958 // If column not found the user clicked at the right of rows
959 if ev.Col == "" {
960 return
961 }
962 // Checks if is in header
963 if t.header.Visible() && y < t.header.Height() {
964 ev.Header = true
965 }
966
967 // Find row clicked
968 rowy := float32(0)
969 if t.header.Visible() {
970 rowy = t.header.Height()
971 }
972 theight := t.ContentHeight()
973 for ri := t.firstRow; ri < len(t.rows); ri++ {
974 trow := t.rows[ri]
975 rowy += trow.height
976 if rowy > theight {
977 break
978 }
979 if y < rowy {
980 ev.Row = ri
981 break
982 }
983 }
984}
985
986// selNext selects the next row if possible
987func (t *Table) selNext() {

Callers 1

onMouseMethod · 0.95

Calls 5

ContentCoordsMethod · 0.80
ContentHeightMethod · 0.80
VisibleMethod · 0.65
WidthMethod · 0.65
HeightMethod · 0.65

Tested by

no test coverage detected