Add multi-line text inputs
This commit is contained in:
parent
c7887c5ea4
commit
92e4eb970d
52
textinput.go
52
textinput.go
@ -12,18 +12,27 @@ var _ tomo.ContentObject = new(TextInput)
|
|||||||
type TextInput struct {
|
type TextInput struct {
|
||||||
box tomo.TextBox
|
box tomo.TextBox
|
||||||
text []rune
|
text []rune
|
||||||
|
multiline bool
|
||||||
on struct {
|
on struct {
|
||||||
valueChange event.FuncBroadcaster
|
valueChange event.FuncBroadcaster
|
||||||
confirm event.FuncBroadcaster
|
confirm event.FuncBroadcaster
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTextInput creates a new text input containing the specified text.
|
func newTextInput (text string, multiline bool) *TextInput {
|
||||||
func NewTextInput (text string) *TextInput {
|
textInput := &TextInput {
|
||||||
textInput := &TextInput { box: tomo.NewTextBox() }
|
box: tomo.NewTextBox(),
|
||||||
|
multiline: multiline,
|
||||||
|
}
|
||||||
textInput.box.SetRole(tomo.R("objects", "TextInput"))
|
textInput.box.SetRole(tomo.R("objects", "TextInput"))
|
||||||
textInput.box.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
textInput.box.SetTag("multiline", multiline)
|
||||||
|
if multiline {
|
||||||
|
textInput.box.SetAttr(tomo.AOverflow(false, true))
|
||||||
|
textInput.box.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignStart))
|
||||||
|
} else {
|
||||||
textInput.box.SetAttr(tomo.AOverflow(true, false))
|
textInput.box.SetAttr(tomo.AOverflow(true, false))
|
||||||
|
textInput.box.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||||
|
}
|
||||||
textInput.SetValue(text)
|
textInput.SetValue(text)
|
||||||
textInput.box.SetFocusable(true)
|
textInput.box.SetFocusable(true)
|
||||||
textInput.box.SetSelectable(true)
|
textInput.box.SetSelectable(true)
|
||||||