@@ -194,4 +194,72 @@ uie.add("warning", {
194194 end
195195})
196196
197+ -- Dropdown with sub-options optionally coming out of the options
198+ uie .add (" dropdownWithSubmenu" , {
199+ base = " dropdown" ,
200+
201+ getItemCached = function (self , entry , i )
202+ local cache = self ._itemsCache
203+ local item = cache [i ]
204+ if not item then
205+ local dropdown = self
206+
207+ if entry .submenu then
208+ local itemContainer = {}
209+
210+ local submenuEntries = uiu .map (entry .submenu , function (subentry )
211+ return {subentry .text , function (self )
212+ -- call the event listener
213+ dropdown :cb (subentry .data )
214+
215+ -- change the selected values
216+ dropdown .selected = itemContainer .item
217+ self .parent .selected = self
218+ dropdown .selectedSubIndex = uie .list .getSelectedIndex (self .parent )
219+ dropdown .text = subentry .dropdownText or self .text
220+
221+ -- close everything
222+ dropdown .submenu :removeSelf ()
223+ end }
224+ end )
225+
226+ item = uie .menuItem (entry .text , submenuEntries ):with ({
227+ owner = dropdown
228+ }):hook ({
229+ onClick = function (orig , self , x , y , button )
230+ orig (self , x , y , button )
231+ self .parent .submenu .isList = true
232+ self .parent .submenu .enabled = true
233+ if dropdown .selected == itemContainer .item then
234+ self .parent .submenu .selected = self .parent .submenu .children [dropdown .selectedSubIndex ]
235+ end
236+ end
237+ })
238+
239+ itemContainer [" item" ] = item
240+ else
241+ item = uie .menuItem (entry .text , function (self )
242+ -- call the event listener
243+ dropdown :cb (entry .data )
244+
245+ -- change the selected values
246+ dropdown .text = self .text
247+ dropdown .selected = self
248+
249+ -- close everything
250+ dropdown .submenu :removeSelf ()
251+ end ):with ({
252+ owner = dropdown
253+ })
254+ end
255+
256+ cache [i ] = item
257+ end
258+
259+ item :reflow ()
260+ return item
261+ end
262+ })
263+
264+
197265return uie
0 commit comments