widget - 一种使用鼠标滚动布局小部件的方法?
问题描述
您能帮我了解如何使用鼠标滚动布局的内容吗?或者有可能吗?
我创建了这个通知中心小部件,我用来wibox.layout.fixed.vertical()
存储小部件/通知。我的问题是有太多的小部件会占用所有空间,并且没有足够的空间来显示其他小部件。所以我一直在尝试使小部件在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
)
)
)
对不起,如果我解释得不好。我的英语真的不是很好。
解决方案
没关系。我在这里尝试了 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)
推荐阅读
- python - 如何在具有文件目录参数并在另一个 python 文件中返回数组的方法中使用数组?
- asp.net - ASP。NET ScriptManager 安全问题
- python - 创建新工作表而不是使用现有工作表
- angular - 将值设置为表格 Grid Angular 5 中动态生成的下拉列表
- c# - 如何通过串口编写结构?
- android - 如何从适配器获取变量值到android kotlin recyclerview中的活动?
- sql - 关键字“选择”附近的语法不正确。如何在此代码中解决
- python - rm -rf 不通过 python fork execl 脚本删除目录
- ruby-on-rails - Rails如何缓存部分?
- java - 无法解析方法膨胀(android.context.Context)