2022-10-19 13:23:22 -05:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import "log"
|
2022-10-21 11:40:08 -05:00
|
|
|
// import "errors"
|
2022-10-20 06:55:42 -05:00
|
|
|
import "regexp"
|
2022-10-19 13:23:22 -05:00
|
|
|
|
|
|
|
// functions for handling text related GUI elements
|
|
|
|
|
2022-10-21 11:40:08 -05:00
|
|
|
func (n *Node) SetText(str string) bool {
|
2022-11-13 08:53:03 -06:00
|
|
|
if (Config.Debug.Change) {
|
2022-11-05 10:19:04 -05:00
|
|
|
log.Println("gui.SetText() value =", str)
|
|
|
|
}
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
return true
|
2022-10-21 11:40:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) GetText() string {
|
2022-11-13 08:53:03 -06:00
|
|
|
return "not implemented"
|
2022-10-19 13:23:22 -05:00
|
|
|
}
|
2022-10-20 06:55:42 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
// string handling examples that might be helpful for normalizeInt()
|
|
|
|
isAlpha := regexp.MustCompile(`^[A-Za-z]+$`).MatchString
|
|
|
|
|
|
|
|
for _, username := range []string{"userone", "user2", "user-three"} {
|
|
|
|
if !isAlpha(username) {
|
2022-11-14 14:30:28 -06:00
|
|
|
log.Printf("%q is not valid\n", username)
|
2022-10-20 06:55:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const alpha = "abcdefghijklmnopqrstuvwxyz"
|
|
|
|
|
|
|
|
func alphaOnly(s string) bool {
|
|
|
|
for _, char := range s {
|
|
|
|
if !strings.Contains(alpha, strings.ToLower(string(char))) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
func normalizeInt(s string) string {
|
|
|
|
// reg, err := regexp.Compile("[^a-zA-Z0-9]+")
|
|
|
|
reg, err := regexp.Compile("[^0-9]+")
|
|
|
|
if err != nil {
|
|
|
|
log.Println("normalizeInt() regexp.Compile() ERROR =", err)
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
clean := reg.ReplaceAllString(s, "")
|
|
|
|
log.Println("normalizeInt() s =", clean)
|
|
|
|
return clean
|
|
|
|
}
|
2022-11-13 08:53:03 -06:00
|
|
|
|
|
|
|
func commonCallback(n *Node) {
|
|
|
|
// TODO: make all of this common code to all the widgets
|
|
|
|
if (n.OnChanged == nil) {
|
|
|
|
if (Config.Debug.Change) {
|
|
|
|
log.Println("Not Running n.OnChanged(n) == nil")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (Config.Debug.Change) {
|
|
|
|
log.Println("Running n.OnChanged(n)")
|
|
|
|
}
|
|
|
|
n.OnChanged(n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n.custom == nil) {
|
|
|
|
if (Config.Debug.Change) {
|
|
|
|
log.Println("Not Running n.custom(n) == nil")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (Config.Debug.Change) {
|
|
|
|
log.Println("Running n.custom()")
|
|
|
|
}
|
|
|
|
n.custom()
|
|
|
|
}
|
|
|
|
}
|