Basic elements now conform to new API

This commit is contained in:
2023-03-15 01:41:23 -04:00
parent f4799ba03d
commit 0015820fac
15 changed files with 137 additions and 272 deletions

View File

@@ -6,6 +6,7 @@ import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/elements"
import "git.tebibyte.media/sashakoshka/tomo/textdraw"
import "git.tebibyte.media/sashakoshka/tomo/textmanip"
import "git.tebibyte.media/sashakoshka/tomo/fixedutil"
@@ -33,7 +34,6 @@ 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
@@ -42,9 +42,9 @@ type TextBox struct {
func NewTextBox (placeholder, value string) (element *TextBox) {
element = &TextBox { }
element.theme.Case = theme.C("basic", "textBox")
element.Core, element.core = core.NewCore(element.handleResize)
element.Core, element.core = core.NewCore(element, element.handleResize)
element.FocusableCore,
element.focusableControl = core.NewFocusableCore (func () {
element.focusableControl = core.NewFocusableCore (element.core, func () {
if element.core.HasImage () {
element.draw()
element.core.DamageAll()
@@ -60,8 +60,8 @@ func NewTextBox (placeholder, value string) (element *TextBox) {
func (element *TextBox) handleResize () {
element.scrollToCursor()
element.draw()
if element.onScrollBoundsChange != nil {
element.onScrollBoundsChange()
if parent, ok := element.core.Parent().(elements.ScrollableParent); ok {
parent.NotifyScrollBoundsChange(element)
}
}
@@ -187,9 +187,10 @@ func (element *TextBox) HandleKeyDown(key input.Key, modifiers input.Modifiers)
element.scrollToCursor()
}
if (textChanged || scrollMemory != element.scroll) &&
element.onScrollBoundsChange != nil {
element.onScrollBoundsChange()
if (textChanged || scrollMemory != element.scroll) {
if parent, ok := element.core.Parent().(elements.ScrollableParent); ok {
parent.NotifyScrollBoundsChange(element)
}
}
if altered {
@@ -274,8 +275,8 @@ func (element *TextBox) ScrollTo (position image.Point) {
if element.scroll > maxPosition { element.scroll = maxPosition }
element.redo()
if element.onScrollBoundsChange != nil {
element.onScrollBoundsChange()
if parent, ok := element.core.Parent().(elements.ScrollableParent); ok {
parent.NotifyScrollBoundsChange(element)
}
}
@@ -284,10 +285,6 @@ func (element *TextBox) ScrollAxes () (horizontal, vertical bool) {
return true, false
}
func (element *TextBox) OnScrollBoundsChange (callback func ()) {
element.onScrollBoundsChange = callback
}
func (element *TextBox) runOnChange () {
if element.onChange != nil {
element.onChange()