aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/quarrel/ui.lua
blob: 274d48abb4d60b51a5a03d4f57321500e89d4cea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
local awful = require "awful"
local gtable = require "gears.table"
local qbind = require "quarrel.bind"
local qvars = require "quarrel.vars"
local wibox = require "wibox"

local qui = {}

function qui.markup_fg(color, text)
    return "<span color=\"" .. color .. "\">" .. text .. "</span>"
end

function qui.markup_bg(color, text)
    return "<span bgcolor=\"" .. color .. "\">" .. text .. "</span>"
end

function qui.font(factor)
    return qvars.text_font .. " " .. qvars.font_size * (factor or 1)
end

function qui.styled(target)
    return gtable.crush({
        bg = qvars.colors.bg,
        border_color = qvars.colors.bright.black,
        border_width = qvars.border_width,
        shape = qvars.shape
    }, target)
end

function qui.popup(target)
    target.widget = {
        widget = wibox.container.margin,
        margins = qvars.big_padding,
        target.widget
    }

    return awful.popup(qui.styled(target))
end

function qui.tooltip(objects, callback)
    awful.tooltip(qui.styled {
        objects = objects,
        timer_function = callback,
        margin_leftright = qvars.padding,
        margin_topbottom = qvars.padding
    })
end

function qui.recolor(color)
    return "svg{fill:" .. color .. "}"
end

function qui.icon(image, color, target)
    local widget = {
        widget = wibox.widget.imagebox,
        image = image,
        forced_width = qvars.char_height,
        forced_height = qvars.char_height,
        stylesheet = qui.recolor(color or qvars.colors.fg)
    }
    if target then 
        return gtable.crush(widget, target)
    else
        return widget
    end
end

function qui.button(args)
    args.press = args.press or function(_) end
    local widget = wibox.widget(gtable.crush({
        widget = wibox.widget.imagebox,
        image = args.image,
        forced_height = qvars.char_height,
        forced_width = qvars.char_height,
        stylesheet = qui.recolor(qvars.colors.fg),
        press = args.press
    }, args.widget or {}))

    widget.buttons = {
        qbind:new {
            triggers = qvars.btns.left,
            press = function()
                widget:press()
            end,
            hidden = true
        }
    }

    return widget
end

function qui.toggle(args)
    args.press = args.press or function(_) end
    local widget = qui.button({
        widget = gtable.crush({
            toggled = false,
            silent_press = function(self, state)
                if state then
                    self.toggled = state
                else
                    self.toggled = not self.toggled
                end
                
                if self.toggled then
                    self.image = args.on
                else
                    self.image = args.off
                end
            end,
        }, args.widget or {}),
        image = args.off,
        press = function(self)
            if not args.manual then
                self:silent_press()
            end
            args.press(self)
        end
    })

    return widget
end

return qui