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

Function NewDropDown

gui/dropdown.go:36–86  ·  view source on GitHub ↗

NewDropDown creates and returns a pointer to a new drop down widget with the specified width.

(width float32, item *ImageLabel)

Source from the content-addressed store, hash-verified

34
35// NewDropDown creates and returns a pointer to a new drop down widget with the specified width.
36func NewDropDown(width float32, item *ImageLabel) *DropDown {
37
38 dd := new(DropDown)
39 dd.styles = &StyleDefault().DropDown
40 dd.litem = item
41
42 dd.Panel.Initialize(dd, width, 0)
43 dd.Panel.Subscribe(OnMouseDown, dd.onMouse)
44 dd.Panel.Subscribe(OnCursorEnter, dd.onCursor)
45 dd.Panel.Subscribe(OnCursorLeave, dd.onCursor)
46 dd.Panel.Subscribe(OnResize, func(name string, ev interface{}) { dd.recalc() })
47
48 // ListItem
49 dd.Panel.Add(dd.litem)
50
51 // Create icon
52 dd.icon = NewIcon(" ")
53 dd.icon.SetFontSize(StyleDefault().Label.PointSize * 1.3)
54 dd.icon.SetText(string(icon.ArrowDropDown))
55 dd.Panel.Add(dd.icon)
56
57 /// Create list
58 dd.list = NewVList(0, 0)
59 dd.list.bounded = false
60 dd.list.zLayerDelta = 1
61 dd.list.dropdown = true
62 dd.list.SetVisible(false)
63
64 dd.Panel.Subscribe(OnKeyDown, dd.list.onKeyEvent)
65 dd.Subscribe(OnMouseDownOut, func(s string, i interface{}) {
66 // Hide list when clicked out
67 if dd.list.Visible() {
68 dd.list.SetVisible(false)
69 }
70 })
71
72 dd.list.Subscribe(OnCursorEnter, func(evname string, ev interface{}) {
73 dd.Dispatch(OnCursorLeave, ev)
74 })
75 dd.list.Subscribe(OnCursorLeave, func(evname string, ev interface{}) {
76 dd.Dispatch(OnCursorEnter, ev)
77 })
78
79 dd.list.Subscribe(OnChange, dd.onListChangeEvent)
80 dd.Panel.Add(dd.list)
81
82 dd.update()
83 // This will trigger recalc()
84 dd.Panel.SetContentHeight(item.Height())
85 return dd
86}
87
88// Add adds a list item at the end of the list
89func (dd *DropDown) Add(item *ImageLabel) {

Callers 1

buildDropDownFunction · 0.85

Calls 15

StyleDefaultFunction · 0.85
NewIconFunction · 0.85
NewVListFunction · 0.85
SetContentHeightMethod · 0.80
SubscribeMethod · 0.65
SetVisibleMethod · 0.65
VisibleMethod · 0.65
DispatchMethod · 0.65
HeightMethod · 0.65
InitializeMethod · 0.45
recalcMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected