package gui // Common actions for widgets like 'Enable' or 'Hide' import ( "errors" "go.wit.com/log" "go.wit.com/widget" ) // This will set the visable name for widgets that // have text displayed that is not editable by the user // For example, a button, window, group, checkbox func (n *Node) SetLabel(label string) *Node { switch n.WidgetType { case widget.Checkbox: n.label = label case widget.Button: n.label = label case widget.Label: n.label = label case widget.Group: n.label = label case widget.Window: n.label = label default: } n.changed = true log.Log(CHANGE, "SetLabel() value =", label) // inform the toolkits sendAction(n, widget.SetText) return n } // What "SetText" means depends on the type of widget // should this be a different name? func (n *Node) SetText(text string) *Node { if !n.Ready() { return n } if n.String() == text { // nothing changed // return n } n.value = text n.changed = true log.Log(CHANGE, "SetText() value =", text) // inform the toolkits sendAction(n, widget.SetText) return n } func (n *Node) SetValue(val any) { if !n.Ready() { return } n.value = val n.changed = true log.Log(CHANGE, "Set() value =", val) // inform the toolkits sendAction(n, widget.Set) } func (n *Node) Set(val any) { if !n.Ready() { return } switch v := val.(type) { case bool: if widget.GetBool(n.value) == val.(bool) { // nothing changed return } case string: if widget.GetString(n.value) == val.(string) { // nothing changed return } case int: if widget.GetInt(n.value) == val.(int) { // nothing changed return } default: log.Error(errors.New("Set() unknown type"), "v =", v) } n.value = val n.changed = true log.Log(CHANGE, "Set() value =", val) // inform the toolkits sendAction(n, widget.Set) }