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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
local awful = require "awful"
local gtable = require "gears.table"
local qbind = require "quarrel.bind"
local qvars = require "quarrel.vars"
local rtimed = require "lib.rubato.timed"
local wibox = require "wibox"
---@class QuarrelUi
local qui = {}
--- Return qvars.text_font with size scaled by factor
---@param factor number
---@return string
---@see QuarrelVars.text_font
function qui.font(factor)
return qvars.text_font .. " " .. qvars.font_size * (factor or 1)
end
--- Inject background widget styling into target
---@param target table
---@return table
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
--- Generate a styled popup
---@param target table
---@return table
function qui.popup(target)
target.widget = {
widget = wibox.container.margin,
margins = qvars.big_padding,
target.widget,
}
return awful.popup(qui.styled(target))
end
--- Generate svg recolor string
---@param color string
---@return string
function qui.recolor(color)
return "svg{fill:" .. color .. "}"
end
--- Generate icon widget
---@param args table
---@return table
function qui.icon(args)
return gtable.crush({
widget = wibox.widget.imagebox,
image = args.icon,
forced_width = qvars.char_height,
forced_height = qvars.char_height,
stylesheet = qui.recolor(args.color or qvars.colors.fg),
}, args.widget or {})
end
--- Generate button widget
---@param args table
---@return table
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
--- Generate toggle widget
---@param args table
---@return table
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
---@param widget wibox.widget.base
---@param cursor string
function qui.hoverable(widget, cursor)
local hovering = false
widget:connect_signal("mouse::enter", function()
local w = mouse.current_wibox
if w then
w.cursor = cursor
end
end)
widget:connect_signal("mouse::leave", function()
local w = mouse.current_wibox
if w then
w.cursor = "left_ptr"
end
end)
end
return qui
|