-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradio_action.go
151 lines (132 loc) · 4.9 KB
/
radio_action.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright (c) 2023 The Go-Curses Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ctk
import (
"github.com/go-curses/cdk"
)
const TypeRadioAction cdk.CTypeTag = "ctk-radio-action"
func init() {
_ = cdk.TypesManager.AddType(TypeRadioAction, func() interface{} { return MakeRadioAction() })
}
// RadioAction Hierarchy:
// Object
// +- Action
// +- ToggleAction
// +- RadioAction
type RadioAction interface {
ToggleAction
GetGroup() (value ActionGroup)
SetGroup(group ActionGroup)
GetCurrentValue() (value int)
SetCurrentValue(currentValue int)
}
var _ RadioAction = (*CRadioAction)(nil)
// The CRadioAction structure implements the RadioAction interface and is
// exported to facilitate type embedding with custom implementations. No member
// variables are exported as the interface methods are the only intended means
// of interacting with RadioAction objects.
type CRadioAction struct {
CToggleAction
}
// MakeRadioAction is used by the Buildable system to construct a new RadioAction.
func MakeRadioAction() RadioAction {
return NewRadioAction("", "", "", "", 0)
}
// NewRadioAction is the constructor for new RadioAction instances.
func NewRadioAction(name string, label string, tooltip string, stockId string, value int) (r RadioAction) {
r = new(CRadioAction)
r.Init()
return r
}
// Init initializes an RadioAction object. This must be called at least once to
// set up the necessary defaults and allocate any memory structures. Calling
// this more than once is safe though unnecessary. Only the first call will
// result in any effect upon the RadioAction instance. Init is used in the
// NewRadioAction constructor and only necessary when implementing a derivative
// RadioAction type.
func (r *CRadioAction) Init() (already bool) {
if r.InitTypeItem(TypeRadioAction, r) {
return true
}
r.CToggleAction.Init()
_ = r.InstallProperty(PropertyCurrentValue, cdk.IntProperty, true, 0)
_ = r.InstallProperty(PropertyGroup, cdk.StructProperty, true, nil)
_ = r.InstallProperty(PropertyValue, cdk.IntProperty, true, 0)
return false
}
// GetGroup returns the list representing the radio group for this object. Note
// that the returned list is only valid until the next change to the group.
//
// Parameters:
// action the action object
func (r *CRadioAction) GetGroup() (value ActionGroup) {
var ok bool
if v, err := r.GetStructProperty(PropertyGroup); err != nil {
r.LogErr(err)
} else if value, ok = v.(ActionGroup); !ok {
value = nil
r.LogError("value stored in %v property is not of ActionGroup type: %v (%T)", PropertyGroup, v, v)
}
return
}
// SetGroup updates the radio group for the radio action object.
//
// Parameters:
// group a list representing a radio group
func (r *CRadioAction) SetGroup(group ActionGroup) {
if err := r.SetStructProperty(PropertyGroup, group); err != nil {
r.LogErr(err)
}
}
// GetCurrentValue returns the value property of the currently active member of
// the group to which action belongs.
//
// Returns:
// The value of the currently active group member
func (r *CRadioAction) GetCurrentValue() (value int) {
var err error
if value, err = r.GetIntProperty(PropertyCurrentValue); err != nil {
r.LogErr(err)
}
return
}
// SetCurrentValue updates the currently active group member to the member with
// value property current_value.
//
// Parameters:
// currentValue the new value
func (r *CRadioAction) SetCurrentValue(currentValue int) {
if err := r.SetIntProperty(PropertyCurrentValue, currentValue); err != nil {
r.LogErr(err)
}
}
// The value property of the currently active member of the group to which
// this action belongs.
// Flags: Read / Write
// Default value: 0
const PropertyCurrentValue cdk.Property = "current-value"
// Sets a new group for a radio action.
// Flags: Write
const PropertyGroup cdk.Property = "group"
// The value is an arbitrary integer which can be used as a convenient way to
// determine which action in the group is currently active in an ::activate
// or ::changed signal handler. See GetCurrentValue and
// RadioActionEntry for convenient ways to get and set this property.
// Flags: Read / Write
// Default value: 0
const PropertyRadioActionValue cdk.Property = "value"
// The ::changed signal is emitted on every member of a radio group when the
// active member is changed. The signal gets emitted after the ::activate
// signals for the previous and current active members.
const SignalRadioActionChanged cdk.Signal = "changed"