Refactor
This commit is contained in:
parent
3cca359a54
commit
d76fd4b58f
|
@ -403,7 +403,7 @@ function widget.new(args)
|
||||||
function widget_instance:_load_widget_settings()
|
function widget_instance:_load_widget_settings()
|
||||||
if self._widget_settings_loaded then return end
|
if self._widget_settings_loaded then return end
|
||||||
self.width = args.width or dpi(1200)
|
self.width = args.width or dpi(1200)
|
||||||
self.height = args.height or dpi(800)
|
self.height = args.height or dpi(300)
|
||||||
self.bg = args.bg or
|
self.bg = args.bg or
|
||||||
beautiful.hotkeys_bg or beautiful.bg_normal
|
beautiful.hotkeys_bg or beautiful.bg_normal
|
||||||
self.fg = args.fg or
|
self.fg = args.fg or
|
||||||
|
@ -595,6 +595,14 @@ function widget.new(args)
|
||||||
return margin
|
return margin
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function widget_instance:_render_all_hotkeys(labels, find_keywords)
|
||||||
|
local rendered_hotkeys = {}
|
||||||
|
for _, label in ipairs(labels) do
|
||||||
|
table.insert(rendered_hotkeys, self:_render_hotkey(label, find_keywords))
|
||||||
|
end
|
||||||
|
return table.concat(rendered_hotkeys, "\n")
|
||||||
|
end
|
||||||
|
|
||||||
function widget_instance:_render_hotkey(label, find_keywords)
|
function widget_instance:_render_hotkey(label, find_keywords)
|
||||||
local rendered_text = label.text or ""
|
local rendered_text = label.text or ""
|
||||||
|
|
||||||
|
@ -714,9 +722,7 @@ function widget.new(args)
|
||||||
|
|
||||||
local function insert_keys(ik_keys, ik_add_new_column)
|
local function insert_keys(ik_keys, ik_add_new_column)
|
||||||
local labels = {}
|
local labels = {}
|
||||||
local max_label_width = 0
|
for _, key in ipairs(ik_keys) do
|
||||||
local joined_labels = ""
|
|
||||||
for i, key in ipairs(ik_keys) do
|
|
||||||
local modifiers = key.mod
|
local modifiers = key.mod
|
||||||
if not modifiers or modifiers == "none" then
|
if not modifiers or modifiers == "none" then
|
||||||
modifiers = ""
|
modifiers = ""
|
||||||
|
@ -740,26 +746,22 @@ function widget.new(args)
|
||||||
text = tostring(key.description or ""),
|
text = tostring(key.description or ""),
|
||||||
}
|
}
|
||||||
table.insert(labels, label)
|
table.insert(labels, label)
|
||||||
local rendered_hotkey = self:_render_hotkey(label)
|
|
||||||
local label_width = wibox.widget.textbox.get_markup_geometry(rendered_hotkey, s).width
|
|
||||||
if label_width > max_label_width then
|
|
||||||
max_label_width = label_width
|
|
||||||
end
|
end
|
||||||
joined_labels = joined_labels .. rendered_hotkey .. (i~=#ik_keys and "\n" or "")
|
local rendered_hotkeys = self:_render_all_hotkeys(labels)
|
||||||
end
|
local textbox = wibox.widget.textbox(rendered_hotkeys)
|
||||||
local textbox = wibox.widget.textbox(joined_labels)
|
|
||||||
current_column.layout:add(textbox)
|
current_column.layout:add(textbox)
|
||||||
table.insert(find_data.groups, {
|
table.insert(find_data.groups, {
|
||||||
textbox = textbox,
|
textbox = textbox,
|
||||||
labels = labels,
|
labels = labels,
|
||||||
})
|
})
|
||||||
|
local max_label_width = wibox.widget.textbox.get_markup_geometry(rendered_hotkeys, s).width
|
||||||
local max_width = max_label_width + self.group_margin
|
local max_width = max_label_width + self.group_margin
|
||||||
if not current_column.max_width or (max_width > current_column.max_width) then
|
if not current_column.max_width or (max_width > current_column.max_width) then
|
||||||
current_column.max_width = max_width
|
current_column.max_width = max_width
|
||||||
end
|
end
|
||||||
-- +1 for group label:
|
-- +1 for group label:
|
||||||
current_column.height_px = (current_column.height_px or 0) +
|
current_column.height_px = (current_column.height_px or 0) +
|
||||||
gstring.linecount(joined_labels)*line_height + group_label_height
|
gstring.linecount(rendered_hotkeys)*line_height + group_label_height
|
||||||
if ik_add_new_column then
|
if ik_add_new_column then
|
||||||
table.insert(column_layouts, current_column)
|
table.insert(column_layouts, current_column)
|
||||||
end
|
end
|
||||||
|
@ -951,12 +953,8 @@ function widget.new(args)
|
||||||
end
|
end
|
||||||
w_self.find_data.last_query = query
|
w_self.find_data.last_query = query
|
||||||
|
|
||||||
for _, row in ipairs(w_self.find_data.groups) do
|
for _, group in ipairs(w_self.find_data.groups) do
|
||||||
local rendered_hotkeys = {}
|
group.textbox:set_markup(self:_render_all_hotkeys(group.labels, keywords))
|
||||||
for _, label in ipairs(row.labels) do
|
|
||||||
table.insert(rendered_hotkeys, self:_render_hotkey(label, keywords))
|
|
||||||
end
|
|
||||||
row.textbox:set_markup(table.concat(rendered_hotkeys, "\n"))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue