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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// InsertBefore inserts a new item in the Listbox before the item at the given position.
|
// 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.
|
||||||
// (TODO action on invalid index)
|
|
||||||
func (l *Listbox) InsertBefore(what string, before int) (err error) {
|
func (l *Listbox) InsertBefore(what string, before int) (err error) {
|
||||||
l.lock.Lock()
|
l.lock.Lock()
|
||||||
defer l.lock.Unlock()
|
defer l.lock.Unlock()
|
||||||
|
|
||||||
|
var m []string
|
||||||
|
|
||||||
if l.created {
|
if l.created {
|
||||||
|
if before < 0 || before >= l.sysData.len() {
|
||||||
|
goto badrange
|
||||||
|
}
|
||||||
return l.sysData.insertBefore(what, before)
|
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, l.initItems[:before]...)
|
||||||
m = append(m, what)
|
m = append(m, what)
|
||||||
l.initItems = append(m, l.initItems[before:]...)
|
l.initItems = append(m, l.initItems[before:]...)
|
||||||
return nil
|
return nil
|
||||||
|
badrange:
|
||||||
|
panic(fmt.Errorf("index %d out of range in Listbox.InsertBefore()", before))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete removes the given item from the Listbox.
|
// Delete removes the given item from the Listbox.
|
||||||
|
|
|
@ -59,8 +59,13 @@ func invalidTest(c *Combobox, l *Listbox) {
|
||||||
func() {
|
func() {
|
||||||
defer x("Listbox.Delete > len"); c.Delete(c.Len() + 5); panic(nil)
|
defer x("Listbox.Delete > len"); c.Delete(c.Len() + 5); panic(nil)
|
||||||
}()
|
}()
|
||||||
// TODO
|
func() {
|
||||||
_ = l
|
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")
|
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.DeleteAll
|
||||||
- Combobox/Listbox.Select (with Listbox.Select allowing bulk)
|
- Combobox/Listbox.Select (with Listbox.Select allowing bulk)
|
||||||
- Listbox.SelectAll
|
- 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
|
- same for other methods that take indices, like the Stack and Grid stretchy methods
|
||||||
- make the Windows implementation of message boxes run on uitask
|
- make the Windows implementation of message boxes run on uitask
|
||||||
- ensure MsgBoxError can run if initialization failed if things change ever
|
- ensure MsgBoxError can run if initialization failed if things change ever
|
||||||
- should Labels be selectable?
|
- should Labels be selectable?
|
||||||
- should message box text be selectable on all platforms or only on those that make it the default?
|
- 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?
|
- Index(n) is the name used by reflect.Value; use a different one?
|
||||||
|
|
||||||
important things:
|
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
|
- 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 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)
|
- 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
|
- 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:
|
super ultra important things:
|
||||||
|
|
Loading…
Reference in New Issue