根据内容增加 wibox 高度
Increase wibox height depending on content
我有一个垂直布局的 wibox 和两个文本小部件:
local w = wibox {
width = 300,
height = 80,
ontop = true,
screen = mouse.screen,
}
w:setup {
{
id = 'header',
widget = wibox.widget.textbox
},
{
id = 'body',
widget = wibox.widget.textbox
},
id = 'text',
layout = wibox.layout.flex.vertical,
}
当 'body' 文本框中的字符串很短时一切正常,小部件看起来像这样:
但是如果字符串很长,wibox的大小不足以显示所有字符串,所以截掉了部分字符串:
是否可以使 wibox 大小根据内容的大小动态变化?
我不确定你想要什么。如果要为内容调整wibox的高度:
更改文本框的文本后,运行类似于以下代码:
local t1 = w:get_children_by_id("header")[1]
local t2 = w:get_children_by_id("body")[1]
local h1 = t1:get_height_for_width(w.width, w.screen)
local h2 = t2:get_height_for_width(w.width, w.screen)
w.height = h1 + h2
如果您想要一些额外的空白 space 就像在您的第一个屏幕截图中一样,您可以在高度上添加一些数字。 42 始终是一个很好的答案。 ;-)
我有一个垂直布局的 wibox 和两个文本小部件:
local w = wibox {
width = 300,
height = 80,
ontop = true,
screen = mouse.screen,
}
w:setup {
{
id = 'header',
widget = wibox.widget.textbox
},
{
id = 'body',
widget = wibox.widget.textbox
},
id = 'text',
layout = wibox.layout.flex.vertical,
}
当 'body' 文本框中的字符串很短时一切正常,小部件看起来像这样:
但是如果字符串很长,wibox的大小不足以显示所有字符串,所以截掉了部分字符串:
是否可以使 wibox 大小根据内容的大小动态变化?
我不确定你想要什么。如果要为内容调整wibox的高度:
更改文本框的文本后,运行类似于以下代码:
local t1 = w:get_children_by_id("header")[1]
local t2 = w:get_children_by_id("body")[1]
local h1 = t1:get_height_for_width(w.width, w.screen)
local h2 = t2:get_height_for_width(w.width, w.screen)
w.height = h1 + h2
如果您想要一些额外的空白 space 就像在您的第一个屏幕截图中一样,您可以在高度上添加一些数字。 42 始终是一个很好的答案。 ;-)