2013-05-11 21:02:42 +02:00
|
|
|
local setmetatable = setmetatable
|
2016-03-05 09:23:59 +01:00
|
|
|
local scroll = require( "radical.widgets.scroll" )
|
|
|
|
local filter = require( "radical.widgets.filter" )
|
|
|
|
local wibox = require( "wibox" )
|
|
|
|
local common = require( "radical.common" )
|
2013-05-11 21:02:42 +02:00
|
|
|
|
|
|
|
local module = {}
|
|
|
|
|
|
|
|
--Get preferred item geometry
|
2016-01-09 10:25:46 +01:00
|
|
|
local function item_fit(data,item,self,context, width,height)
|
2016-03-05 09:23:59 +01:00
|
|
|
local w, h = item._private_data._fit(self,context,width,height)
|
|
|
|
return w, item.height or h --TODO use a constraint widget
|
2014-01-05 07:04:40 +01:00
|
|
|
end
|
2013-07-04 19:19:01 +02:00
|
|
|
|
2016-02-21 08:34:05 +01:00
|
|
|
function module:setup_item(data,item,args)
|
2016-06-24 06:46:41 +02:00
|
|
|
item._private_data._fit = wibox.container.background.fit
|
2016-03-05 08:14:24 +01:00
|
|
|
|
|
|
|
if not item._internal.margin_w then return end
|
|
|
|
|
|
|
|
item._internal.margin_w.fit = function(...) return item_fit(data,item,...) end
|
2014-02-05 05:29:38 +01:00
|
|
|
|
2016-02-21 08:34:05 +01:00
|
|
|
-- Compute the minimum width
|
2016-06-24 06:46:41 +02:00
|
|
|
if data.auto_resize then --FIXME this wont work if the text change
|
2016-03-05 09:23:59 +01:00
|
|
|
local fit_w = item._internal.margin_w:get_preferred_size()
|
|
|
|
|
2016-02-21 08:34:05 +01:00
|
|
|
if fit_w < 1000 and (not data._internal.largest_item_w_v or data._internal.largest_item_w_v < fit_w) then
|
|
|
|
data._internal.largest_item_w = item
|
|
|
|
data._internal.largest_item_w_v = fit_w
|
|
|
|
end
|
2014-03-24 05:00:01 +01:00
|
|
|
end
|
|
|
|
|
2013-05-27 02:49:51 +02:00
|
|
|
end
|
|
|
|
|
2014-10-06 00:01:54 +02:00
|
|
|
local function compute_geo(data,width,height,force_values)
|
2016-02-21 08:34:05 +01:00
|
|
|
local w = data.default_width
|
|
|
|
if data.auto_resize and data._internal.largest_item_w then
|
|
|
|
w = data._internal.largest_item_w_v > data.default_width and data._internal.largest_item_w_v or data.default_width
|
|
|
|
end
|
2015-12-29 12:21:13 +01:00
|
|
|
|
2016-02-21 08:34:05 +01:00
|
|
|
local visblerow = data.visible_row_count
|
2015-12-29 12:21:13 +01:00
|
|
|
|
2016-02-21 08:34:05 +01:00
|
|
|
local sw,sh = data._internal.suf_l:get_preferred_size()
|
|
|
|
local pw,ph = data._internal.pref_l:get_preferred_size()
|
|
|
|
if not data._internal.has_widget then
|
2016-06-24 06:46:41 +02:00
|
|
|
return w, visblerow*data.item_height + ph + sh
|
2016-02-21 08:34:05 +01:00
|
|
|
else
|
|
|
|
local sumh = data.widget_fit_height_sum
|
|
|
|
local h = (visblerow-#data._internal.widgets)*data.item_height + sumh
|
|
|
|
return w,h
|
|
|
|
end
|
2013-07-04 07:20:46 +02:00
|
|
|
end
|
|
|
|
|
2013-05-11 21:02:42 +02:00
|
|
|
local function new(data)
|
2016-02-11 08:51:14 +01:00
|
|
|
|
|
|
|
local function real_fit(self,context,o_w,o_h,force_values)
|
2016-03-05 10:52:35 +01:00
|
|
|
return compute_geo(data,o_w,o_h,force_values)
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
2016-02-11 08:51:14 +01:00
|
|
|
|
|
|
|
-- Create the scroll widgets
|
2013-07-07 06:39:17 +02:00
|
|
|
if data.max_items then
|
2016-02-11 08:51:14 +01:00
|
|
|
data._internal.scroll_w = scroll(data)
|
2013-07-07 06:39:17 +02:00
|
|
|
end
|
2016-02-11 08:51:14 +01:00
|
|
|
|
2016-02-11 10:21:10 +01:00
|
|
|
-- Define the item layout
|
|
|
|
local real_l = wibox.widget.base.make_widget_declarative {
|
2016-02-11 08:51:14 +01:00
|
|
|
-- Widgets
|
|
|
|
{
|
|
|
|
-- The prefix section, used for the scroll widgets and custom prefixes
|
|
|
|
|
|
|
|
-- Widgets
|
|
|
|
data._internal.scroll_w and data._internal.scroll_w["up"] or nil,
|
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
id = "prefix_layout",
|
|
|
|
layout = wibox.layout.fixed.vertical
|
|
|
|
},
|
|
|
|
{
|
|
|
|
-- The main layout (where items are added)
|
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
id = "content_layout",
|
|
|
|
spacing = data.spacing and data.spacing or 0,
|
|
|
|
layout = wibox.layout.fixed.vertical ,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
-- The suffix section, used for the scroll widgets and custom suffixes
|
|
|
|
|
|
|
|
-- Widgets
|
|
|
|
data._internal.scroll_w and data._internal.scroll_w["down"] or nil,
|
|
|
|
data.show_filter and {
|
|
|
|
id = "filter_widget",
|
2016-03-05 08:54:17 +01:00
|
|
|
data = data,
|
|
|
|
widget = filter
|
2016-02-11 08:51:14 +01:00
|
|
|
} or nil,
|
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
id = "suffix_layout" ,
|
|
|
|
layout = wibox.layout.fixed.vertical,
|
|
|
|
},
|
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
layout = wibox.layout.fixed.vertical,
|
|
|
|
|
|
|
|
-- Methods
|
|
|
|
item_fit = item_fit ,
|
2016-02-21 08:34:05 +01:00
|
|
|
setup_key_hooks = common.setup_key_hooks,
|
2016-02-11 08:51:14 +01:00
|
|
|
setup_item = module.setup_item ,
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Set the important widgets
|
|
|
|
data._internal.content_layout = real_l:get_children_by_id( "content_layout" )[1]
|
|
|
|
data._internal.suf_l = real_l:get_children_by_id( "suffix_layout" )[1]
|
|
|
|
data._internal.pref_l = real_l:get_children_by_id( "prefix_layout" )[1]
|
|
|
|
|
|
|
|
-- Set the overloaded methods
|
2016-02-11 10:21:10 +01:00
|
|
|
real_l.fit = real_fit
|
2016-02-11 08:51:14 +01:00
|
|
|
|
2016-02-11 10:21:10 +01:00
|
|
|
return real_l
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
2016-02-11 08:51:14 +01:00
|
|
|
-- kate: space-indent on; indent-width 4; replace-tabs on;
|