【问题标题】:Widget on backroud of widget小部件背景上的小部件
【发布时间】:2016-10-17 23:17:59
【问题描述】:

在很棒的 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

【问题讨论】:

    标签: lua awesome-wm


    【解决方案1】:

    没有这样的内置,但你可以自己写(未经测试):

    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))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-17
      • 2014-12-18
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 2021-04-30
      相关资源
      最近更新 更多