Added Checkbox.SetChecked() and implemented it on GTK+.
This commit is contained in:
parent
5c002e3d0f
commit
098beef996
19
checkbox.go
19
checkbox.go
|
@ -12,7 +12,7 @@ type Checkbox struct {
|
||||||
created bool
|
created bool
|
||||||
sysData *sysData
|
sysData *sysData
|
||||||
initText string
|
initText string
|
||||||
initCheck bool
|
initCheck bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCheckbox creates a new checkbox with the specified text.
|
// NewCheckbox creates a new checkbox with the specified text.
|
||||||
|
@ -46,7 +46,19 @@ func (c *Checkbox) Text() string {
|
||||||
return c.initText
|
return c.initText
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checked() returns whether or not the checkbox has been checked.
|
// 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
|
||||||
|
}
|
||||||
|
c.initCheck = checked
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checked() returns whether or not the Checkbox has been checked.
|
||||||
func (c *Checkbox) Checked() bool {
|
func (c *Checkbox) Checked() bool {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
|
@ -54,7 +66,7 @@ func (c *Checkbox) Checked() bool {
|
||||||
if c.created {
|
if c.created {
|
||||||
return c.sysData.isChecked()
|
return c.sysData.isChecked()
|
||||||
}
|
}
|
||||||
return false
|
return c.initCheck
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Checkbox) make(window *sysData) error {
|
func (c *Checkbox) make(window *sysData) error {
|
||||||
|
@ -66,6 +78,7 @@ func (c *Checkbox) make(window *sysData) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.sysData.setText(c.initText)
|
c.sysData.setText(c.initText)
|
||||||
|
c.sysData.setChecked(c.initCheck)
|
||||||
c.created = true
|
c.created = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,6 +153,10 @@ func gtk_toggle_button_get_active(widget *C.GtkWidget) bool {
|
||||||
return fromgbool(C.gtk_toggle_button_get_active(togtktogglebutton(widget)))
|
return fromgbool(C.gtk_toggle_button_get_active(togtktogglebutton(widget)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func gtk_toggle_button_set_active(widget *C.GtkWidget, checked bool) {
|
||||||
|
C.gtk_toggle_button_set_active(togtktogglebutton(widget), togbool(checked))
|
||||||
|
}
|
||||||
|
|
||||||
func gtk_combo_box_text_new() *C.GtkWidget {
|
func gtk_combo_box_text_new() *C.GtkWidget {
|
||||||
w := C.gtk_combo_box_text_new()
|
w := C.gtk_combo_box_text_new()
|
||||||
C.gtkSetComboBoxArbitrarilyResizeable(w)
|
C.gtkSetComboBoxArbitrarilyResizeable(w)
|
||||||
|
|
|
@ -41,6 +41,7 @@ var _xSysData interface {
|
||||||
setAreaSize(int, int)
|
setAreaSize(int, int)
|
||||||
repaintAll()
|
repaintAll()
|
||||||
center()
|
center()
|
||||||
|
setChecked(bool)
|
||||||
} = &sysData{} // this line will error if there's an inconsistency
|
} = &sysData{} // this line will error if there's an inconsistency
|
||||||
|
|
||||||
// signal sends the event signal. This raise is done asynchronously to avoid deadlocking the UI task.
|
// signal sends the event signal. This raise is done asynchronously to avoid deadlocking the UI task.
|
||||||
|
|
|
@ -410,3 +410,13 @@ func (s *sysData) center() {
|
||||||
}
|
}
|
||||||
<-ret
|
<-ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *sysData) setChecked(checked bool) {
|
||||||
|
ret := make(chan struct{})
|
||||||
|
defer close(ret)
|
||||||
|
uitask <- func() {
|
||||||
|
gtk_toggle_button_set_active(s.widget, checked)
|
||||||
|
ret <- struct{}{}
|
||||||
|
}
|
||||||
|
<-ret
|
||||||
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ func gridWindow() *Window {
|
||||||
b12 := NewButton("1,2")
|
b12 := NewButton("1,2")
|
||||||
l20 := NewLabel("2,0")
|
l20 := NewLabel("2,0")
|
||||||
c21 := NewCheckbox("2,1")
|
c21 := NewCheckbox("2,1")
|
||||||
|
c21.SetChecked(true)
|
||||||
l22 := NewLabel("2,2")
|
l22 := NewLabel("2,2")
|
||||||
g := NewGrid(3,
|
g := NewGrid(3,
|
||||||
b00, b01, b02,
|
b00, b01, b02,
|
||||||
|
@ -43,6 +44,10 @@ func gridWindow() *Window {
|
||||||
g.SetStretchy(1, 1)
|
g.SetStretchy(1, 1)
|
||||||
w.SetSpaced(*spacingTest)
|
w.SetSpaced(*spacingTest)
|
||||||
w.Open(g)
|
w.Open(g)
|
||||||
|
go func() {for {select {
|
||||||
|
case <-b12.Clicked:
|
||||||
|
c21.SetChecked(!c21.Checked())
|
||||||
|
}}}()
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue