NewImageButton creates and returns a pointer to a new ImageButton widget with the specified image.
(normalImgPath string)
| 48 | // NewImageButton creates and returns a pointer to a new ImageButton widget |
| 49 | // with the specified image. |
| 50 | func NewImageButton(normalImgPath string) (*ImageButton, error) { |
| 51 | |
| 52 | b := new(ImageButton) |
| 53 | b.styles = &StyleDefault().ImageButton |
| 54 | |
| 55 | tex, err := texture.NewTexture2DFromImage(normalImgPath) |
| 56 | if err != nil { |
| 57 | return nil, err |
| 58 | } |
| 59 | b.stateImages[ButtonNormal] = tex |
| 60 | b.image = NewImageFromTex(tex) |
| 61 | |
| 62 | // Initializes the button panel |
| 63 | b.Panel = NewPanel(0, 0) |
| 64 | b.Panel.SetContentSize(b.image.Width(), b.image.Height()) |
| 65 | b.Panel.SetBorders(5, 5, 5, 5) |
| 66 | b.Panel.Add(b.image) |
| 67 | |
| 68 | // Subscribe to panel events |
| 69 | b.Panel.Subscribe(OnKeyDown, b.onKey) |
| 70 | b.Panel.Subscribe(OnKeyUp, b.onKey) |
| 71 | b.Panel.Subscribe(OnMouseUp, b.onMouse) |
| 72 | b.Panel.Subscribe(OnMouseDown, b.onMouse) |
| 73 | b.Panel.Subscribe(OnCursor, b.onCursor) |
| 74 | b.Panel.Subscribe(OnCursorEnter, b.onCursor) |
| 75 | b.Panel.Subscribe(OnCursorLeave, b.onCursor) |
| 76 | b.Panel.Subscribe(OnEnable, func(name string, ev interface{}) { b.update() }) |
| 77 | b.Panel.Subscribe(OnResize, func(name string, ev interface{}) { b.recalc() }) |
| 78 | |
| 79 | b.recalc() |
| 80 | b.update() |
| 81 | return b, nil |
| 82 | } |
| 83 | |
| 84 | // SetText sets the text of the label |
| 85 | func (b *ImageButton) SetText(text string) { |
nothing calls this directly
no test coverage detected