From e1447e90b5678b3f03c7ed3ff1a2042ab0cf6e95 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Thu, 11 Feb 2016 23:39:45 -0500 Subject: [PATCH] refactor: Port radical.item.layout.centerred to the declarative syntax --- item/layout/centerred.lua | 63 ++++++++++++++++++++------------------- item/layout/icon.lua | 21 ++++++++----- 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/item/layout/centerred.lua b/item/layout/centerred.lua index 14b93f4..80d2d63 100644 --- a/item/layout/centerred.lua +++ b/item/layout/centerred.lua @@ -1,45 +1,48 @@ local setmetatable = setmetatable -local beautiful = require( "beautiful" ) -local color = require( "gears.color" ) -local cairo = require( "lgi" ).cairo local wibox = require( "wibox" ) -local checkbox = require( "radical.widgets.checkbox" ) -local fkey = require( "radical.widgets.fkey" ) local util = require( "awful.util" ) local horizontal = require( "radical.item.layout.horizontal" ) local margins2 = require("radical.margins") -local module = {} - local function create_item(item,data,args) - -- Background - local bg = wibox.widget.background() - -- Margins - local m = wibox.layout.margin(la) - local mrgns = margins2(m,util.table.join(data.item_style.margins,data.default_item_margins)) - item.get_margins = function() - return mrgns - end + -- Define the item layout + local w = wibox.widget.base.make_widget_declarative { + { + { + nil, + { + id = "main_text" , + align = "center" , + widget = wibox.widget.textbox, + }, + nil, + layout = wibox.layout.align.horizontal, + }, + id = "main_margin", + layout = wibox.layout.margin + }, + widget = wibox.widget.background, + } - local text = wibox.widget.textbox() - text:set_align("center") + item._internal.margin_w = item.widget:get_children_by_id("main_margin")[1] + item._internal.text_w = item.widget:get_children_by_id("main_text" )[1] - -- Layout - local align = wibox.layout.align.horizontal() - align:set_middle( text ) - m:set_widget(align) - bg:set_widget(m) + -- Margins + local mrgns = margins2( + item._internal.margin_w, + util.table.join(data.item_style.margins,data.default_item_margins) + ) - item._internal.text_w = text - item._internal.icon_w = nil - item._internal.margin_w = m + function item:get_margins() + return mrgns + end - -- Setup events - horizontal.setup_event(data,item,bg) + -- Setup events + horizontal.setup_event(data, item, w) - return bg + return w end -return setmetatable(module, { __call = function(_, ...) return create_item(...) end }) --- kate: space-indent on; indent-width 2; replace-tabs on; +return setmetatable({}, { __call = function(_, ...) return create_item(...) end }) +-- kate: space-indent on; indent-width 4; replace-tabs on; diff --git a/item/layout/icon.lua b/item/layout/icon.lua index 6df6cdd..d60f658 100644 --- a/item/layout/icon.lua +++ b/item/layout/icon.lua @@ -32,13 +32,6 @@ end local function create_item(item,data,args) - -- Setup margins - local mrgns = margins2(m,util.table.join(data.item_style.margins,data.default_item_margins)) - - function item:get_margins() - return mrgns - end - if data.fkeys_prefix == true then local pref = wibox.widget.textbox() @@ -121,7 +114,8 @@ local function create_item(item,data,args) }, layout = wibox.layout.align.vertical }, - left = data.fkeys_prefix and 0 or nil, + left = data.fkeys_prefix and 0 or nil, + id = "main_margin", layout = wibox.layout.margin, }, @@ -133,11 +127,22 @@ local function create_item(item,data,args) item.widget = w item._internal.icon_w = icon + item._internal.margin_w = item.widget:get_children_by_id("main_margin")[1] item._internal.text_w = item.widget:get_children_by_id("main_text")[1] item._private_data._fit = wibox.widget.background.fit w.after_draw_children = horizontal.after_draw_children w.fit = bg_fit + -- Setup margins + local mrgns = margins2( + item._internal.margin_w, + util.table.join(data.item_style.margins,data.default_item_margins) + ) + + function item:get_margins() + return mrgns + end + -- Setup events horizontal.setup_event(data,item,w)