Add new 'flexbar' menu type (bar with a flex layout)

This commit is contained in:
Emmanuel Lepage Vallee 2014-02-06 23:47:24 -05:00
parent c0c57eff16
commit 220dd27a02
8 changed files with 44 additions and 17 deletions

View File

@ -31,15 +31,15 @@ themselves programatically.
The most simple kind of menus, contexts one, can be created like this:
```lua
local menu = radical.context({})
menu:add_item({text="Screen 1",button1=function() print("Hello World! ") end})
menu:add_item({text="Screen 9",icon=beautiful.path.."Icon/layouts/tileleft.png"})
menu:add_item({text="Sub Menu",sub_menu = function()
local smenu = radical.context({})
smenu:add_item({text="item 1"})
smenu:add_item({text="item 2"})
local menu = radical.context{}
menu:add_item {text="Screen 1",button1=function() print("Hello World! ") end}
menu:add_item {text="Screen 9",icon=beautiful.path.."Icon/layouts/tileleft.png"}
menu:add_item {text="Sub Menu",sub_menu = function()
local smenu = radical.context{}
smenu:add_item{text="item 1"}
smenu:add_item{text="item 2"}
return smenu
end})
end}
-- To add the menu to a widget:
local mytextbox = wibox.widget.textbox()
@ -112,10 +112,10 @@ Item layouts are how widgets (icons, label, prefix) are disposed in the item
```lua
local radical = require("radical")
local m = radical.context({
local m = radical.context {
style = radical.style.classic ,
item_style = radical.item_style.classic ,
layout = radical.layout.vertical })
layout = radical.layout.vertical }
```
@ -228,10 +228,11 @@ here is the list:
| 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 | --- |
Menu also emit many signals, the syntax is usually `PROPERTY_NAME::changed`. The
exeptions are `item::moved`, `item::swapped`, `item::removed`
exeptions are `item::moved`, `item::swapped`, `item::removed`, `item::appended`
###Beautiful options

15
bar.lua
View File

@ -42,7 +42,7 @@ local function setup_drawable(data)
internal.margin._data = data
internal.margin.draw = bg_draw
internal.layout = wibox.layout.fixed.horizontal()
internal.layout = internal.layout_func or wibox.layout.fixed.horizontal()
internal.margin:set_widget(internal.layout)
--Getters
@ -71,6 +71,10 @@ local function setup_drawable(data)
table.remove(internal.layout.widgets,old_idx)
internal.layout:emit_signal("widget::updated")
end)
data:connect_signal("item::appended",function(_,item)
internal.layout.widgets[#internal.layout.widgets+1] = item.widget
internal.layout:emit_signal("widget::updated")
end)
end
local function setup_buttons(data,item,args)
@ -134,5 +138,14 @@ local function new(args)
return ret
end
function module.flex(args)
local args = args or {}
args.internal = args.internal or {}
args.internal.layout_func = wibox.layout.flex.horizontal()
local data = new(args)
data._internal.text_fit = function(self,width,height) return width,height end
return data
end
return setmetatable(module, { __call = function(_, ...) return new(...) end })
-- kate: space-indent on; indent-width 2; replace-tabs on;

View File

@ -512,6 +512,11 @@ local function new(args)
end
end
function data:append(item)
internal.items[#internal.items + 1] = item
data:emit_signal("item::appended",item)
end
function data:scroll_up()
if data.max_items ~= nil and data.rowcount >= data.max_items and (data._start_at or 1) > 1 then
data._start_at = (data._start_at or 1) - 1

View File

@ -42,6 +42,8 @@ base.make_widget = function(...)
return ret
end
local bar = require( "radical.bar" )
return {
layout = require( "radical.layout" ),
object = require( "radical.object" ),
@ -50,11 +52,12 @@ return {
context = require( "radical.context" ),
embed = require( "radical.embed" ),
box = require( "radical.box" ),
bar = require( "radical.bar" ),
style = require( "radical.style" ),
item_style = require( "radical.item_style" ),
widgets = require( "radical.widgets" ),
item_layout = require( "radical.item_layout"),
bar = bar,
flexbar = bar.flex,
tooltip = tooltip
}
-- kate: space-indent on; indent-width 2; replace-tabs on;

0
item/init.lua Normal file
View File

View File

@ -138,7 +138,7 @@ local function create_item(item,data,args)
-- Text
local tb = wibox.widget.textbox()
tb.fit = textbox_fit
tb.fit = data._internal.text_fit or textbox_fit
tb.draw = function(self,w, cr, width, height)
if item.underlay then
module.paint_underlay(data,item,cr,width,height)
@ -172,7 +172,7 @@ local function create_item(item,data,args)
m:set_widget ( align )
align._item = item
align._data = data
align.fit = align_fit
align.fit = data._internal.align_fit or align_fit
item._internal.align = align
-- Set widget

View File

@ -10,8 +10,8 @@ local module = {
margins = {
TOP = 0,
BOTTOM = 0,
RIGHT = 50,
LEFT = 50
RIGHT = 15,
LEFT = 15
}
}

View File

@ -254,6 +254,11 @@ local function new(data)
table.remove(real_l.widgets,old_idx)
real_l:emit_signal("widget::updated")
end)
data:connect_signal("item::appended",function(_,item)
real_l.widgets[#real_l.widgets+1] = item.widget
real_l:emit_signal("widget::updated")
end)
data._internal.text_fit = function(self,width,height) return width,height end
return real_l
end