bool.go raw

   1  package widget
   2  
   3  import (
   4  	"github.com/p9c/p9/pkg/gel/gio/layout"
   5  )
   6  
   7  type Bool struct {
   8  	Value bool
   9  
  10  	clk Clickable
  11  
  12  	changed bool
  13  }
  14  
  15  // Changed reports whether Value has changed since the last
  16  // call to Changed.
  17  func (b *Bool) Changed() bool {
  18  	changed := b.changed
  19  	b.changed = false
  20  	return changed
  21  }
  22  
  23  // Hovered returns whether pointer is over the element.
  24  func (b *Bool) Hovered() bool {
  25  	return b.clk.Hovered()
  26  }
  27  
  28  // Pressed returns whether pointer is pressing the element.
  29  func (b *Bool) Pressed() bool {
  30  	return b.clk.Pressed()
  31  }
  32  
  33  func (b *Bool) History() []Press {
  34  	return b.clk.History()
  35  }
  36  
  37  func (b *Bool) Layout(gtx layout.Context) layout.Dimensions {
  38  	dims := b.clk.Layout(gtx)
  39  	for b.clk.Clicked() {
  40  		b.Value = !b.Value
  41  		b.changed = true
  42  	}
  43  	return dims
  44  }
  45