From fdfbab2f5232a2c6ff3f094832472aca5d1041db Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 9 Aug 2013 02:34:49 -0400 Subject: [PATCH] Only display scroll widget when there is enough item --- layout/vertical.lua | 8 +++++++- widgets/scroll.lua | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/layout/vertical.lua b/layout/vertical.lua index cc5bc1e..bb99e6e 100644 --- a/layout/vertical.lua +++ b/layout/vertical.lua @@ -238,6 +238,12 @@ function module:setup_item(data,item,args) icon:set_image(value) end item._internal.set_map.text(item._private_data.text) + + if data._internal.scroll_w and data.rowcount > data.max_items then + data._internal.scroll_w.visible = true + data._internal.scroll_w["up"]:emit_signal("widget::updated") + data._internal.scroll_w["down"]:emit_signal("widget::updated") + end end local function compute_geo(data) @@ -258,7 +264,7 @@ local function compute_geo(data) end end 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["up"].visible and (2*data.item_height) or 0) + 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) else local h = (visblerow-#data._internal.widgets)*data.item_height for k,v in ipairs(data._internal.widgets) do diff --git a/widgets/scroll.lua b/widgets/scroll.lua index 98fe6cb..c2d6c73 100644 --- a/widgets/scroll.lua +++ b/widgets/scroll.lua @@ -46,14 +46,20 @@ end local function new(data) local scroll_w = {} + scroll_w.visible = false for k,v in ipairs({"up","down"}) do local ib = wibox.widget.imagebox() ib:set_image(module[v]()) ib.fit = function(tb,width,height) + if scroll_w.visible == false then + return 0,0 + end return width,data.item_height end ib.draw = function(self,wibox, cr, width, height) - cr:set_source_surface(self._image, width/2 - self._image:get_width()/2, 0) + if width > 0 and height > 0 then + cr:set_source_surface(self._image, width/2 - self._image:get_width()/2, 0) + end cr:paint() end scroll_w[v] = wibox.widget.background()