From 8aaa0179027d470605f5184c0764105a5bd0fbe1 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 15 Mar 2023 23:56:00 -0400 Subject: [PATCH] Re-added OnScrollBoundsChange methods because they are useful --- elements/basic/documentContainer.go | 8 ++++++++ elements/basic/list.go | 9 ++++++++- elements/basic/textbox.go | 7 +++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/elements/basic/documentContainer.go b/elements/basic/documentContainer.go index 96d3558..a5ddda9 100644 --- a/elements/basic/documentContainer.go +++ b/elements/basic/documentContainer.go @@ -21,6 +21,8 @@ type DocumentContainer struct { config config.Wrapped theme theme.Wrapped + + onScrollBoundsChange func () } // NewDocumentContainer creates a new document container. @@ -255,6 +257,12 @@ func (element *DocumentContainer) ScrollTo (position image.Point) { } } +// OnScrollBoundsChange sets a function to be called when the element's viewport +// bounds, content bounds, or scroll axes change. +func (element *DocumentContainer) OnScrollBoundsChange (callback func ()) { + element.onScrollBoundsChange = callback +} + func (element *DocumentContainer) maxScrollHeight () (height int) { padding := element.theme.Padding(theme.PatternSunken) viewportHeight := element.Bounds().Dy() - padding.Vertical() diff --git a/elements/basic/list.go b/elements/basic/list.go index 45b7951..03d0bd6 100644 --- a/elements/basic/list.go +++ b/elements/basic/list.go @@ -30,7 +30,8 @@ type List struct { config config.Wrapped theme theme.Wrapped - onNoEntrySelected func () + onNoEntrySelected func () + onScrollBoundsChange func () } // NewList creates a new list element with the specified entries. @@ -240,6 +241,12 @@ func (element *List) OnNoEntrySelected (callback func ()) { element.onNoEntrySelected = callback } +// OnScrollBoundsChange sets a function to be called when the element's viewport +// bounds, content bounds, or scroll axes change. +func (element *List) OnScrollBoundsChange (callback func ()) { + element.onScrollBoundsChange = callback +} + // CountEntries returns the amount of entries in the list. func (element *List) CountEntries () (count int) { return len(element.entries) diff --git a/elements/basic/textbox.go b/elements/basic/textbox.go index 601e270..4646324 100644 --- a/elements/basic/textbox.go +++ b/elements/basic/textbox.go @@ -34,6 +34,7 @@ type TextBox struct { onKeyDown func (key input.Key, modifiers input.Modifiers) (handled bool) onChange func () + onScrollBoundsChange func () } // NewTextBox creates a new text box with the specified placeholder text, and @@ -241,6 +242,12 @@ func (element *TextBox) OnChange (callback func ()) { element.onChange = callback } +// OnScrollBoundsChange sets a function to be called when the element's viewport +// bounds, content bounds, or scroll axes change. +func (element *TextBox) OnScrollBoundsChange (callback func ()) { + element.onScrollBoundsChange = callback +} + // ScrollContentBounds returns the full content size of the element. func (element *TextBox) ScrollContentBounds () (bounds image.Rectangle) { bounds = element.valueDrawer.LayoutBounds()