小部件背景上的小部件
Widget on backroud of widget
是否可以在 awesome wm 中将小部件绘制在另一个小部件之上?例如:在进度条上绘制带有一些文本(百分比)的 texbox。
这是可行的解决方案
local function make_stack(w1, w2)
local ret = wibox.widget.base.make_widget()
ret.fit = function(self, ...) return w1:fit(...) end
ret.draw = function(self, wibox, cr, width, height)
w1:draw(wibox, cr, width, height)
w2:draw(wibox, cr, width, height)
end
update = function() ret:emit_signal("widget::updated") end
w1:connect_signal("widget::updated", update)
w2:connect_signal("widget::updated", update)
return ret
end
没有像这样内置的东西,但你可以自己写(未经测试):
function make_stack(w1, w2)
local ret = wibox.widget.base.make_widget()
local update = function() ret:emit_signal("widget::updated") end
w1:connect_signal("widget::updated", update)
w2:connect_signal("widget::updated", update)
ret.fit = function(self, ...) return w2:fit(...) end
ret.draw = function(self, wibox, cr, width, height)
wibox.layout.base.draw_widget(wibox, cr, w1, 0, 0, width, height)
wibox.layout.base.draw_widget(wibox, cr, w2, 0, 0, width, height)
end
return ret
end
函数 make_stack(w1, w2)
创建了一个新的小部件,它在 w1
之上绘制 w2
。小部件 w2
决定两个小部件的大小,如 fit
函数中所示。
可以这样使用,例如:left_layout:add(make_stack(mytasklist[s], mytextclock))
是否可以在 awesome wm 中将小部件绘制在另一个小部件之上?例如:在进度条上绘制带有一些文本(百分比)的 texbox。
这是可行的解决方案
local function make_stack(w1, w2)
local ret = wibox.widget.base.make_widget()
ret.fit = function(self, ...) return w1:fit(...) end
ret.draw = function(self, wibox, cr, width, height)
w1:draw(wibox, cr, width, height)
w2:draw(wibox, cr, width, height)
end
update = function() ret:emit_signal("widget::updated") end
w1:connect_signal("widget::updated", update)
w2:connect_signal("widget::updated", update)
return ret
end
没有像这样内置的东西,但你可以自己写(未经测试):
function make_stack(w1, w2)
local ret = wibox.widget.base.make_widget()
local update = function() ret:emit_signal("widget::updated") end
w1:connect_signal("widget::updated", update)
w2:connect_signal("widget::updated", update)
ret.fit = function(self, ...) return w2:fit(...) end
ret.draw = function(self, wibox, cr, width, height)
wibox.layout.base.draw_widget(wibox, cr, w1, 0, 0, width, height)
wibox.layout.base.draw_widget(wibox, cr, w2, 0, 0, width, height)
end
return ret
end
函数 make_stack(w1, w2)
创建了一个新的小部件,它在 w1
之上绘制 w2
。小部件 w2
决定两个小部件的大小,如 fit
函数中所示。
可以这样使用,例如:left_layout:add(make_stack(mytasklist[s], mytextclock))