Skip to content

Commit

Permalink
[framework] stop empty textboxes from scrunching up
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowsink committed Feb 26, 2023
1 parent 5643956 commit 172a52b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
9 changes: 7 additions & 2 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/uwu/frenyard"
"github.com/uwu/frenyard/design"
"github.com/uwu/frenyard/framework"
"github.com/uwu/frenyard/integration"
)

func main() {
Expand Down Expand Up @@ -34,6 +33,8 @@ func main() {
TeleportSettings: framework.SlideTransition{},
})

strptr := ""

// Start an instant transition to our main screen.
app.Teleport(
// A 'document', with a title header and body.
Expand All @@ -46,7 +47,11 @@ func main() {
DirVertical: true,
Slots: []framework.FlexboxSlot{
{
Element: framework.NewUILabelPtr(integration.NewTextTypeChunk("Hello World!", design.GlobalFont), design.ThemeText, 0, frenyard.Alignment2i{}),
Element: //framework.NewUILabelPtr(integration.NewTextTypeChunk("Hello World!", design.GlobalFont), design.ThemeText, 0, frenyard.Alignment2i{}),
design.NewUITextboxPtr("test", &strptr, "hi!"),
},
{
Element: design.NewUITextboxPtr("", &strptr, "hi 2!"),
},
},
}),
Expand Down
19 changes: 16 additions & 3 deletions framework/uiLibTextInput.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ type UITextbox struct {

// NewUITextboxPtr creates a UITextbox.
func NewUITextboxPtr(text string, hint string, face font.Face, primaryColour uint32, suggestionColour uint32, hintColour uint32, backgroundColour uint32, align frenyard.Alignment2i) *UITextbox {
// empty textboxes misbehave layout-wise, so don't let it become so
if hint == "" {
hint = " "
}

textbox := &UITextbox{
_textPre: text,
_hint: hint,
Expand Down Expand Up @@ -92,24 +97,31 @@ func (tb *UITextbox) FyETick(delta float64) {
func (tb *UITextbox) rebuild() {
tb._stallTimer = 0
tb._caretBlinker = 0

// see comment in NewUITextboxPtr - empty textboxes misbehave
safeTextPre := tb._textPre
if safeTextPre == "" && tb._textPost == "" {
safeTextPre = " "
}

if !tb._open {
if tb._textPre == "" && tb._textPost == "" {
tb._label.SetText(integration.NewCompoundTypeChunk([]integration.TypeChunk{
integration.NewColouredTextTypeChunk(tb._hint, tb._face, tb._hintColour),
}))
} else {
tb._label.SetText(integration.NewCompoundTypeChunk([]integration.TypeChunk{
integration.NewColouredTextTypeChunk(tb._textPre+tb._textPost, tb._face, tb._primaryColour),
integration.NewColouredTextTypeChunk(safeTextPre+tb._textPost, tb._face, tb._primaryColour),
}))
}
} else if !tb._suggesting {
tb._label.SetText(integration.NewCompoundTypeChunk([]integration.TypeChunk{
integration.NewColouredTextTypeChunk(tb._textPre, tb._face, tb._primaryColour),
integration.NewColouredTextTypeChunk(safeTextPre, tb._face, tb._primaryColour),
integration.NewColouredTextTypeChunk(tb._textPost, tb._face, tb._primaryColour),
}))
} else {
tb._label.SetText(integration.NewCompoundTypeChunk([]integration.TypeChunk{
integration.NewColouredTextTypeChunk(tb._textPre, tb._face, tb._primaryColour),
integration.NewColouredTextTypeChunk(safeTextPre, tb._face, tb._primaryColour),
integration.NewColouredTextTypeChunk(tb._textSuggestion1, tb._face, tb._suggestionColour),
integration.NewUnderlineTypeChunk(integration.NewColouredTextTypeChunk(tb._textSuggestion2, tb._face, tb._suggestionColour), tb._suggestionColour),
integration.NewColouredTextTypeChunk(tb._textSuggestion3, tb._face, tb._suggestionColour),
Expand All @@ -126,6 +138,7 @@ func (tb *UITextbox) FyEDraw(target frenyard.Renderer, under bool) {
tb._translation = target.Translation()
tb.UILayoutProxy.FyEDraw(target, under)

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

Expand Down

0 comments on commit 172a52b

Please sign in to comment.