AHHHHH!!!

This commit is contained in:
Sasha Koshka 2023-02-16 14:39:51 -05:00
parent fa934fa485
commit e2e846a0e5
3 changed files with 34 additions and 5 deletions

View File

@ -38,7 +38,7 @@ func run () {
popups.NewDialog(popups.DialogKindInfo, "", "Sike!") popups.NewDialog(popups.DialogKindInfo, "", "Sike!")
}) })
mouse := testing.NewMouse() mouse := testing.NewMouse()
input := basicElements.NewTextBox("Write some text", "fkjasdklfja\ndjkfhadf") input := basicElements.NewTextBox("Write some text", "")
form := basicElements.NewContainer(basicLayouts.Vertical { true, false}) form := basicElements.NewContainer(basicLayouts.Vertical { true, false})
form.Adopt(basicElements.NewLabel("I have:", false), false) form.Adopt(basicElements.NewLabel("I have:", false), false)
form.Adopt(basicElements.NewSpacer(true), false) form.Adopt(basicElements.NewSpacer(true), false)

View File

@ -65,6 +65,7 @@ func (setter *TypeSetter) needLayout () {
// add a null onto the end because the very end of the text should have // add a null onto the end because the very end of the text should have
// a valid layout position // a valid layout position
// lastLine = lastLine
lastWord := &lastLine.Words[len(lastLine.Words) - 1] lastWord := &lastLine.Words[len(lastLine.Words) - 1]
lastWord.Runes = append (lastWord.Runes, RuneLayout { lastWord.Runes = append (lastWord.Runes, RuneLayout {
X: lastWord.Width + lastWord.SpaceAfter, X: lastWord.Width + lastWord.SpaceAfter,
@ -203,8 +204,11 @@ func (setter *TypeSetter) For (iterator RuneIterator) {
index := 0 index := 0
for _, line := range setter.lines { for _, line := range setter.lines {
lastCharRightBound := fixed.Int26_6(0)
for _, word := range line.Words { for _, word := range line.Words {
for _, char := range word.Runes { for _, char := range word.Runes {
lastCharRightBound = word.X + char.X + char.Width
keepGoing := iterator (index, char.Rune, fixed.Point26_6 { keepGoing := iterator (index, char.Rune, fixed.Point26_6 {
X: word.X + char.X, X: word.X + char.X,
Y: line.Y, Y: line.Y,
@ -212,13 +216,20 @@ func (setter *TypeSetter) For (iterator RuneIterator) {
if !keepGoing { return } if !keepGoing { return }
index ++ index ++
}} }}
if line.BreakAfter { index ++ }
if line.BreakAfter {
keepGoing := iterator (index, '\n', fixed.Point26_6 {
X: lastCharRightBound,
Y: line.Y,
})
if !keepGoing { return }
index ++
}
} }
} }
// AtPosition returns the index of the rune at the specified position. // AtPosition returns the index of the rune at the specified position.
func (setter *TypeSetter) AtPosition (position fixed.Point26_6) (index int) { func (setter *TypeSetter) AtPosition (position fixed.Point26_6) (index int) {
println("XXX", position.Y.Round())
setter.needAlignedLayout() setter.needAlignedLayout()
if setter.lines == nil { return } if setter.lines == nil { return }
@ -250,12 +261,12 @@ func (setter *TypeSetter) AtPosition (position fixed.Point26_6) (index int) {
for _, curWord := range line.Words { for _, curWord := range line.Words {
for _, curChar := range curWord.Runes { for _, curChar := range curWord.Runes {
x := curWord.X + curChar.X + curChar.Width x := curWord.X + curChar.X + curChar.Width
println(index, x.Round(), position.X.Round())
if x > position.X { goto foundRune } if x > position.X { goto foundRune }
index ++ index ++
} }
} }
foundRune: foundRune:
println(index)
return return
} }

View File

@ -110,6 +110,24 @@ func TestSetterIndex (test *testing.T) {
pos = fixed.P(-59, 230) pos = fixed.P(-59, 230)
index = setter.AtPosition(pos) index = setter.AtPosition(pos)
expect = 20
if index != expect {
test.Fatalf (
`setter index at (%d, %d): %d, expected: %d`,
pos.X.Round(), pos.Y.Round(), index, expect)
}
pos = fixed.P(-500, -500)
index = setter.AtPosition(pos)
expect = 0
if index != expect {
test.Fatalf (
`setter index at (%d, %d): %d, expected: %d`,
pos.X.Round(), pos.Y.Round(), index, expect)
}
pos = fixed.P(500, -500)
index = setter.AtPosition(pos)
expect = 19 expect = 19
if index != expect { if index != expect {
test.Fatalf ( test.Fatalf (
@ -119,7 +137,7 @@ func TestSetterIndex (test *testing.T) {
pos = fixed.P(500, 500) pos = fixed.P(500, 500)
index = setter.AtPosition(pos) index = setter.AtPosition(pos)
expect = 45 expect = setter.Length()
if index != expect { if index != expect {
test.Fatalf ( test.Fatalf (
`setter index at (%d, %d): %d, expected: %d`, `setter index at (%d, %d): %d, expected: %d`,