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?

FluffyDango
  • 133
  • 9
  • What happens when you leave out the inner call to `wibox.widget`? Specifically, replace `widget = wibox.widget {` with just `{`. – Uli Schlachter Apr 23 '22 at 20:21
  • Actually, I think you should get rid of all calls to `wibox.widget`. `:setup` already does that for you and running that "magic" several times creates several "universes" where IDs can be resolved and the inner ones do not know about the outer ones and vice-versa. – Uli Schlachter Apr 23 '22 at 20:22

1 Answers1

0
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

FluffyDango
  • 133
  • 9