selNext selects or highlights the next item, if possible
(sel bool, update bool)
| 236 | |
| 237 | // selNext selects or highlights the next item, if possible |
| 238 | func (li *List) selNext(sel bool, update bool) *ListItem { |
| 239 | |
| 240 | // Checks for empty list |
| 241 | if len(li.items) == 0 { |
| 242 | return nil |
| 243 | } |
| 244 | // Find currently selected item |
| 245 | var pos int |
| 246 | if sel { |
| 247 | pos = li.selected() |
| 248 | } else { |
| 249 | pos = li.highlighted() |
| 250 | } |
| 251 | |
| 252 | var newItem *ListItem |
| 253 | newSel := true |
| 254 | // If no item found, returns first. |
| 255 | if pos < 0 { |
| 256 | newItem = li.items[0].(*ListItem) |
| 257 | if sel { |
| 258 | newItem.SetSelected(true) |
| 259 | } else { |
| 260 | newItem.SetHighlighted(true) |
| 261 | } |
| 262 | } else { |
| 263 | item := li.items[pos].(*ListItem) |
| 264 | // Item is not the last, get next |
| 265 | if pos < len(li.items)-1 { |
| 266 | newItem = li.items[pos+1].(*ListItem) |
| 267 | if sel { |
| 268 | item.SetSelected(false) |
| 269 | newItem.SetSelected(true) |
| 270 | } else { |
| 271 | item.SetHighlighted(false) |
| 272 | newItem.SetHighlighted(true) |
| 273 | } |
| 274 | if !li.ItemVisible(pos + 1) { |
| 275 | li.ScrollDown() |
| 276 | } |
| 277 | // Item is the last, don't change |
| 278 | } else { |
| 279 | newItem = item |
| 280 | newSel = false |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | if update { |
| 285 | li.update() |
| 286 | } |
| 287 | if sel && newSel { |
| 288 | li.Dispatch(OnChange, nil) |
| 289 | } |
| 290 | return newItem |
| 291 | } |
| 292 | |
| 293 | // selPrev selects or highlights the next item, if possible |
| 294 | func (li *List) selPrev(sel bool, update bool) *ListItem { |
no test coverage detected