Added Separator.
This commit is contained in:
parent
ae710db0e9
commit
2347394944
|
@ -0,0 +1,68 @@
|
||||||
|
// 12 december 2015
|
||||||
|
|
||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// #include "ui.h"
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
// Separator is a Control that represents a horizontal line that
|
||||||
|
// visually separates controls.
|
||||||
|
type Separator struct {
|
||||||
|
c *C.uiControl
|
||||||
|
s *C.uiSeparator
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSeparator creates a new horizontal Separator.
|
||||||
|
func NewHorizontalSeparator() *Separator {
|
||||||
|
s := new(Separator)
|
||||||
|
|
||||||
|
s.s = C.uiNewHorizontalSeparator()
|
||||||
|
s.c = (*C.uiControl)(unsafe.Pointer(s.s))
|
||||||
|
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destroy destroys the Separator.
|
||||||
|
func (s *Separator) Destroy() {
|
||||||
|
C.uiControlDestroy(s.c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LibuiControl returns the libui uiControl pointer that backs
|
||||||
|
// the Window. This is only used by package ui itself and should
|
||||||
|
// not be called by programs.
|
||||||
|
func (s *Separator) LibuiControl() uintptr {
|
||||||
|
return uintptr(unsafe.Pointer(s.c))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle returns the OS-level handle associated with this Separator.
|
||||||
|
// On Windows this is an HWND of a standard Windows API STATIC
|
||||||
|
// class (as provided by Common Controls version 6).
|
||||||
|
// On GTK+ this is a pointer to a GtkSeparator.
|
||||||
|
// On OS X this is a pointer to a NSBox.
|
||||||
|
func (s *Separator) Handle() uintptr {
|
||||||
|
return uintptr(C.uiControlHandle(s.c))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show shows the Separator.
|
||||||
|
func (s *Separator) Show() {
|
||||||
|
C.uiControlShow(s.c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide hides the Separator.
|
||||||
|
func (s *Separator) Hide() {
|
||||||
|
C.uiControlHide(s.c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable enables the Separator.
|
||||||
|
func (s *Separator) Enable() {
|
||||||
|
C.uiControlEnable(s.c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable disables the Separator.
|
||||||
|
func (s *Separator) Disable() {
|
||||||
|
C.uiControlDisable(s.c)
|
||||||
|
}
|
26
zz_test.go
26
zz_test.go
|
@ -2,38 +2,18 @@
|
||||||
|
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
import "time"
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestIt(t *testing.T) {
|
func TestIt(t *testing.T) {
|
||||||
err := Main(func() {
|
err := Main(func() {
|
||||||
w := NewWindow("Hello", 320, 240, false)
|
w := NewWindow("Hello", 320, 240, false)
|
||||||
stop := make(chan struct{})
|
|
||||||
w.OnClosing(func(w *Window) bool {
|
w.OnClosing(func(w *Window) bool {
|
||||||
stop <- struct{}{}
|
|
||||||
Quit()
|
Quit()
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
p := NewProgressBar()
|
s := NewHorizontalSeparator()
|
||||||
w.SetChild(p)
|
w.SetChild(s)
|
||||||
go func() {
|
w.SetMargined(true)
|
||||||
value := 0
|
|
||||||
ticker := time.NewTicker(time.Second / 2)
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ticker.C:
|
|
||||||
QueueMain(func() {
|
|
||||||
value++
|
|
||||||
if value > 100 {
|
|
||||||
value = 0
|
|
||||||
}
|
|
||||||
p.SetValue(value)
|
|
||||||
})
|
|
||||||
case <-stop:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
w.Show()
|
w.Show()
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue