Began the migration to the new API. Removed locks from the public control APIs; they won't be needed anymore.
This commit is contained in:
parent
05ffc6511a
commit
ea6200a432
11
area.go
11
area.go
|
@ -6,7 +6,6 @@ import (
|
|||
"fmt"
|
||||
"image"
|
||||
"reflect"
|
||||
"sync"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
@ -28,7 +27,6 @@ import (
|
|||
// to lead to trouble.
|
||||
// [FOR FUTURE PLANNING Use TextArea instead, providing a TextAreaHandler.]
|
||||
type Area struct {
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
sysData *sysData
|
||||
handler AreaHandler
|
||||
|
@ -298,9 +296,6 @@ func NewArea(width int, height int, handler AreaHandler) *Area {
|
|||
// SetSize will also signal the entirety of the Area to be redrawn as in RepaintAll.
|
||||
// It panics if width or height is zero or negative.
|
||||
func (a *Area) SetSize(width int, height int) {
|
||||
a.lock.Lock()
|
||||
defer a.lock.Unlock()
|
||||
|
||||
checkAreaSize(width, height, "Area.SetSize()")
|
||||
if a.created {
|
||||
a.sysData.setAreaSize(width, height)
|
||||
|
@ -313,9 +308,6 @@ func (a *Area) SetSize(width int, height int) {
|
|||
// RepaintAll signals the entirety of the Area for redraw.
|
||||
// If called before the Window containing the Area is created, RepaintAll does nothing.
|
||||
func (a *Area) RepaintAll() {
|
||||
a.lock.Lock()
|
||||
defer a.lock.Unlock()
|
||||
|
||||
if !a.created {
|
||||
return
|
||||
}
|
||||
|
@ -323,9 +315,6 @@ func (a *Area) RepaintAll() {
|
|||
}
|
||||
|
||||
func (a *Area) make(window *sysData) error {
|
||||
a.lock.Lock()
|
||||
defer a.lock.Unlock()
|
||||
|
||||
a.sysData.handler = a.handler
|
||||
err := a.sysData.make(window)
|
||||
if err != nil {
|
||||
|
|
20
button.go
20
button.go
|
@ -2,18 +2,8 @@
|
|||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// A Button represents a clickable button with some text.
|
||||
type Button struct {
|
||||
// Clicked gets a message when the button is clicked.
|
||||
// You cannot change it once the Window containing the Button has been created.
|
||||
// If you do not respond to this signal, nothing will happen.
|
||||
Clicked chan struct{}
|
||||
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
sysData *sysData
|
||||
initText string
|
||||
|
@ -30,9 +20,6 @@ func NewButton(text string) (b *Button) {
|
|||
|
||||
// SetText sets the button's text.
|
||||
func (b *Button) SetText(text string) {
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
|
||||
if b.created {
|
||||
b.sysData.setText(text)
|
||||
return
|
||||
|
@ -42,9 +29,6 @@ func (b *Button) SetText(text string) {
|
|||
|
||||
// Text returns the button's text.
|
||||
func (b *Button) Text() string {
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
|
||||
if b.created {
|
||||
return b.sysData.text()
|
||||
}
|
||||
|
@ -52,10 +36,6 @@ func (b *Button) Text() string {
|
|||
}
|
||||
|
||||
func (b *Button) make(window *sysData) error {
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
|
||||
b.sysData.event = b.Clicked
|
||||
err := b.sysData.make(window)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
20
checkbox.go
20
checkbox.go
|
@ -2,13 +2,8 @@
|
|||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// A Checkbox is a clickable square with a label. The square can be either checked or unchecked. Checkboxes start out unchecked.
|
||||
type Checkbox struct {
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
sysData *sysData
|
||||
initText string
|
||||
|
@ -25,9 +20,6 @@ func NewCheckbox(text string) (c *Checkbox) {
|
|||
|
||||
// SetText sets the checkbox's text.
|
||||
func (c *Checkbox) SetText(text string) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.created {
|
||||
c.sysData.setText(text)
|
||||
return
|
||||
|
@ -37,9 +29,6 @@ func (c *Checkbox) SetText(text string) {
|
|||
|
||||
// Text returns the checkbox's text.
|
||||
func (c *Checkbox) Text() string {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.created {
|
||||
return c.sysData.text()
|
||||
}
|
||||
|
@ -48,9 +37,6 @@ func (c *Checkbox) Text() string {
|
|||
|
||||
// SetChecked() changes the checked state of the Checkbox.
|
||||
func (c *Checkbox) SetChecked(checked bool) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.created {
|
||||
c.sysData.setChecked(checked)
|
||||
return
|
||||
|
@ -60,9 +46,6 @@ func (c *Checkbox) SetChecked(checked bool) {
|
|||
|
||||
// Checked() returns whether or not the Checkbox has been checked.
|
||||
func (c *Checkbox) Checked() bool {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.created {
|
||||
return c.sysData.isChecked()
|
||||
}
|
||||
|
@ -70,9 +53,6 @@ func (c *Checkbox) Checked() bool {
|
|||
}
|
||||
|
||||
func (c *Checkbox) make(window *sysData) error {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
err := c.sysData.make(window)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
23
combobox.go
23
combobox.go
|
@ -4,12 +4,10 @@ package ui
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// A Combobox is a drop-down list of items, of which at most one can be selected at any given time. You may optionally make the combobox editable to allow custom items. Initially, no item will be selected (and no text entered in an editable Combobox's entry field). What happens to the text shown in a Combobox if its width is too small is implementation-defined.
|
||||
type Combobox struct {
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
sysData *sysData
|
||||
initItems []string
|
||||
|
@ -37,9 +35,6 @@ func NewEditableCombobox(items ...string) *Combobox {
|
|||
// Append adds items to the end of the Combobox's list.
|
||||
// Append will panic if something goes wrong on platforms that do not abort themselves.
|
||||
func (c *Combobox) Append(what ...string) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.created {
|
||||
for _, s := range what {
|
||||
c.sysData.append(s)
|
||||
|
@ -52,9 +47,6 @@ func (c *Combobox) Append(what ...string) {
|
|||
// InsertBefore inserts a new item in the Combobox before the item at the given position. It panics if the given index is out of bounds.
|
||||
// InsertBefore will also panic if something goes wrong on platforms that do not abort themselves.
|
||||
func (c *Combobox) InsertBefore(what string, before int) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
var m []string
|
||||
|
||||
if c.created {
|
||||
|
@ -78,9 +70,6 @@ badrange:
|
|||
|
||||
// Delete removes the given item from the Combobox. It panics if the given index is out of bounds.
|
||||
func (c *Combobox) Delete(index int) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.created {
|
||||
if index < 0 || index >= c.sysData.len() {
|
||||
goto badrange
|
||||
|
@ -99,9 +88,6 @@ badrange:
|
|||
|
||||
// Selection returns the current selection.
|
||||
func (c *Combobox) Selection() string {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.created {
|
||||
return c.sysData.text()
|
||||
}
|
||||
|
@ -110,9 +96,6 @@ func (c *Combobox) Selection() string {
|
|||
|
||||
// SelectedIndex returns the index of the current selection in the Combobox. It returns -1 either if no selection was made or if text was manually entered in an editable Combobox.
|
||||
func (c *Combobox) SelectedIndex() int {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.created {
|
||||
return c.sysData.selectedIndex()
|
||||
}
|
||||
|
@ -123,9 +106,6 @@ func (c *Combobox) SelectedIndex() int {
|
|||
//
|
||||
// On platforms for which this function may return an error, it panics if one is returned.
|
||||
func (c *Combobox) Len() int {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.created {
|
||||
return c.sysData.len()
|
||||
}
|
||||
|
@ -133,9 +113,6 @@ func (c *Combobox) Len() int {
|
|||
}
|
||||
|
||||
func (c *Combobox) make(window *sysData) (err error) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
err = c.sysData.make(window)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
11
grid.go
11
grid.go
|
@ -4,7 +4,6 @@ package ui
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// A Grid arranges Controls in a two-dimensional grid.
|
||||
|
@ -16,7 +15,6 @@ import (
|
|||
// A stretchy Control implicitly fills its cell.
|
||||
// All cooridnates in a Grid are given in (row,column) form with (0,0) being the top-left cell.
|
||||
type Grid struct {
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
controls [][]Control
|
||||
filling [][]bool
|
||||
|
@ -69,9 +67,6 @@ func NewGrid(nPerRow int, controls ...Control) *Grid {
|
|||
// This function cannot be called after the Window that contains the Grid has been created.
|
||||
// It panics if the given coordinate is invalid.
|
||||
func (g *Grid) SetFilling(row int, column int) {
|
||||
g.lock.Lock()
|
||||
defer g.lock.Unlock()
|
||||
|
||||
if g.created {
|
||||
panic(fmt.Errorf("Grid.SetFilling() called after window create"))
|
||||
}
|
||||
|
@ -87,9 +82,6 @@ func (g *Grid) SetFilling(row int, column int) {
|
|||
// This function cannot be called after the Window that contains the Grid has been created.
|
||||
// It panics if the given coordinate is invalid.
|
||||
func (g *Grid) SetStretchy(row int, column int) {
|
||||
g.lock.Lock()
|
||||
defer g.lock.Unlock()
|
||||
|
||||
if g.created {
|
||||
panic(fmt.Errorf("Grid.SetFilling() called after window create"))
|
||||
}
|
||||
|
@ -102,9 +94,6 @@ func (g *Grid) SetStretchy(row int, column int) {
|
|||
}
|
||||
|
||||
func (g *Grid) make(window *sysData) error {
|
||||
g.lock.Lock()
|
||||
defer g.lock.Unlock()
|
||||
|
||||
// commit filling for the stretchy control now (see SetStretchy() above)
|
||||
if g.stretchyrow != -1 && g.stretchycol != -1 {
|
||||
g.filling[g.stretchyrow][g.stretchycol] = true
|
||||
|
|
14
label.go
14
label.go
|
@ -2,16 +2,11 @@
|
|||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// A Label is a static line of text used to mark other controls.
|
||||
// Label text is drawn on a single line; text that does not fit is truncated.
|
||||
// A Label can appear in one of two places: bound to a control or standalone.
|
||||
// This determines the vertical alignment of the label.
|
||||
type Label struct {
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
sysData *sysData
|
||||
initText string
|
||||
|
@ -39,9 +34,6 @@ func NewStandaloneLabel(text string) *Label {
|
|||
|
||||
// SetText sets the Label's text.
|
||||
func (l *Label) SetText(text string) {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
if l.created {
|
||||
l.sysData.setText(text)
|
||||
return
|
||||
|
@ -51,9 +43,6 @@ func (l *Label) SetText(text string) {
|
|||
|
||||
// Text returns the Label's text.
|
||||
func (l *Label) Text() string {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
if l.created {
|
||||
return l.sysData.text()
|
||||
}
|
||||
|
@ -61,9 +50,6 @@ func (l *Label) Text() string {
|
|||
}
|
||||
|
||||
func (l *Label) make(window *sysData) error {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
l.sysData.alternate = l.standalone
|
||||
err := l.sysData.make(window)
|
||||
if err != nil {
|
||||
|
|
14
lineedit.go
14
lineedit.go
|
@ -2,13 +2,8 @@
|
|||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// A LineEdit is a control which allows you to enter a single line of text.
|
||||
type LineEdit struct {
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
sysData *sysData
|
||||
initText string
|
||||
|
@ -33,9 +28,6 @@ func NewPasswordEdit() *LineEdit {
|
|||
|
||||
// SetText sets the LineEdit's text.
|
||||
func (l *LineEdit) SetText(text string) {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
if l.created {
|
||||
l.sysData.setText(text)
|
||||
return
|
||||
|
@ -45,9 +37,6 @@ func (l *LineEdit) SetText(text string) {
|
|||
|
||||
// Text returns the LineEdit's text.
|
||||
func (l *LineEdit) Text() string {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
if l.created {
|
||||
return l.sysData.text()
|
||||
}
|
||||
|
@ -55,9 +44,6 @@ func (l *LineEdit) Text() string {
|
|||
}
|
||||
|
||||
func (l *LineEdit) make(window *sysData) error {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
l.sysData.alternate = l.password
|
||||
err := l.sysData.make(window)
|
||||
if err != nil {
|
||||
|
|
23
listbox.go
23
listbox.go
|
@ -4,7 +4,6 @@ package ui
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// A Listbox is a vertical list of items, of which either at most one or any number of items can be selected at any given time.
|
||||
|
@ -12,7 +11,6 @@ import (
|
|||
// For information on scrollbars, see "Scrollbars" in the Overview.
|
||||
// Due to implementation issues, the presence of horizontal scrollbars is currently implementation-defined.
|
||||
type Listbox struct {
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
sysData *sysData
|
||||
initItems []string
|
||||
|
@ -40,9 +38,6 @@ func NewMultiSelListbox(items ...string) *Listbox {
|
|||
// Append adds items to the end of the Listbox's list.
|
||||
// Append will panic if something goes wrong on platforms that do not abort themselves.
|
||||
func (l *Listbox) Append(what ...string) {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
if l.created {
|
||||
for _, s := range what {
|
||||
l.sysData.append(s)
|
||||
|
@ -55,9 +50,6 @@ func (l *Listbox) Append(what ...string) {
|
|||
// 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.
|
||||
// InsertBefore will also panic if something goes wrong on platforms that do not abort themselves.
|
||||
func (l *Listbox) InsertBefore(what string, before int) {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
var m []string
|
||||
|
||||
if l.created {
|
||||
|
@ -81,9 +73,6 @@ badrange:
|
|||
|
||||
// Delete removes the given item from the Listbox. It panics if the given index is out of bounds.
|
||||
func (l *Listbox) Delete(index int) {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
if l.created {
|
||||
if index < 0 || index >= l.sysData.len() {
|
||||
goto badrange
|
||||
|
@ -102,9 +91,6 @@ badrange:
|
|||
|
||||
// Selection returns a list of strings currently selected in the Listbox, or an empty list if none have been selected. This list will have at most one item on a single-selection Listbox.
|
||||
func (l *Listbox) Selection() []string {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
if l.created {
|
||||
return l.sysData.selectedTexts()
|
||||
}
|
||||
|
@ -113,9 +99,6 @@ func (l *Listbox) Selection() []string {
|
|||
|
||||
// SelectedIndices returns a list of the currently selected indexes in the Listbox, or an empty list if none have been selected. This list will have at most one item on a single-selection Listbox.
|
||||
func (l *Listbox) SelectedIndices() []int {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
if l.created {
|
||||
return l.sysData.selectedIndices()
|
||||
}
|
||||
|
@ -126,9 +109,6 @@ func (l *Listbox) SelectedIndices() []int {
|
|||
//
|
||||
// On platforms for which this function may return an error, it panics if one is returned.
|
||||
func (l *Listbox) Len() int {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
if l.created {
|
||||
return l.sysData.len()
|
||||
}
|
||||
|
@ -136,9 +116,6 @@ func (l *Listbox) Len() int {
|
|||
}
|
||||
|
||||
func (l *Listbox) make(window *sysData) (err error) {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
err = l.sysData.make(window)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -2,16 +2,11 @@
|
|||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// A ProgressBar is a horizontal rectangle that fills up from left to right to indicate the progress of a long-running task.
|
||||
// This progress is represented by an integer within the range [0,100], representing a percentage.
|
||||
// Alternatively, a progressbar can show an animation indicating that progress is being made but how much is indeterminate.
|
||||
// Newly-created ProgressBars default to showing 0% progress.
|
||||
type ProgressBar struct {
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
sysData *sysData
|
||||
initProg int
|
||||
|
@ -30,9 +25,6 @@ func NewProgressBar() *ProgressBar {
|
|||
// Otherwise, SetProgress panics.
|
||||
// Calling SetProgress(-1) repeatedly will neither leave indeterminate mode nor stop any animation involved in indeterminate mode indefinitely; any other side-effect of doing so is implementation-defined.
|
||||
func (p *ProgressBar) SetProgress(percent int) {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
if percent < -1 || percent > 100 {
|
||||
panic("percent value out of range")
|
||||
}
|
||||
|
@ -44,9 +36,6 @@ func (p *ProgressBar) SetProgress(percent int) {
|
|||
}
|
||||
|
||||
func (p *ProgressBar) make(window *sysData) error {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
err := p.sysData.make(window)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
8
stack.go
8
stack.go
|
@ -4,7 +4,6 @@ package ui
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type orientation bool
|
||||
|
@ -20,7 +19,6 @@ const (
|
|||
// Any extra space at the end of a Stack is left blank.
|
||||
// Some controls may be marked as "stretchy": when the Window they are in changes size, stretchy controls resize to take up the remaining space after non-stretchy controls are laid out. If multiple controls are marked stretchy, they are alloted equal distribution of the remaining space.
|
||||
type Stack struct {
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
orientation orientation
|
||||
controls []Control
|
||||
|
@ -51,9 +49,6 @@ func NewVerticalStack(controls ...Control) *Stack {
|
|||
// SetStretchy marks a control in a Stack as stretchy. This cannot be called once the Window containing the Stack has been created.
|
||||
// It panics if index is out of range.
|
||||
func (s *Stack) SetStretchy(index int) {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
if s.created {
|
||||
panic("call to Stack.SetStretchy() after Stack has been created")
|
||||
}
|
||||
|
@ -64,9 +59,6 @@ func (s *Stack) SetStretchy(index int) {
|
|||
}
|
||||
|
||||
func (s *Stack) make(window *sysData) error {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
for i, c := range s.controls {
|
||||
err := c.make(window)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue