| skipped 153 lines |
154 | 154 | | ) |
155 | 155 | | } |
156 | 156 | | |
157 | | - | // Keyboard processes keyboard events, acts as a button press on the configured |
158 | | - | // Key. |
159 | | - | // |
160 | | - | // Implements widgetapi.Widget.Keyboard. |
161 | | - | func (b *Button) Keyboard(k *terminalapi.Keyboard) error { |
| 157 | + | // activated asserts whether the keyboard event activated the button. |
| 158 | + | func (b *Button) keyActivated(k *terminalapi.Keyboard) bool { |
162 | 159 | | b.mu.Lock() |
163 | 160 | | defer b.mu.Unlock() |
164 | 161 | | |
| skipped 1 lines |
166 | 163 | | b.state = button.Down |
167 | 164 | | now := time.Now().UTC() |
168 | 165 | | b.keyTriggerTime = &now |
| 166 | + | return true |
| 167 | + | } |
| 168 | + | return false |
| 169 | + | } |
| 170 | + | |
| 171 | + | // Keyboard processes keyboard events, acts as a button press on the configured |
| 172 | + | // Key. |
| 173 | + | // |
| 174 | + | // Implements widgetapi.Widget.Keyboard. |
| 175 | + | func (b *Button) Keyboard(k *terminalapi.Keyboard) error { |
| 176 | + | if b.keyActivated(k) { |
| 177 | + | // Mutex must be released when calling the callback. |
| 178 | + | // Users might call container methods from the callback like the |
| 179 | + | // Container.Update, see #205. |
169 | 180 | | return b.callback() |
170 | 181 | | } |
171 | 182 | | return nil |
172 | 183 | | } |
173 | 184 | | |
174 | | - | // Mouse processes mouse events, acts as a button press if both the press and |
175 | | - | // the release happen inside the button. |
176 | | - | // |
177 | | - | // Implements widgetapi.Widget.Mouse. |
178 | | - | func (b *Button) Mouse(m *terminalapi.Mouse) error { |
| 185 | + | // mouseActivated asserts whether the mouse event activated the button. |
| 186 | + | func (b *Button) mouseActivated(m *terminalapi.Mouse) bool { |
179 | 187 | | b.mu.Lock() |
180 | 188 | | defer b.mu.Unlock() |
181 | 189 | | |
| skipped 1 lines |
183 | 191 | | b.state = state |
184 | 192 | | b.keyTriggerTime = nil |
185 | 193 | | |
186 | | - | if clicked { |
| 194 | + | return clicked |
| 195 | + | } |
| 196 | + | |
| 197 | + | // Mouse processes mouse events, acts as a button press if both the press and |
| 198 | + | // the release happen inside the button. |
| 199 | + | // |
| 200 | + | // Implements widgetapi.Widget.Mouse. |
| 201 | + | func (b *Button) Mouse(m *terminalapi.Mouse) error { |
| 202 | + | if b.mouseActivated(m) { |
| 203 | + | // Mutex must be released when calling the callback. |
| 204 | + | // Users might call container methods from the callback like the |
| 205 | + | // Container.Update, see #205. |
187 | 206 | | return b.callback() |
188 | 207 | | } |
189 | 208 | | return nil |
| skipped 19 lines |