NewDropDown creates and returns a pointer to a new drop down widget with the specified width.
(width float32, item *ImageLabel)
| 34 | |
| 35 | // NewDropDown creates and returns a pointer to a new drop down widget with the specified width. |
| 36 | func 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 |
| 89 | func (dd *DropDown) Add(item *ImageLabel) { |
no test coverage detected