Change the way position is computed

The old way was a hack arounf an Awesome 3.5.0 limitation.
The newer should be more reliable.

Please report any regressions.
This commit is contained in:
Emmanuel Lepage Vallee 2014-03-22 00:11:03 -04:00
parent d8e220a7bb
commit 059572956e
6 changed files with 25 additions and 25 deletions

View File

@ -507,7 +507,7 @@ local function new(args)
if data.max_items ~= nil and data.rowcount >= data.max_items and (data._start_at or 1) > 1 then
local current_item = data._current_item
if current_item then
current_item.selected = false
current_item:set_selected(false,true)
end
data._start_at = (data._start_at or 1) - 1
internal.items[data._start_at][1]._hidden = false
@ -522,7 +522,7 @@ local function new(args)
if data.max_items ~= nil and data.rowcount >= data.max_items and (data._start_at or 1)+data.max_items <= data.rowcount then
local current_item = data._current_item
if current_item then
current_item.selected = false
current_item:set_selected(false,true)
end
data._start_at = (data._start_at or 1) + 1
internal.items[data._start_at-1][1]._hidden = true

View File

@ -45,7 +45,7 @@ local function set_position(self)
if parent.direction == "right" then
ret={x=parent.x-self.width,y=parent.y+(self.parent_item.y)}
else
ret={x=parent.x+parent.width,y=parent.y+(self.parent_item.y)- (parent.show_filter and parent.item_height or 0)}
ret={x=parent.x+parent.width,y=parent.y+(self.parent_item.y)-self.style.margins.TOP}
--Handle when the menu doesn't fit in the srceen horizontally
if ret.x+self.width > src_geo.x + src_geo.width then
@ -54,7 +54,7 @@ local function set_position(self)
-- Handle when the menu doesn't fit on the screen vertically
if ret.y+self.height > src_geo.y + src_geo.height then
ret.y = ret.y - self.height + self.item_height
ret.y = ret.y - self.height + self.item_height + 2*self.style.margins.TOP
end
end
elseif parent then

View File

@ -26,9 +26,9 @@ local function setup_drawable(data)
data.set_visible = function(_,v) if data._embeded_parent then data._embeded_parent.visible = v end end
-- Enumate geometry --BUG this is fake, but better than nothing
data.get_width = function() return data._embeded_parent and (data._embeded_parent.width --[[+ (internal.current_width or 0)]])end
data.get_y = function() return data._embeded_parent and (data._embeded_parent.y--[[ + (internal.current_y or 0)]]) end
data.get_x = function() return data._embeded_parent and (data._embeded_parent.x--[[ + (internal.current_x or 0)]]) end
data.get_width = function() return data._embeded_parent and (data._embeded_parent.width)end
data.get_y = function() return data._embeded_parent and (data._embeded_parent.y) end
data.get_x = function() return data._embeded_parent and (data._embeded_parent.x) end
if not data.layout then
data.layout = layout.vertical
end
@ -36,9 +36,6 @@ local function setup_drawable(data)
data.width,data.height = data._internal.layout:fit()
data.margins={left=0,right=0,bottom=0,top=0}
internal.layout:connect_signal("mouse::enter",function(_,geo)
-- internal.current_x = geo.x
-- internal.current_y = geo.y
-- internal.current_width = geo.width
if data._embeded_parent._current_item then
data._embeded_parent._current_item.state[base.item_flags.SELECTED] = nil
data._embeded_parent._current_item.selected = false
@ -53,6 +50,8 @@ local function setup_drawable(data)
end
local function setup_item(data,item,args)
-- Create the layout
local f = (data._internal.layout.setup_item) or (layout.vertical.setup_item)
f(data._internal.layout,data,item,args)
local buttons = {}
@ -86,9 +85,6 @@ local function setup_item(data,item,args)
end
end)
item.widget:connect_signal("mouse::enter",function(_,geo)
item.y = geo.y
end)
end
local function new(args)

View File

@ -135,12 +135,12 @@ local function new_item(data,args)
data._internal.items[#data._internal.items][1] = item
-- Setters
item.set_selected = function(_,value)
item.set_selected = function(_,value,force)
private_data.selected = value
-- Hide the sub-menu
local current_item = data._current_item
if current_item and current_item ~= item or not value then
if current_item and current_item ~= item or force then
current_item.state[module.item_flags.SELECTED] = nil
if current_item._tmp_menu then
current_item._tmp_menu.visible = false

View File

@ -156,12 +156,6 @@ local function create_item(item,data,args)
-- Background
local bg = wibox.widget.background()
--Cache item height
bg.fit = function(box,w,h,...)
args.y = data.height-h-data.margins.top
return wibox.widget.background.fit(box,w,h)
end
-- Margins
local m = wibox.layout.margin(la)
m:set_margins (0)

View File

@ -129,11 +129,21 @@ function module:setup_item(data,item,args)
--Event handling
if data.select_on == base.event.HOVER then
item.widget:connect_signal("mouse::enter", function() item.selected = true end)
item.widget:connect_signal("mouse::leave", function() item.selected = false end)
item.widget:connect_signal("mouse::enter", function(_,geo)
item.y = geo.y
item.selected = true
end)
item.widget:connect_signal("mouse::leave", function()
item.selected = false
end)
else
item.widget:connect_signal("mouse::enter", function() item.hover = true end)
item.widget:connect_signal("mouse::leave", function() item.hover = false end)
item.widget:connect_signal("mouse::enter", function(_,geo)
item.y = geo.y
item.hover = true
end)
item.widget:connect_signal("mouse::leave", function()
item.hover = false
end)
end
data._internal.layout:add(item)