andlabs-ui/sysdata.go

128 lines
3.4 KiB
Go
Raw Normal View History

// 11 february 2014
package ui
import (
"runtime"
)
const eventbufsiz = 100 // suggested by skelterjohn
// newEvent returns a new channel suitable for listening for events.
func newEvent() chan struct{} {
return make(chan struct{}, eventbufsiz)
}
// The sysData type contains all system data. It provides the system-specific underlying implementation. It is guaranteed to have the following by embedding:
type cSysData struct {
2014-02-12 19:57:30 -06:00
ctype int
event chan struct{}
resize func(x int, y int, width int, height int, rr *[]resizerequest)
resizes []resizerequest
alternate bool // editable for Combobox, multi-select for listbox, password for lineedit
handler AreaHandler // for Areas
}
func (c *cSysData) make(initText string, window *sysData) error {
panic(runtime.GOOS + " sysData does not define make()")
}
func (c *cSysData) firstShow() error {
panic(runtime.GOOS + " sysData does not define firstShow()")
}
func (c *cSysData) show() {
panic(runtime.GOOS + " sysData does not define show()")
}
func (c *cSysData) hide() {
panic(runtime.GOOS + " sysData does not define hide()")
}
func (c *cSysData) setText(text string) {
panic(runtime.GOOS + " sysData does not define setText()")
}
func (c *cSysData) setRect(x int, y int, width int, height int, winheight int) error {
panic(runtime.GOOS + " sysData does not define setRect()")
}
func (c *cSysData) isChecked() bool {
2014-02-13 14:14:10 -06:00
panic(runtime.GOOS + " sysData does not define isChecked()")
}
2014-02-15 13:03:46 -06:00
func (c *cSysData) text() string {
2014-02-14 11:16:27 -06:00
panic(runtime.GOOS + " sysData does not define text()")
}
func (c *cSysData) append(string) {
2014-02-14 11:16:27 -06:00
panic(runtime.GOOS + " sysData does not define append()")
}
func (c *cSysData) insertBefore(string, int) {
2014-02-15 11:06:29 -06:00
panic(runtime.GOOS + " sysData does not define insertBefore()")
}
2014-02-15 13:03:46 -06:00
func (c *cSysData) selectedIndex() int {
panic(runtime.GOOS + " sysData does not define selectedIndex()")
}
2014-02-15 13:03:46 -06:00
func (c *cSysData) selectedIndices() []int {
panic(runtime.GOOS + " sysData does not define selectedIndices()")
}
2014-02-15 13:03:46 -06:00
func (c *cSysData) selectedTexts() []string {
panic(runtime.GOOS + " sysData does not define selectedIndex()")
}
func (c *cSysData) setWindowSize(int, int) error {
panic(runtime.GOOS + " sysData does not define setWindowSize()")
}
func (c *cSysData) delete(int) {
panic(runtime.GOOS + " sysData does not define delete()")
}
func (c *cSysData) preferredSize() (int, int) {
panic(runtime.GOOS + " sysData does not define preferredSize()")
}
2014-02-24 23:13:47 -06:00
func (c *cSysData) setProgress(int) {
panic(runtime.GOOS + " sysData does not define setProgress()")
}
func (c *cSysData) len() int {
panic(runtime.GOOS + " sysData does not define len()")
}
func (c *cSysData) setAreaSize(int, int) {
panic(runtime.GOOS + " sysData does not define setAreaSize()")
}
// signal sends the event signal. This raise is done asynchronously to avoid deadlocking the UI task.
// Thanks skelterjohn for this techinque: if we can't queue any more events, drop them
func (s *cSysData) signal() {
if s.event != nil {
go func() {
select {
case s.event <- struct{}{}:
default:
}
}()
}
}
const (
c_window = iota
c_button
c_checkbox
2014-02-14 11:16:27 -06:00
c_combobox
2014-02-14 14:00:59 -06:00
c_lineedit
2014-02-14 14:12:03 -06:00
c_label
c_listbox
2014-02-24 23:13:47 -06:00
c_progressbar
c_area
nctypes
)
func mksysdata(ctype int) *sysData {
s := &sysData{
cSysData: cSysData{
ctype: ctype,
},
}
if ctype == c_window { // make resizes non-nil so it can be passed in
s.resizes = make([]resizerequest, 0, 0)
}
return s
}
type resizerequest struct {
sysData *sysData
x int
y int
width int
height int
}