Added scrollable element interface
This commit is contained in:
parent
b69eb6b62e
commit
3889cb5252
22
element.go
22
element.go
@ -1,5 +1,7 @@
|
||||
package tomo
|
||||
|
||||
import "image"
|
||||
|
||||
// ParentHooks is a struct that contains callbacks that let child elements send
|
||||
// information to their parent element without the child element knowing
|
||||
// anything about the parent element or containing any reference to it. When a
|
||||
@ -203,3 +205,23 @@ type Flexible interface {
|
||||
// flexible chilren, it itself will likely need to be flexible.
|
||||
MinimumHeightFor (width int) (height int)
|
||||
}
|
||||
|
||||
// Scrollable represents an element that can be scrolled. It acts as a viewport
|
||||
// through which its contents can be observed.
|
||||
type Scrollable interface {
|
||||
Element
|
||||
|
||||
// ScrollContentBounds returns the full content size of the element.
|
||||
ScrollContentBounds () (bounds image.Rectangle)
|
||||
|
||||
// ScrollViewportBounds returns the size and position of the element's
|
||||
// viewport relative to ScrollBounds.
|
||||
ScrollViewportBounds () (bounds image.Rectangle)
|
||||
|
||||
// ScrollTo scrolls the viewport to the specified point relative to
|
||||
// ScrollBounds.
|
||||
ScrollTo (position image.Point)
|
||||
|
||||
// ScrollAxes returns the supported axes for scrolling.
|
||||
ScrollAxes () (horizontal, vertical bool)
|
||||
}
|
||||
|
@ -182,15 +182,6 @@ func (element *TextBox) SetPlaceholder (placeholder string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (element *TextBox) updateMinimumSize () {
|
||||
textBounds := element.placeholderDrawer.LayoutBounds()
|
||||
element.core.SetMinimumSize (
|
||||
textBounds.Dx() +
|
||||
theme.Padding() * 2,
|
||||
element.placeholderDrawer.LineHeight().Round() +
|
||||
theme.Padding() * 2)
|
||||
}
|
||||
|
||||
func (element *TextBox) SetValue (text string) {
|
||||
// if element.text == text { return }
|
||||
|
||||
@ -230,6 +221,15 @@ func (element *TextBox) OnChange (callback func ()) {
|
||||
element.onChange = callback
|
||||
}
|
||||
|
||||
func (element *TextBox) updateMinimumSize () {
|
||||
textBounds := element.placeholderDrawer.LayoutBounds()
|
||||
element.core.SetMinimumSize (
|
||||
textBounds.Dx() +
|
||||
theme.Padding() * 2,
|
||||
element.placeholderDrawer.LineHeight().Round() +
|
||||
theme.Padding() * 2)
|
||||
}
|
||||
|
||||
func (element *TextBox) runOnChange () {
|
||||
if element.onChange != nil {
|
||||
element.onChange()
|
||||
|
Reference in New Issue
Block a user