Properly handle menu prefix and suffix widgets
This was previously hardcoded 100 commits!
This commit is contained in:
parent
5255cca803
commit
ad20d9e2be
30
README.md
30
README.md
|
@ -221,20 +221,22 @@ Multiple items can have multiple sets of options.
|
|||
All menus provide a bunch of methods. Most of them have been coverred above, but
|
||||
here is the list:
|
||||
|
||||
| Name | Description | Arguments | Return |
|
||||
| ---------------- | -------------------------------------------- | --------------------- | ------ |
|
||||
| add_item | Add new item to a menu | array of options | item |
|
||||
| add_widget | Add a new widget instead of an item | a widget, args | --- |
|
||||
| add_embeded_menu | Add an inline menu to another menu | an "embed" menu | --- |
|
||||
| add_key_binding | Add a global key binding to a menu | mod array, key | --- |
|
||||
| add_key_hook | Add a callback when a key is pressed | mod, key, event, func | --- |
|
||||
| clear | Remove all items | --- | --- |
|
||||
| scroll_down | If the menu is cropped, scroll down | --- | --- |
|
||||
| scroll_up | If the menu is cropped, scroll up | --- | --- |
|
||||
| swap | Swap 2 items | both items | --- |
|
||||
| move | Move an item | the item, the new idx | --- |
|
||||
| remove | Remove the item | the item | --- |
|
||||
| append | Append an existing (but unused) item | the item | --- |
|
||||
| Name | Description | Arguments | Return |
|
||||
| ----------------- | -------------------------------------------- | --------------------- | ------ |
|
||||
| add_item | Add new item to a menu | array of options | item |
|
||||
| add_widget | Add a new widget instead of an item | a widget, args | --- |
|
||||
| add_embeded_menu | Add an inline menu to another menu | an "embed" menu | --- |
|
||||
| add_key_binding | Add a global key binding to a menu | mod array, key | --- |
|
||||
| add_key_hook | Add a callback when a key is pressed | mod, key, event, func | --- |
|
||||
| clear | Remove all items | --- | --- |
|
||||
| scroll_down | If the menu is cropped, scroll down | --- | --- |
|
||||
| scroll_up | If the menu is cropped, scroll up | --- | --- |
|
||||
| swap | Swap 2 items | both items | --- |
|
||||
| move | Move an item | the item, the new idx | --- |
|
||||
| remove | Remove the item | the item | --- |
|
||||
| append | Append an existing (but unused) item | the item | --- |
|
||||
| add_prefix_widget | Add a widget at the beginning of the menu | the widget | --- |
|
||||
| add_suffix_widget | Add a widget at the end of the menu | the widget | --- |
|
||||
|
||||
|
||||
###Signals
|
||||
|
|
2
bar.lua
2
bar.lua
|
@ -143,7 +143,7 @@ local function new(args)
|
|||
ret:connect_signal("_hidden::changed",function(_,item)
|
||||
item.widget:emit_signal("widget::updated")
|
||||
end)
|
||||
return ret
|
||||
return ret,ret._internal.layout
|
||||
end
|
||||
|
||||
function module.flex(args)
|
||||
|
|
9
base.lua
9
base.lua
|
@ -207,6 +207,14 @@ local function add_widget(data,widget,args)
|
|||
end
|
||||
end
|
||||
|
||||
local function add_prefix_widget(data,widget,args)
|
||||
data:emit_signal("prefix_widget::added",widget,args)
|
||||
end
|
||||
|
||||
local function add_suffix_widget(data,widget,args)
|
||||
data:emit_signal("suffix_widget::added",widget,args)
|
||||
end
|
||||
|
||||
local function add_embeded_menu(data,menu)
|
||||
add_widget(data,menu._internal.layout)
|
||||
menu._embeded_parent = data
|
||||
|
@ -293,6 +301,7 @@ local function new(args)
|
|||
})
|
||||
internal.private_data = private_data
|
||||
data.add_item,data.add_widget,data.add_embeded_menu,data._internal,data.add_key_binding = add_item,add_widget,add_embeded_menu,internal,add_key_binding
|
||||
data.add_prefix_widget,data.add_suffix_widget=add_prefix_widget,add_suffix_widget
|
||||
theme.setup_colors(data,args)
|
||||
|
||||
-- Getters
|
||||
|
|
|
@ -25,8 +25,8 @@ local module = {
|
|||
DISABLED = 1 , -- Cannot be interacted with
|
||||
URGENT = 2 , -- Need attention
|
||||
SELECTED = 3 , -- Single item selected [[FOCUS]]
|
||||
PRESSED = 4 , -- Mouse pressed
|
||||
HOVERED = 5 , -- Mouse hover
|
||||
PRESSED = 4 , -- Mouse pressed
|
||||
USED = 6 , -- Common flag
|
||||
CHECKED = 7 , -- When checkbox isn't enough
|
||||
ALTERNATE = 8 ,
|
||||
|
|
|
@ -199,8 +199,10 @@ local function compute_geo(data)
|
|||
visblerow = vis
|
||||
end
|
||||
end
|
||||
local sw,sh = data._internal.suf_l:fit(9999,9999)
|
||||
local pw,ph = data._internal.pref_l:fit(9999,9999)
|
||||
if not data._internal.has_widget then
|
||||
return w,(total and total > 0 and total or visblerow*data.item_height) + (data._internal.filter_tb and data.item_height or 0) + (data.max_items and data._internal.scroll_w.visible and (2*data.item_height) or 0)
|
||||
return w,(total and total > 0 and total or visblerow*data.item_height) + ph + sh
|
||||
else
|
||||
local h = (visblerow-#data._internal.widgets)*data.item_height
|
||||
for k,v in ipairs(data._internal.widgets) do
|
||||
|
@ -217,21 +219,24 @@ local function new(data)
|
|||
end
|
||||
local l,real_l = wibox.layout.fixed.vertical(),nil
|
||||
real_l = wibox.layout.fixed.vertical()
|
||||
local pref_l,suf_l = wibox.layout.fixed.vertical(),wibox.layout.fixed.vertical()
|
||||
real_l:add(pref_l)
|
||||
if data.max_items then
|
||||
data._internal.scroll_w = scroll(data)
|
||||
real_l:add(data._internal.scroll_w["up"])
|
||||
pref_l:add(data._internal.scroll_w["up"])
|
||||
end
|
||||
real_l:add(l)
|
||||
real_l:add(suf_l)
|
||||
if data.show_filter then
|
||||
if data.max_items then
|
||||
real_l:add(data._internal.scroll_w["down"])
|
||||
suf_l:add(data._internal.scroll_w["down"])
|
||||
end
|
||||
local filter_tb = filter(data)
|
||||
real_l:add(filter_tb)
|
||||
suf_l:add(filter_tb)
|
||||
data._internal.filter_tb = filter_tb.widget
|
||||
else
|
||||
if data.max_items then
|
||||
real_l:add(data._internal.scroll_w["down"])
|
||||
suf_l:add(data._internal.scroll_w["down"])
|
||||
end
|
||||
end
|
||||
real_l.fit = function(a1,a2,a3)
|
||||
|
@ -247,24 +252,33 @@ local function new(data)
|
|||
real_l.setup_key_hooks = module.setup_key_hooks
|
||||
real_l.setup_item = module.setup_item
|
||||
data._internal.content_layout = l
|
||||
data._internal.suf_l,data._internal.pref_l=suf_l,pref_l
|
||||
|
||||
--SWAP / MOVE / REMOVE
|
||||
data:connect_signal("item::swapped",function(_,item1,item2,index1,index2)
|
||||
real_l.widgets[index1],real_l.widgets[index2] = real_l.widgets[index2],real_l.widgets[index1]
|
||||
real_l:emit_signal("widget::updated")
|
||||
l.widgets[index1],l.widgets[index2] = l.widgets[index2],l.widgets[index1]
|
||||
l:emit_signal("widget::updated")
|
||||
end)
|
||||
data:connect_signal("item::moved",function(_,item,new_idx,old_idx)
|
||||
table.insert(real_l.widgets,new_idx,table.remove(real_l.widgets,old_idx))
|
||||
real_l:emit_signal("widget::updated")
|
||||
table.insert(l.widgets,new_idx,table.remove(l.widgets,old_idx))
|
||||
l:emit_signal("widget::updated")
|
||||
end)
|
||||
data:connect_signal("item::removed",function(_,item,old_idx)
|
||||
table.remove(real_l.widgets,old_idx)
|
||||
real_l:emit_signal("widget::updated")
|
||||
table.remove(l.widgets,old_idx)
|
||||
l:emit_signal("widget::updated")
|
||||
end)
|
||||
data:connect_signal("item::appended",function(_,item)
|
||||
real_l.widgets[#real_l.widgets+1] = item.widget
|
||||
l.widgets[#l.widgets+1] = item.widget
|
||||
l:emit_signal("widget::updated")
|
||||
end)
|
||||
data:connect_signal("prefix_widget::added",function(_,widget,args)
|
||||
table.insert(pref_l.widgets,1,widget)
|
||||
pref_l:emit_signal("widget::updated")
|
||||
real_l:emit_signal("widget::updated")
|
||||
end)
|
||||
data:connect_signal("suffix_widget::added",function(_,widget,args)
|
||||
suf_l:add(widget)
|
||||
end)
|
||||
data._internal.text_fit = function(self,width,height) return width,height end
|
||||
return real_l
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue