From 9aab9b0d3c97009ad73602aea9502e168f4e931e Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 4 Jan 2014 18:51:07 -0500 Subject: [PATCH] Add separator widget --- README.md | 14 ++++++++------ base.lua | 1 + widgets/init.lua | 1 + widgets/separator.lua | 30 ++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 widgets/separator.lua diff --git a/README.md b/README.md index 0672b06..5ec732b 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,10 @@ The most simple kind of menus, contexts one, can be created like this: smenu:add_item({text="item 2"}) return smenu end}) + + -- To add the menu to a widget: + local mytextbox = wibox.widget.textbox() + mytextbox:set_menu(m,3) -- 3 = right mouse button, 1 = left mouse button ``` In this example, a simple 3 item menu is created with a dynamically generated @@ -47,6 +51,9 @@ submenu. Please note that generating submenus using function will generate it every time it is being shown. For static menus, it is faster to simply create them once and passing the submenu object to the "sub_menu" item property. +`:set_menu` can also take a lazy-loading function instead of a +menu. The second parameter is not mandatory, the default is `1`. + ### Menu types The current valid types are: @@ -95,14 +102,8 @@ On top of each styles, menu can also have different layouts to display items: item_style = radical.item_style.classic , layout = radical.layout.vertical }) - -- To add the menu to a widget: - local mytextbox = wibox.widget.textbox() - mytextbox:set_menu(m,3) -- 3 = right mouse button, 1 = left mouse button - ``` -Please note that `:set_menu` can also take a lazy-loading function instead of a -menu. The second parameter is not mandatory, the default is "1". ### Tooltip @@ -205,3 +206,4 @@ Radical also use the some of the same theme options as awful.menu, plus some: * menu_bg_normal * menu_bg_highlight * menu_submenu_icon + * menu_separator_color diff --git a/base.lua b/base.lua index 403ef14..835f852 100644 --- a/base.lua +++ b/base.lua @@ -258,6 +258,7 @@ local function new(args) bg_header = args.bg_header or beautiful.menu_bg_header or beautiful.fg_normal, border_color = args.border_color or beautiful.menu_border_color or beautiful.border_color or "#333333", border_width = args.border_width or beautiful.menu_border_width or beautiful.border_width or 3, + separator_color = args.separator_color or beautiful.menu_separator_color or args.border_color or beautiful.menu_border_color or beautiful.border_color or "#333333", item_height = args.item_height or beautiful.menu_height or 30, item_width = args.item_width or nil, width = args.width or beautiful.menu_width or 130, diff --git a/widgets/init.lua b/widgets/init.lua index 6e666ac..6bba708 100644 --- a/widgets/init.lua +++ b/widgets/init.lua @@ -6,4 +6,5 @@ return { table = require( "radical.widgets.table" ), header = require( "radical.widgets.header" ), piechart = require( "radical.widgets.piechart" ), + separator= require( "radical.widgets.separator"), } \ No newline at end of file diff --git a/widgets/separator.lua b/widgets/separator.lua new file mode 100644 index 0000000..381dba0 --- /dev/null +++ b/widgets/separator.lua @@ -0,0 +1,30 @@ +local setmetatable = setmetatable +local print = print +local color = require( "gears.color") +local cairo = require( "lgi" ).cairo +local wibox = require( "wibox" ) +local beautiful = require( "beautiful" ) + +local function draw(self, w, cr, width, height) + cr:save() + cr:set_source(self._color) + cr:rectangle(5,2,width-10,1) + cr:fill() + cr:restore() +end + +local function fit(box, w, h) + return w,5 +end + +local function new(menu) + local bg = wibox.widget.base.make_widget() + bg.fit = fit + bg._color = color( menu and menu.separator_color or beautiful.border_color or beautiful.fg_normal) + bg.draw = draw + bg._force_fit = true + return bg +end + +return setmetatable({}, { __call = function(_, ...) return new(...) end }) +-- kate: space-indent on; indent-width 2; replace-tabs on;