一种使用鼠标滚动布局小部件的方法?
A way to scroll a layout's widgets using mouse?
你能帮我看看如何使用鼠标滚动布局的内容吗?或者有可能吗?
我创建了这个 notification-center 小部件,并使用 wibox.layout.fixed.vertical()
来存储 widgets/notifications。我的问题是有太多的小部件会消耗所有 space 并且没有足够的 space 来显示其他小部件。所以我一直在尝试使 wibox.layout.fixed.vertical()
内的小部件可滚动,但我总是走到死胡同。我也尝试了 wibox.container.scroll
但正如文档所述:
Please note that mouse events do not propagate to widgets inside of the scroll container.
这是我使用的简单代码:
-- Layout
local notifbox_layout = wibox.layout.fixed.vertical()
-- Add these textbox widgets to layout
-- Make this widgets scrollable if there's too many of them
notifbox_layout:insert(1, wibox.widget.textbox('String 1'))
notifbox_layout:insert(1, wibox.widget.textbox('String 2'))
notifbox_layout:insert(1, wibox.widget.textbox('String 3'))
notifbox_layout:insert(1, wibox.widget.textbox('String 4'))
notifbox_layout:insert(1, wibox.widget.textbox('String 5'))
-- Mouse event
notifbox_layout:buttons(
gears.table.join(
awful.button(
{},
4,
nil,
function()
-- some magic here to scroll up
end
),
awful.button(
{},
5,
nil,
function()
-- some magic here to scroll down
end
)
)
)
This is the notification center with no enough space to show the other widgets
对不起,如果我解释得不好。我的英语不是很好
没关系。我尝试了 Uli Schlachter 的回答 。它完美地工作。我稍微修改了一下,然后变成了这个样子
local w = wibox{ x = 100, y = 100, width = 100, height = 20, visible = true }
my_wiget = function()
return some_widget
end
local own_widget = wibox.widget.base.make_widget()
local offset_x, offset_y = -20, 0
function own_widget:layout(context, width, height)
-- No idea how to pick good widths and heights for the inner widget.
return { wibox.widget.base.place_widget_at(my_widget(), offset_x, offset_y, 200, 40) }
end
own_widget:buttons(
awful.util.table.join(
awful.button(
{},
4,
function()
if offset_y <= 490 then
offset_y = offset_y + 5
end
own_widget:emit_signal("widget::layout_changed")
end
),
awful.button(
{},
5,
function()
if offset_y >= 5 then
offset_y = offset_y - 5
end
own_widget:emit_signal("widget::layout_changed")
end
)
)
)
w:set_widget(own_widget)
你能帮我看看如何使用鼠标滚动布局的内容吗?或者有可能吗?
我创建了这个 notification-center 小部件,并使用 wibox.layout.fixed.vertical()
来存储 widgets/notifications。我的问题是有太多的小部件会消耗所有 space 并且没有足够的 space 来显示其他小部件。所以我一直在尝试使 wibox.layout.fixed.vertical()
内的小部件可滚动,但我总是走到死胡同。我也尝试了 wibox.container.scroll
但正如文档所述:
Please note that mouse events do not propagate to widgets inside of the scroll container.
这是我使用的简单代码:
-- Layout
local notifbox_layout = wibox.layout.fixed.vertical()
-- Add these textbox widgets to layout
-- Make this widgets scrollable if there's too many of them
notifbox_layout:insert(1, wibox.widget.textbox('String 1'))
notifbox_layout:insert(1, wibox.widget.textbox('String 2'))
notifbox_layout:insert(1, wibox.widget.textbox('String 3'))
notifbox_layout:insert(1, wibox.widget.textbox('String 4'))
notifbox_layout:insert(1, wibox.widget.textbox('String 5'))
-- Mouse event
notifbox_layout:buttons(
gears.table.join(
awful.button(
{},
4,
nil,
function()
-- some magic here to scroll up
end
),
awful.button(
{},
5,
nil,
function()
-- some magic here to scroll down
end
)
)
)
This is the notification center with no enough space to show the other widgets
对不起,如果我解释得不好。我的英语不是很好
没关系。我尝试了 Uli Schlachter 的回答
local w = wibox{ x = 100, y = 100, width = 100, height = 20, visible = true }
my_wiget = function()
return some_widget
end
local own_widget = wibox.widget.base.make_widget()
local offset_x, offset_y = -20, 0
function own_widget:layout(context, width, height)
-- No idea how to pick good widths and heights for the inner widget.
return { wibox.widget.base.place_widget_at(my_widget(), offset_x, offset_y, 200, 40) }
end
own_widget:buttons(
awful.util.table.join(
awful.button(
{},
4,
function()
if offset_y <= 490 then
offset_y = offset_y + 5
end
own_widget:emit_signal("widget::layout_changed")
end
),
awful.button(
{},
5,
function()
if offset_y >= 5 then
offset_y = offset_y - 5
end
own_widget:emit_signal("widget::layout_changed")
end
)
)
)
w:set_widget(own_widget)