@@ -17,32 +17,75 @@ func (c *Context) Button(text string) EventHandler {
1717 pc := caller ()
1818 id := c .idFromCaller (pc )
1919 return c .wrapEventHandlerAndError (func () (EventHandler , error ) {
20- return c .button (text , iconNone , optionAlignCenter , id )
20+ return c .button (text , optionAlignCenter , id )
2121 })
2222}
2323
24- func (c * Context ) iconButton (icon icon ) EventHandler {
24+ func (c * Context ) button (text string , opt option , id widgetID ) (EventHandler , error ) {
25+ return c .widget (id , opt , nil , func (bounds image.Rectangle , wasFocused bool ) EventHandler {
26+ var e EventHandler
27+ if c .pointing .justPressed () && c .focus == id {
28+ e = & eventHandler {}
29+ }
30+ return e
31+ }, func (bounds image.Rectangle ) {
32+ c .drawWidgetFrame (id , bounds , colorButton , opt )
33+ if len (text ) > 0 {
34+ c .drawWidgetText (text , bounds , colorText , opt )
35+ }
36+ })
37+ }
38+
39+ func (c * Context ) spinButtons () (up , down EventHandler ) {
2540 pc := caller ()
2641 id := c .idFromCaller (pc )
27- return c .wrapEventHandlerAndError (func () (EventHandler , error ) {
28- return c .button ("" , icon , optionAlignCenter , id )
42+ c .idScopeFromID (id , func () {
43+ upID := c .idFromString ("up" )
44+ downID := c .idFromString ("down" )
45+ c .GridCell (func (bounds image.Rectangle ) {
46+ c .setGridLayout (nil , []int {- 1 , - 1 })
47+ up = c .wrapEventHandlerAndError (func () (EventHandler , error ) {
48+ var e EventHandler
49+ var err error
50+ e , err = c .spinButton (true , optionAlignCenter , upID , downID )
51+ if err != nil {
52+ return nil , err
53+ }
54+ return e , nil
55+ })
56+ down = c .wrapEventHandlerAndError (func () (EventHandler , error ) {
57+ var e EventHandler
58+ var err error
59+ c .idScopeFromID (id , func () {
60+ e , err = c .spinButton (false , optionAlignCenter , upID , downID )
61+ })
62+ if err != nil {
63+ return nil , err
64+ }
65+ return e , nil
66+ })
67+ })
2968 })
69+ return up , down
3070}
3171
32- func (c * Context ) button (text string , icon icon , opt option , id widgetID ) (EventHandler , error ) {
72+ func (c * Context ) spinButton (up bool , opt option , upID , downID widgetID ) (EventHandler , error ) {
73+ id := downID
74+ if up {
75+ id = upID
76+ }
3377 return c .widget (id , opt , nil , func (bounds image.Rectangle , wasFocused bool ) EventHandler {
3478 var e EventHandler
35- if c .pointing .justPressed () && c .focus == id {
79+ if c .pointing .repeated () && ( c .focus == upID || c . focus == downID ) && c . pointing . position (). In ( bounds ) {
3680 e = & eventHandler {}
3781 }
3882 return e
3983 }, func (bounds image.Rectangle ) {
4084 c .drawWidgetFrame (id , bounds , colorButton , opt )
41- if len (text ) > 0 {
42- c .drawWidgetText (text , bounds , colorText , opt )
43- }
44- if icon != iconNone {
45- c .drawIcon (icon , bounds , c .style ().colors [colorText ])
85+ icon := iconDown
86+ if up {
87+ icon = iconUp
4688 }
89+ c .drawIcon (icon , bounds , c .style ().colors [colorText ])
4790 })
4891}
0 commit comments