awesome-wm

Why can't I use get_children_by_id() on this widget


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?


Solution

  • 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