Skip to content

Commit

Permalink
[framework] Broken fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lexisother committed Mar 1, 2023
1 parent 2b17e19 commit 5143bc8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion design/textbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func mkTxtBox(hint string, str *string, text []string, newline bool) framework.U
if confirm && newline {
// handle multiline textboxes
fwTextbox.FyTInput("\n")
fwTextbox.AdditionalCaretPosY += 15
}

// The reason why we wait for stall is because this reduces the lag.
Expand Down Expand Up @@ -63,7 +64,7 @@ func NewUITextboxPtr(hint string, str *string, init ...string) framework.UILayou
return mkTxtBox(hint, str, init, false)
}

// like NewUITextboxPtr except multiline
// NewUITextareaPtr is NewUITextboxPtr, but with multiline support
func NewUITextareaPtr(hint string, str *string, init ...string) framework.UILayoutElement {
return mkTxtBox(hint, str, init, true)
}
13 changes: 10 additions & 3 deletions framework/uiLibTextInput.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package framework

import (
"fmt"
"golang.org/x/image/math/fixed"
"strings"

"github.com/uwu/frenyard"
"github.com/uwu/frenyard/integration"
"github.com/veandco/go-sdl2/sdl"
"golang.org/x/image/font"
"golang.org/x/image/math/fixed"
)

// UITextbox is a textbox.
Expand All @@ -21,6 +22,8 @@ type UITextbox struct {
// Called on enter
OnConfirm func()

AdditionalCaretPosY int32

_open bool
_caretBlinker float64
_stallTimer float64
Expand Down Expand Up @@ -141,13 +144,17 @@ func (tb *UITextbox) FyEDraw(target frenyard.Renderer, under bool) {
tb._translation = target.Translation()
tb.UILayoutProxy.FyEDraw(target, under)

// TODO: For the love of god improve this
currentLineSlice := strings.Split(tb._textPre, "\n")
currentLine := currentLineSlice[len(currentLineSlice)-1]

// all between here and the end of the func is caret drawing code
preChunk := integration.NewColouredTextTypeChunk(tb._textPre, tb._face, tb._primaryColour)
preChunk := integration.NewColouredTextTypeChunk(currentLine, tb._face, tb._primaryColour)
preDot, _ := preChunk.FyCBounds(fixed.Point26_6{})

caretPos := frenyard.Vec2i{
X: int32(preDot.X.Ceil()),
Y: int32(preDot.Y.Ceil()) + 2, // lil visual oset
Y: int32(preDot.Y.Ceil()) + 2 + tb.AdditionalCaretPosY, // lil visual offset
}
caretSize := frenyard.Vec2i{
X: 1,
Expand Down

0 comments on commit 5143bc8

Please sign in to comment.