TableContainer is now scrollable
This commit is contained in:
parent
eca75c642b
commit
55c13ebf89
@ -263,7 +263,68 @@ func (element *TableContainer) HandleMouseDown (x, y int, button input.Button) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}}}
|
}}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScrollContentBounds returns the full content size of the element.
|
||||||
|
func (element *TableContainer) ScrollContentBounds () image.Rectangle {
|
||||||
|
return element.contentBounds
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScrollViewportBounds returns the size and position of the element's
|
||||||
|
// viewport relative to ScrollBounds.
|
||||||
|
func (element *TableContainer) ScrollViewportBounds () image.Rectangle {
|
||||||
|
bounds := element.Bounds()
|
||||||
|
bounds = bounds.Sub(bounds.Min).Add(element.scroll)
|
||||||
|
return bounds
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScrollTo scrolls the viewport to the specified point relative to
|
||||||
|
// ScrollBounds.
|
||||||
|
func (element *TableContainer) ScrollTo (position image.Point) {
|
||||||
|
if position.Y < 0 {
|
||||||
|
position.Y = 0
|
||||||
|
}
|
||||||
|
maxScrollHeight := element.maxScrollHeight()
|
||||||
|
if position.Y > maxScrollHeight {
|
||||||
|
position.Y = maxScrollHeight
|
||||||
|
}
|
||||||
|
if position.X < 0 {
|
||||||
|
position.X = 0
|
||||||
|
}
|
||||||
|
maxScrollWidth := element.maxScrollWidth()
|
||||||
|
if position.X > maxScrollWidth {
|
||||||
|
position.X = maxScrollWidth
|
||||||
|
}
|
||||||
|
element.scroll = position
|
||||||
|
if element.core.HasImage() && !element.warping {
|
||||||
|
element.redoAll()
|
||||||
|
element.core.DamageAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnScrollBoundsChange sets a function to be called when the element's viewport
|
||||||
|
// bounds, content bounds, or scroll axes change.
|
||||||
|
func (element *TableContainer) OnScrollBoundsChange (callback func ()) {
|
||||||
|
element.onScrollBoundsChange = callback
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScrollAxes returns the supported axes for scrolling.
|
||||||
|
func (element *TableContainer) ScrollAxes () (horizontal, vertical bool) {
|
||||||
|
return true, true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (element *TableContainer) maxScrollHeight () (height int) {
|
||||||
|
viewportHeight := element.Bounds().Dy()
|
||||||
|
height = element.contentBounds.Dy() - viewportHeight
|
||||||
|
if height < 0 { height = 0 }
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (element *TableContainer) maxScrollWidth () (width int) {
|
||||||
|
viewportWidth := element.Bounds().Dx()
|
||||||
|
width = element.contentBounds.Dx() - viewportWidth
|
||||||
|
if width < 0 { width = 0 }
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (element *TableContainer) hook (child tomo.Element) {
|
func (element *TableContainer) hook (child tomo.Element) {
|
||||||
@ -326,9 +387,17 @@ func (element *TableContainer) redoAll () {
|
|||||||
element.updateMinimumSize()
|
element.updateMinimumSize()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maxScrollHeight := element.maxScrollHeight()
|
||||||
|
if element.scroll.Y > maxScrollHeight {
|
||||||
|
element.scroll.Y = maxScrollHeight
|
||||||
|
}
|
||||||
|
maxScrollWidth := element.maxScrollWidth()
|
||||||
|
if element.scroll.X > maxScrollWidth {
|
||||||
|
element.scroll.X = maxScrollWidth
|
||||||
|
}
|
||||||
|
|
||||||
// calculate the minimum size of each column and row
|
// calculate the minimum size of each column and row
|
||||||
bounds := element.Bounds()
|
|
||||||
var minWidth, minHeight float64
|
var minWidth, minHeight float64
|
||||||
columnWidths := make([]float64, element.columns)
|
columnWidths := make([]float64, element.columns)
|
||||||
rowHeights := make([]float64, element.rows)
|
rowHeights := make([]float64, element.rows)
|
||||||