所以我当前要做的是非常出色地实现rofi。
我想这样做而不是仅仅使用rofi的原因是因为我想学习如何“很棒”地“自动生成”小部件。 稍后,当我实现网络小部件(单击该小部件,显示面板,显示行中可用的wifi热点等)之类的功能时,这将派上用场。因此,这对我来说就是要学习如何实现出色的工作。而且,我想要一个程序启动器。
而且,在有人提出建议之前,我已经知道有一个很棒的内置发射器,而且我还知道有this。这不是我想要的。我想让rofi和dmenu拥有相同的东西:当您按下键时,我想弹出建议。我希望能够点击建议等。 我想要的是这样的:uhhhh
所以我遇到的问题是:如何自动生成行?我只想在一个地方指定我要多少行,其余的就做得很棒。
我浏览了Elv的github,发现radical
,尽管他制作的是菜单系统,但我认为我可以使用他的一些代码来完成我想要的事情。但是我不能为上帝的爱弄清楚它是如何工作的。对他没有冒犯,但即使对于用户而言,它也并不是很好地记录文件,而且对于实际解释代码的工作原理也没有记录。
所以我的问题是:我怎样做这项工作?我将如何制作自动充当行的小部件?
我想要的是能够自动创建启动器的行。我知道我可以自己对行进行硬编码,让每一行具有不同的ID,然后可以编写一个函数,该函数在每次按键时都会用最相关的匹配项来更新每个小部件。就像(完全未经测试)这样:
local wibox = require("wibox")
local awful = require("awful")
local num_rows = 10
local row_height = 40
-- set the height of the background in accordance to how many rows there are,
-- and how high each row should be
local prompt_height = row_height * num_rows
local prompt_width = 300
-- make a widget in the middle of the screen
local background = wibox({
x = awful.screen.focused().geometry.width / 2 - prompt_width / 2,
y = awful.screen.focused().geometry.height / 2 - prompt_height / 2,
width = prompt_width,
height = prompt_height,
bg = "#111111",
visible = false,
ontop = false
})
local rofi_launcher = wibox.widget({
widget = background,
{
-- get a flexible layout so the searchbox and the suggestion boxes get
-- scaled to take up all the space of the background
layout = wibox.layout.flex.vertical,
{ -- the prompt you actually type in
-- set id here so we can adjust its ratio later, so the magnifying
-- glass will end up on the right, and the texbox will take up the left side
id = "searchbox_and_mangifying_glass",
layout = wibox.layout.ratio.horizontal,
{
-- set id so we can use it as a prompt later
id = "searchbox",
widget = wibox.widget.textbox,
},
{
widget = wibox.widget.imagebox,
icon = '~/path/to/magnifying_glass_icon.svg',
},
},
{ -- this is where I actually create the rows that will display suggestions
{ -- row number 1
-- make a background for the textbox to sit in, so you can change
-- background color later for the selected widget, etc etc.
widget = wibox.widget.background,
{
-- give it an id so we can change what's displayed in the
-- textbox when we press keys in the prompt
id = "suggestion_1",
widget = wibox.widget.textbox,
},
},
{ -- row number 2
-- background, again
widget = wibox.widget.background,
{
-- id and textbox again
id = "suggestion_2",
widget = wibox.widget.textbox,
},
},
-- and another 8 (according to the `num_rows` variable) of the same two
-- textboxes above. This is exactly my problem. How can I make these
-- textboxes automatically and still be able to interact with them to
-- display suggestions on the fly, as the user types keys into the prompt?
},
},
})
如果这还不够清楚,请告诉我您不了解的地方,我会更新我的问题。
答案 0 :(得分:0)
同样未经测试的代码,但这会创建一个文本框表,而不是使用声明性布局来创建所有这些文本框:
[SNIP; For shorter code I removed some stuff at the beginning]
local textboxes = {}
local widgets = {}
for i = 1, num_rows do
local tb = wibox.widget.textbox()
local bg = wibox.widget.background(tb)
bg:set_bg("#ff0000") -- The original code did not set a bg color, but that would make the bg widget useless...?
tb.id = "suggestion_" .. tostring(i) -- This is likely unnecessary, but the original code set these IDs, too
table.insert(textboxes, tb)
table.insert(widgets, bg)
end
local rofi_launcher = wibox.widget({
widget = background,
{
-- get a flexible layout so the searchbox and the suggestion boxes get
-- scaled to take up all the space of the background
layout = wibox.layout.flex.vertical,
{ -- the prompt you actually type in
[SNIP - I did not change anything here; I only removed this part to make the code shorter]
},
widgets
},
})
-- Now make the textboxes display something
textboxes[3].text = "I am the third row"
textboxes[5].text = "I am not"