首页 > 解决方案 > 一种使用鼠标滚动布局小部件的方法?

问题描述

您能帮我了解如何使用鼠标滚动布局的内容吗?或者有可能吗?

我创建了这个通知中心小部件,我用来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
        )
    )
)

这是通知中心,没有足够的空间来显示其他小部件

对不起,如果我解释得不好。我的英语真的不是很好。

标签: widgetawesome-wm

解决方案


没关系。我在这里尝试了 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)


推荐阅读