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

Function NewButton

gui/button.go:49–77  ·  view source on GitHub ↗

NewButton creates and returns a pointer to a new button widget with the specified text for the button label.

(text string)

Source from the content-addressed store, hash-verified

47// NewButton creates and returns a pointer to a new button widget
48// with the specified text for the button label.
49func 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

Callers 2

newWindowTitleFunction · 0.85
buildButtonFunction · 0.85

Calls 7

StyleDefaultFunction · 0.85
NewLabelFunction · 0.85
SubscribeMethod · 0.65
InitializeMethod · 0.45
updateMethod · 0.45
recalcMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected