From f0544de1f24c2e318954b9a7a31faad93b92fabd Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 16 Feb 2022 11:14:05 +0100 Subject: [PATCH] Added RemoveOption() and GetOptionCount() to DropDown. Resolves #682 --- dropdown.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dropdown.go b/dropdown.go index 561ea32..9816279 100644 --- a/dropdown.go +++ b/dropdown.go @@ -267,6 +267,19 @@ func (d *DropDown) SetOptions(texts []string, selected func(text string, index i return d } +// GetOptionCount returns the number of options in the drop-down. +func (d *DropDown) GetOptionCount() int { + return len(d.options) +} + +// RemoveOption removes the specified option from the drop-down. Panics if the +// index is out of range. +func (d *DropDown) RemoveOption(index int) *DropDown { + d.options = append(d.options[:index], d.options[index+1:]...) + d.list.RemoveItem(index) + return d +} + // SetSelectedFunc sets a handler which is called when the user changes the // drop-down's option. This handler will be called in addition and prior to // an option's optional individual handler. The handler is provided with the