tview/demos/presentation/form.go

56 lines
15 KiB
Go
Raw Normal View History

package main
import (
2022-12-27 04:55:31 +08:00
"bytes"
"encoding/base64"
"image/jpeg"
"github.com/rivo/tview"
)
const form = `[green]package[white] main
[green]import[white] (
[red]"github.com/rivo/tview"[white]
)
[green]func[white] [yellow]main[white]() {
form := tview.[yellow]NewForm[white]().
2022-12-27 04:55:31 +08:00
[yellow]AddImage[white]([red]"Photo:"[white], img, [red]0[white], [red]12[white], 0[white]).
[yellow]AddInputField[white]([red]"First name:"[white], [red]""[white], [red]20[white], nil, nil).
[yellow]AddInputField[white]([red]"Last name:"[white], [red]""[white], [red]20[white], nil, nil).
[yellow]AddDropDown[white]([red]"Role:"[white], [][green]string[white]{
[red]"Engineer"[white],
[red]"Manager"[white],
[red]"Administration"[white],
}, [red]0[white], nil).
[yellow]AddCheckbox[white]([red]"On vacation:"[white], false, nil).
[yellow]AddPasswordField[white]([red]"Password:"[white], [red]""[white], [red]10[white], [red]'*'[white], nil).
[yellow]AddTextArea[white]([red]"Notes:"[white], [red]""[white], [red]0[white], [red]5[white], [red]0[white], nil).
[yellow]AddButton[white]([red]"Save"[white], [yellow]func[white]() { [blue]/* Save data */[white] }).
[yellow]AddButton[white]([red]"Cancel"[white], [yellow]func[white]() { [blue]/* Cancel */[white] })
tview.[yellow]NewApplication[white]().
[yellow]SetRoot[white](form, true).
[yellow]Run[white]()
}`
2022-12-27 04:55:31 +08:00
const photo = `/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAQEBAQEBAQEBAQGBgUGBggHBwcHCAwJCQkJCQwTDA4MDA4MExEUEA8QFBEeFxUVFx4iHRsdIiolJSo0MjRERFwBBAQEBAQEBAQEBAYGBQYGCAcHBwcIDAkJCQkJDBMMDgwMDgwTERQQDxAUER4XFRUXHiIdGx0iKiUlKjQyNEREXP/CABEIARgAyAMBIgACEQEDEQH/xAAcAAABBQEBAQAAAAAAAAAAAAAGAgMEBQcBCAD/2gAIAQEAAAAAbUpXVd6nqYef0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g1Yj9k6ylFrkdE/ay9ER/NPNuns482+G1BG4Cw4++aqYcoUQUTVTZmjV2ZR9lG63RZhayzKQ36LVStU8e6nbYmylGpR8Tgq43Y4dbKZvi/VSDN8l6H2FRO32cWbfD6ofgKodKqMFU/gCj7KK9hoob68uqhbfcIaGyvfdWTm+RVrbJwKna6x1VQcoN0Rd2ZSgNzlV98gt2UzuVykAt53XoeDx6lx7D2a9uajqG/gKw0Zq2x3VPo1RO10VONNQqcAqNgvZOGmyLeyDSsndFikbupxoqsHqnG2im287hVDRYquiyG/kjqvRCMZJ5Ot7fL2Z3BwfFcXIKo2GHEsj9DmeFFoFSywsc0SO1PRRSwBoIPRU1Qw/wC02oiCdUtdo0pr9Nd1cLjDujUMClqotW31UlbCNS4KrracHLe99FMQ7madE9xt81OsSLQAD5o30a3fosGM9NTtbfJfUhU0/GYe40PsPw9szjUB5EjNrLGKV1Li1NMW24h/VTymCEvG6bVy5i48v4ipsfmibka65+Oyb6S1rAGh5HwVD6S1L3e9ebdb
// Form demonstrates forms.
func Form(nextSlide func()) (title string, content tview.Primitive) {
2022-12-27 04:55:31 +08:00
b, _ := base64.StdEncoding.DecodeString(photo)
img, _ := jpeg.Decode(bytes.NewReader(b))
f := tview.NewForm().
2022-12-27 04:55:31 +08:00
AddImage("Photo:", img, 0, 12, 0).
AddInputField("First name:", "", 20, nil, nil).
AddInputField("Last name:", "", 20, nil, nil).
AddDropDown("Role:", []string{"Engineer", "Manager", "Administration"}, 0, nil).
AddCheckbox("On vacation:", false, nil).
AddPasswordField("Password:", "", 10, '*', nil).
2022-12-27 04:55:31 +08:00
AddTextArea("Notes:", "", 0, 2, 0, nil).
AddButton("Save", nextSlide).
AddButton("Cancel", nextSlide)
f.SetBorder(true).SetTitle("Employee Information")
2022-12-27 04:55:31 +08:00
return "Forms", Code(f, 36, 31, form)
}