MCPcopy
hub / github.com/g3n/engine / NewImageButton

Function NewImageButton

gui/image_button.go:50–82  ·  view source on GitHub ↗

NewImageButton creates and returns a pointer to a new ImageButton widget with the specified image.

(normalImgPath string)

Source from the content-addressed store, hash-verified

48// NewImageButton creates and returns a pointer to a new ImageButton widget
49// with the specified image.
50func 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
85func (b *ImageButton) SetText(text string) {

Callers

nothing calls this directly

Calls 12

NewTexture2DFromImageFunction · 0.92
StyleDefaultFunction · 0.85
NewImageFromTexFunction · 0.85
NewPanelFunction · 0.85
SetContentSizeMethod · 0.80
SetBordersMethod · 0.80
WidthMethod · 0.65
HeightMethod · 0.65
SubscribeMethod · 0.65
AddMethod · 0.45
updateMethod · 0.45
recalcMethod · 0.45

Tested by

no test coverage detected