From 3889cb5252f096b688401f776ba10ab8d319024e Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 18 Jan 2023 17:32:33 -0500 Subject: [PATCH] Added scrollable element interface --- element.go | 22 ++++++++++++++++++++++ elements/basic/textbox.go | 18 +++++++++--------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/element.go b/element.go index 06e37be..18d282f 100644 --- a/element.go +++ b/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) +} diff --git a/elements/basic/textbox.go b/elements/basic/textbox.go index 6e29c98..7b25c9a 100644 --- a/elements/basic/textbox.go +++ b/elements/basic/textbox.go @@ -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()