Added bounds checks for Listbox.InsertBefore(). This stupid 32-bit Mac bug keeps Listbox.Delete() unchecked for now...
This commit is contained in:
parent
3e47b00eda
commit
f4506277b9
15
listbox.go
15
listbox.go
|
@ -45,20 +45,29 @@ func (l *Listbox) Append(what ...string) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
// InsertBefore inserts a new item in the Listbox before the item at the given position.
|
||||
// (TODO action on invalid index)
|
||||
// InsertBefore inserts a new item in the Listbox before the item at the given position. It panics if the given index is out of bounds.
|
||||
func (l *Listbox) InsertBefore(what string, before int) (err error) {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
var m []string
|
||||
|
||||
if l.created {
|
||||
if before < 0 || before >= l.sysData.len() {
|
||||
goto badrange
|
||||
}
|
||||
return l.sysData.insertBefore(what, before)
|
||||
}
|
||||
m := make([]string, 0, len(l.initItems) + 1)
|
||||
if before < 0 || before >= len(l.initItems) {
|
||||
goto badrange
|
||||
}
|
||||
m = make([]string, 0, len(l.initItems) + 1)
|
||||
m = append(m, l.initItems[:before]...)
|
||||
m = append(m, what)
|
||||
l.initItems = append(m, l.initItems[before:]...)
|
||||
return nil
|
||||
badrange:
|
||||
panic(fmt.Errorf("index %d out of range in Listbox.InsertBefore()", before))
|
||||
}
|
||||
|
||||
// Delete removes the given item from the Listbox.
|
||||
|
|
|
@ -59,8 +59,13 @@ func invalidTest(c *Combobox, l *Listbox) {
|
|||
func() {
|
||||
defer x("Listbox.Delete > len"); c.Delete(c.Len() + 5); panic(nil)
|
||||
}()
|
||||
// TODO
|
||||
_ = l
|
||||
func() {
|
||||
defer x("Listbox.InsertBefore < 0"); l.InsertBefore("xxx", -5); panic(nil)
|
||||
}()
|
||||
func() {
|
||||
defer x("Listbox.InsertBefore > len"); l.InsertBefore("xxx", l.Len() + 5); panic(nil)
|
||||
}()
|
||||
// TODO add Listbox.Delete() tests when I move that over
|
||||
MsgBox("test", "all working as intended")
|
||||
}
|
||||
|
||||
|
|
5
todo.md
5
todo.md
|
@ -17,13 +17,13 @@ so I don't forget:
|
|||
- Combobox/Listbox.DeleteAll
|
||||
- Combobox/Listbox.Select (with Listbox.Select allowing bulk)
|
||||
- Listbox.SelectAll
|
||||
- have Combobox.InsertBefore, Listbox.InsertBefore, Combobox.Delete, and Listbox.Delete return an error on invalid index before creation, or have them panic like an invalid array index, etc.; decide which to do as these do differnet things on different platforms by default
|
||||
- have Listbox.Delete() panic on invalid index; it does not yet due to the Mac OS X signaling issue mentioned under "super important"
|
||||
- same for other methods that take indices, like the Stack and Grid stretchy methods
|
||||
- make the Windows implementation of message boxes run on uitask
|
||||
- ensure MsgBoxError can run if initialization failed if things change ever
|
||||
- should Labels be selectable?
|
||||
- should message box text be selectable on all platforms or only on those that make it the default?
|
||||
- Listbox/Combobox.Len(), Index(n)
|
||||
- Listbox/Combobox.Index(n)
|
||||
- Index(n) is the name used by reflect.Value; use a different one?
|
||||
|
||||
important things:
|
||||
|
@ -45,6 +45,7 @@ important things:
|
|||
- sometimes the size of the drop-down part of a Combobox becomes 0 or 1 or some other impossibly small value on Windows
|
||||
- make gcc (Unix)/clang (Mac OS X) pedantic about warnings/errors; also -Werror
|
||||
- make sure scrollbars in Listbox work identically on all platforms (specifically the existence and autohiding of both horizontal and vertical scrollbars)
|
||||
- pin down this behavior; also note non-editability
|
||||
- GTK+ windows cannot be resized smaller than their controls's current sizes in their current positions; find out how to overrule that so they can be freely resized
|
||||
|
||||
super ultra important things:
|
||||
|
|
Loading…
Reference in New Issue