[GH-ISSUE #948] Make Table.cellAt public #695

Closed
opened 2026-03-04 01:07:05 +03:00 by kerem · 2 comments
Owner

Originally created by @tliron on GitHub (Feb 17, 2024).
Original GitHub issue: https://github.com/rivo/tview/issues/948

The cellAt function is currently private.

However, it makes sense for me to make it public, to allow for custom mouse handlers to determine which cell the mouse is pointing to.

It's actually impossible to workaround this issue because the function relies on private properties in the struct.

Originally created by @tliron on GitHub (Feb 17, 2024). Original GitHub issue: https://github.com/rivo/tview/issues/948 The [cellAt](https://github.com/rivo/tview/blob/861aa94d61c899b32a1304d61b840d0178ece408/table.go#L759) function is currently private. However, it makes sense for me to make it public, to allow for custom mouse handlers to determine which cell the mouse is pointing to. It's actually impossible to workaround this issue because the function relies on private properties in the struct.
kerem closed this issue 2026-03-04 01:07:06 +03:00
Author
Owner

@tliron commented on GitHub (Feb 18, 2024):

OK, maybe there is a workaround. For reference, here's my attempt. It "works" but I have an uneasy feeling that I'm not taking into account some factors. (By the way, does GetLastPosition return negative x if the column is hidden to the left?)

table.
SetMouseCapture(func(action tview.MouseAction, event *tcell.EventMouse) (tview.MouseAction, *tcell.EventMouse) {
	if action == tview.MouseLeftDoubleClick {
		row, column := table.GetOffset()
		x, y := event.Position()
		row += y - 1 // -1 to skip the header

		// Which column are we on?
		columns := table.GetColumnCount()
		for c := 0; c < columns; c++ {
			cell := table.GetCell(row, c)
			cx, _, width := cell.GetLastPosition()
			if (x >= cx) && (x <= cx+width) {
				column = c
				break
			}
		}

		openDetails(row, column)
		self.application.ForceDraw()
		return action, nil
	}
	return action, event
})
<!-- gh-comment-id:1951395927 --> @tliron commented on GitHub (Feb 18, 2024): OK, maybe there is a workaround. For reference, here's my attempt. It "works" but I have an uneasy feeling that I'm not taking into account some factors. (By the way, does `GetLastPosition` return negative `x` if the column is hidden to the left?) ```go table. SetMouseCapture(func(action tview.MouseAction, event *tcell.EventMouse) (tview.MouseAction, *tcell.EventMouse) { if action == tview.MouseLeftDoubleClick { row, column := table.GetOffset() x, y := event.Position() row += y - 1 // -1 to skip the header // Which column are we on? columns := table.GetColumnCount() for c := 0; c < columns; c++ { cell := table.GetCell(row, c) cx, _, width := cell.GetLastPosition() if (x >= cx) && (x <= cx+width) { column = c break } } openDetails(row, column) self.application.ForceDraw() return action, nil } return action, event }) ```
Author
Owner

@rivo commented on GitHub (Apr 4, 2024):

I made Table.CellAt public.

<!-- gh-comment-id:2036830166 --> @rivo commented on GitHub (Apr 4, 2024): I made `Table.CellAt` public.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#695
No description provided.