NewButton creates and returns a pointer to a new button widget with the specified text for the button label.
(text string)
| 47 | // NewButton creates and returns a pointer to a new button widget |
| 48 | // with the specified text for the button label. |
| 49 | func NewButton(text string) *Button { |
| 50 | |
| 51 | b := new(Button) |
| 52 | b.styles = &StyleDefault().Button |
| 53 | |
| 54 | // Initializes the button panel |
| 55 | b.Panel.Initialize(b, 0, 0) |
| 56 | |
| 57 | // Subscribe to panel events |
| 58 | b.Subscribe(OnKeyDown, b.onKey) |
| 59 | b.Subscribe(OnKeyUp, b.onKey) |
| 60 | b.Subscribe(OnMouseUp, b.onMouse) |
| 61 | b.Subscribe(OnMouseDown, b.onMouse) |
| 62 | b.Subscribe(OnMouseUpOut, b.onMouse) |
| 63 | b.Subscribe(OnCursor, b.onCursor) |
| 64 | b.Subscribe(OnCursorEnter, b.onCursor) |
| 65 | b.Subscribe(OnCursorLeave, b.onCursor) |
| 66 | b.Subscribe(OnEnable, func(name string, ev interface{}) { b.update() }) |
| 67 | b.Subscribe(OnResize, func(name string, ev interface{}) { b.recalc() }) |
| 68 | |
| 69 | // Creates label |
| 70 | b.Label = NewLabel(text) |
| 71 | b.Label.Subscribe(OnResize, func(name string, ev interface{}) { b.recalc() }) |
| 72 | b.Panel.Add(b.Label) |
| 73 | |
| 74 | b.recalc() // recalc first then update! |
| 75 | b.update() |
| 76 | return b |
| 77 | } |
| 78 | |
| 79 | // SetIcon sets the button icon from the default Icon font. |
| 80 | // If there is currently a selected image, it is removed |
no test coverage detected