Fix bugs with sub menu, embed menu and scrolling
This commit is contained in:
parent
dbf1865055
commit
d8e220a7bb
8
base.lua
8
base.lua
|
@ -505,6 +505,10 @@ local function new(args)
|
||||||
|
|
||||||
function data:scroll_up()
|
function data:scroll_up()
|
||||||
if data.max_items ~= nil and data.rowcount >= data.max_items and (data._start_at or 1) > 1 then
|
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
|
||||||
|
end
|
||||||
data._start_at = (data._start_at or 1) - 1
|
data._start_at = (data._start_at or 1) - 1
|
||||||
internal.items[data._start_at][1]._hidden = false
|
internal.items[data._start_at][1]._hidden = false
|
||||||
data:emit_signal("_hidden::changed",internal.items[data._start_at][1])
|
data:emit_signal("_hidden::changed",internal.items[data._start_at][1])
|
||||||
|
@ -516,6 +520,10 @@ local function new(args)
|
||||||
|
|
||||||
function data:scroll_down()
|
function data:scroll_down()
|
||||||
if data.max_items ~= nil and data.rowcount >= data.max_items and (data._start_at or 1)+data.max_items <= data.rowcount then
|
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
|
||||||
|
end
|
||||||
data._start_at = (data._start_at or 1) + 1
|
data._start_at = (data._start_at or 1) + 1
|
||||||
internal.items[data._start_at-1][1]._hidden = true
|
internal.items[data._start_at-1][1]._hidden = true
|
||||||
data:emit_signal("_hidden::changed",internal.items[data._start_at-1][1])
|
data:emit_signal("_hidden::changed",internal.items[data._start_at-1][1])
|
||||||
|
|
28
embed.lua
28
embed.lua
|
@ -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
|
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
|
-- 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_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_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_x = function() return data._embeded_parent and (data._embeded_parent.x--[[ + (internal.current_x or 0)]]) end
|
||||||
if not data.layout then
|
if not data.layout then
|
||||||
data.layout = layout.vertical
|
data.layout = layout.vertical
|
||||||
end
|
end
|
||||||
|
@ -36,9 +36,19 @@ local function setup_drawable(data)
|
||||||
data.width,data.height = data._internal.layout:fit()
|
data.width,data.height = data._internal.layout:fit()
|
||||||
data.margins={left=0,right=0,bottom=0,top=0}
|
data.margins={left=0,right=0,bottom=0,top=0}
|
||||||
internal.layout:connect_signal("mouse::enter",function(_,geo)
|
internal.layout:connect_signal("mouse::enter",function(_,geo)
|
||||||
internal.current_x = geo.x
|
-- internal.current_x = geo.x
|
||||||
internal.current_y = geo.y
|
-- internal.current_y = geo.y
|
||||||
internal.current_width = geo.width
|
-- 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
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
internal.layout:connect_signal("mouse::leave",function(_,geo)
|
||||||
|
if data._current_item then
|
||||||
|
data._current_item.selected = false
|
||||||
|
data._current_item.state[base.item_flags.SELECTED] = nil
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -76,9 +86,9 @@ local function setup_item(data,item,args)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- item.widget:connect_signal("mouse::enter",function(_,geo)
|
item.widget:connect_signal("mouse::enter",function(_,geo)
|
||||||
-- item._internal.tmp_y
|
item.y = geo.y
|
||||||
-- end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function new(args)
|
local function new(args)
|
||||||
|
|
|
@ -217,7 +217,6 @@ end
|
||||||
|
|
||||||
capi.tag.connect_signal("property::selected" , select)
|
capi.tag.connect_signal("property::selected" , select)
|
||||||
capi.tag.connect_signal("property::index2",function(t,i)
|
capi.tag.connect_signal("property::index2",function(t,i)
|
||||||
print("FOO",t,i)
|
|
||||||
if t then
|
if t then
|
||||||
local s = tag.getscreen(t)
|
local s = tag.getscreen(t)
|
||||||
local item = cache[t]
|
local item = cache[t]
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
-- This module try to track tags relative index
|
||||||
|
-- It will emit signals the widget can rely on
|
||||||
|
local capi = {tag=tag}
|
||||||
|
local tag = require( "awful.tag" )
|
||||||
|
local object = require( "radical.object" )
|
||||||
|
|
||||||
|
local cache = {}
|
||||||
|
local init = false
|
||||||
|
local screen_cache = setmetatable({}, { __mode = 'k' })--TODO this suck
|
||||||
|
|
||||||
|
local function reload(t,s)
|
||||||
|
local s = s or tag.getscreen(t) or screen_cache[t]
|
||||||
|
local tracker = cache[s]
|
||||||
|
|
||||||
|
if not tracker then return end
|
||||||
|
|
||||||
|
local old_tags = tracker._internal.old_tags or {}
|
||||||
|
|
||||||
|
local new_tags = tag.gettags(s)
|
||||||
|
for k,v in ipairs(new_tags) do
|
||||||
|
if v ~= old_tags[k] then
|
||||||
|
v:emit_signal("property::index2",k)
|
||||||
|
screen_cache[v] = s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
tracker._internal.old_tags = new_tags
|
||||||
|
end
|
||||||
|
|
||||||
|
local function new(s)
|
||||||
|
if cache[s] then return cache[s] end
|
||||||
|
|
||||||
|
local tracker,private_data = object({
|
||||||
|
private_data = {
|
||||||
|
widget = widget,
|
||||||
|
selected = false,
|
||||||
|
},
|
||||||
|
autogen_getmap = true,
|
||||||
|
autogen_setmap = true,
|
||||||
|
autogen_signals = true,
|
||||||
|
})
|
||||||
|
tracker._internal = {}
|
||||||
|
|
||||||
|
cache[s] = tracker
|
||||||
|
|
||||||
|
if not init then
|
||||||
|
capi.tag.connect_signal("property::screen" , reload )
|
||||||
|
capi.tag.connect_signal("property::activated", reload )
|
||||||
|
end
|
||||||
|
|
||||||
|
tracker.reload = function()
|
||||||
|
reload(nil,s)
|
||||||
|
end
|
||||||
|
|
||||||
|
return tracker
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
capi.tag.add_signal("property::index2")
|
||||||
|
|
||||||
|
|
||||||
|
return setmetatable({}, { __call = function(_, ...) return new(...) end })
|
||||||
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|
|
@ -48,7 +48,6 @@ local module = {
|
||||||
}
|
}
|
||||||
|
|
||||||
local function load_async(tab,key)
|
local function load_async(tab,key)
|
||||||
print("here",key)
|
|
||||||
if key == "style" then
|
if key == "style" then
|
||||||
module.style = require("radical.item.style")
|
module.style = require("radical.item.style")
|
||||||
return module.style
|
return module.style
|
||||||
|
@ -138,26 +137,30 @@ local function new_item(data,args)
|
||||||
-- Setters
|
-- Setters
|
||||||
item.set_selected = function(_,value)
|
item.set_selected = function(_,value)
|
||||||
private_data.selected = value
|
private_data.selected = value
|
||||||
if value == false then
|
|
||||||
data.item_style(item,{})
|
-- Hide the sub-menu
|
||||||
return
|
|
||||||
end
|
|
||||||
local current_item = data._current_item
|
local current_item = data._current_item
|
||||||
if current_item and current_item ~= item then
|
if current_item and current_item ~= item or not value then
|
||||||
current_item.state[module.item_flags.SELECTED] = nil
|
current_item.state[module.item_flags.SELECTED] = nil
|
||||||
if current_item._tmp_menu then
|
if current_item._tmp_menu then
|
||||||
current_item._tmp_menu.visible = false
|
current_item._tmp_menu.visible = false
|
||||||
current_item._tmp_menu = nil
|
current_item._tmp_menu = nil
|
||||||
data._tmp_menu = nil
|
data._tmp_menu = nil
|
||||||
|
current_item:emit_signal("state::changed")
|
||||||
end
|
end
|
||||||
data.item_style(current_item,{})
|
|
||||||
-- current_item.selected = false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Unselect item
|
||||||
|
if value == false then
|
||||||
|
item.state[module.item_flags.SELECTED] = nil
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Select the new one
|
||||||
if data.sub_menu_on == module.event.SELECTED and current_item ~= item then
|
if data.sub_menu_on == module.event.SELECTED and current_item ~= item then
|
||||||
module.execute_sub_menu(data,item)
|
module.execute_sub_menu(data,item)
|
||||||
end
|
end
|
||||||
item.state[module.item_flags.SELECTED] = true
|
item.state[module.item_flags.SELECTED] = true
|
||||||
data.item_style(item,{})
|
|
||||||
data._current_item = item
|
data._current_item = item
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue