Disable scroll bars for auto resize text fields

This commit is contained in:
Trevor Slocum 2024-09-01 21:25:01 -07:00
parent 89ca460446
commit 95cc760dea
3 changed files with 25 additions and 14 deletions

2
go.mod
View file

@ -9,7 +9,7 @@ require (
)
require (
github.com/ebitengine/gomobile v0.0.0-20240802043200-192f051f4fcc // indirect
github.com/ebitengine/gomobile v0.0.0-20240825043811-96c531f5bd83 // indirect
github.com/ebitengine/hideconsole v1.0.0 // indirect
github.com/ebitengine/purego v0.7.1 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect

4
go.sum
View file

@ -1,5 +1,5 @@
github.com/ebitengine/gomobile v0.0.0-20240802043200-192f051f4fcc h1:76TYsaP1F48tiQRlrr71NsbfxBcFM9/8bEHS9/JbsQg=
github.com/ebitengine/gomobile v0.0.0-20240802043200-192f051f4fcc/go.mod h1:RM/c3pvru6dRqgGEW7RCTb6czFXYAa3MxbXu3u8/dcI=
github.com/ebitengine/gomobile v0.0.0-20240825043811-96c531f5bd83 h1:yA0CtFKYZI/db1snCOInRS0Z18QGZU6aBYkqUT0H6RI=
github.com/ebitengine/gomobile v0.0.0-20240825043811-96c531f5bd83/go.mod h1:n2NbB/F4d9wOXFzC7FT1ipERidmYWC5I4YNOYRs5N7I=
github.com/ebitengine/hideconsole v1.0.0 h1:5J4U0kXF+pv/DhiXt5/lTz0eO5ogJ1iXb8Yj1yReDqE=
github.com/ebitengine/hideconsole v1.0.0/go.mod h1:hTTBTvVYWKBuxPr7peweneWdkUwEuHuB3C1R/ielR1A=
github.com/ebitengine/purego v0.7.1 h1:6/55d26lG3o9VCZX8lping+bZcmShseiqlh2bnUDiPA=

33
text.go
View file

@ -13,12 +13,13 @@ import (
// Text is a text display widget.
type Text struct {
*Box
field *messeji.TextField
textFont *sfnt.Font
textSize int
textResize bool
textAutoSize int
children []Widget
field *messeji.TextField
textFont *sfnt.Font
textSize int
textResize bool
textAutoSize int
scrollVisible bool
children []Widget
}
// NewText returns a new Text widget.
@ -29,10 +30,11 @@ func NewText(text string) *Text {
f.SetHandleKeyboard(true)
t := &Text{
Box: NewBox(),
field: f,
textFont: Style.TextFont,
textSize: Scale(Style.TextSize),
Box: NewBox(),
field: f,
textFont: Style.TextFont,
textSize: Scale(Style.TextSize),
scrollVisible: true,
}
t.resizeFont()
return t
@ -191,12 +193,20 @@ func (t *Text) resizeFont() {
t.textAutoSize = autoSize
}
func (t *Text) scrollBarVisible() bool {
if t.textResize {
return false
}
return t.scrollVisible
}
// SetScrollBarVisible sets whether the scroll bar is visible on the screen.
func (t *Text) SetScrollBarVisible(scrollVisible bool) {
t.Lock()
defer t.Unlock()
t.field.SetScrollBarVisible(scrollVisible)
t.scrollVisible = scrollVisible
t.field.SetScrollBarVisible(t.scrollBarVisible())
}
// SetAutoHideScrollBar sets whether the scroll bar is automatically hidden
@ -225,6 +235,7 @@ func (t *Text) SetAutoResize(resize bool) {
t.textResize = resize
t.resizeFont()
t.field.SetScrollBarVisible(t.scrollBarVisible())
}
// Padding returns the amount of padding around the text within the field.