为什么我可以在此小部件上使用get_children_by_id()

发布于 2025-01-23 19:06:55 字数 1268 浏览 0 评论 0原文

我想访问内部小部件,但它给了我一个错误,我无法索引零值。

我的小部件:

local previewWidget = wibox()

previewWidget:setup {
    widget = wibox.widget {
        {
            widget = wibox.widget {
                {
                    widget = awful.widget.clienticon,
                    client = "", 
                    id = "clientIcon"
                },
                {
                    widget = wibox.widget.textbox,
                    id = "titleText"
                },
                nil
            },
            layout = wibox.layout.align.horizontal,
            id = "titleBox"
        },
        {
            widget = wibox.widget.imagebox,
            id = "clientImage"
        },
        nil
    },  
    id = "previewBox",
    layout = wibox.layout.align.vertical,
    border_width = 10, 
    border_color = "FF0000",
}

此命令没有给出错误:

local previewBox = previewWidget:get_children_by_id("previewBox")[1]

但这确实:

local titleBox = previewWidget:get_children_by_id("titleBox")[1]
local clientIcon = previewWidget:get_children_by_id("clientIcon")[1]

我在这里做错了什么?

I want to access the internal widgets but it gives me an error, that I can't index a nil value.

My widget:

local previewWidget = wibox()

previewWidget:setup {
    widget = wibox.widget {
        {
            widget = wibox.widget {
                {
                    widget = awful.widget.clienticon,
                    client = "", 
                    id = "clientIcon"
                },
                {
                    widget = wibox.widget.textbox,
                    id = "titleText"
                },
                nil
            },
            layout = wibox.layout.align.horizontal,
            id = "titleBox"
        },
        {
            widget = wibox.widget.imagebox,
            id = "clientImage"
        },
        nil
    },  
    id = "previewBox",
    layout = wibox.layout.align.vertical,
    border_width = 10, 
    border_color = "FF0000",
}

This command doesn't give error:

local previewBox = previewWidget:get_children_by_id("previewBox")[1]

But this does:

local titleBox = previewWidget:get_children_by_id("titleBox")[1]
local clientIcon = previewWidget:get_children_by_id("clientIcon")[1]

What am I doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我家小可爱 2025-01-30 19:06:55
local previewWidget = wibox.widget {
    {
        {
            widget = awful.widget.clienticon,
            client = "",
            id = "clientIcon"
        },
        {
            widget = wibox.widget.textbox,
            id = "titleText"
        },
        nil,

        layout = wibox.layout.align.horizontal,
        id = "titleBox"
    },
    {
        widget = wibox.widget.imagebox,
        id = "clientImage"
    },
    nil,

    layout = wibox.layout.align.vertical,
    id = "previewBox",
}

我错误地使用了布局:
所有3个小部件都必须是布局称为

local some_widget = wibox.widget {
   { widget nr.1 },
   { widget nr.2 },
   { widget nr.3 },
   layout = wibox.layout.align.vertical
}

P.S.这足以声明没有小部件的布局

local previewWidget = wibox.widget {
    {
        {
            widget = awful.widget.clienticon,
            client = "",
            id = "clientIcon"
        },
        {
            widget = wibox.widget.textbox,
            id = "titleText"
        },
        nil,

        layout = wibox.layout.align.horizontal,
        id = "titleBox"
    },
    {
        widget = wibox.widget.imagebox,
        id = "clientImage"
    },
    nil,

    layout = wibox.layout.align.vertical,
    id = "previewBox",
}

I incorrectly used the layout:
All 3 widgets needs to be where the layout is called

local some_widget = wibox.widget {
   { widget nr.1 },
   { widget nr.2 },
   { widget nr.3 },
   layout = wibox.layout.align.vertical
}

P.S. it's enough to declare a layout without a widget

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文