Make the item list a lot better looking, and add placeholders to
inputBox.
This commit is contained in:
parent
e9cfedea55
commit
3c338f05dd
2 changed files with 24 additions and 15 deletions
|
|
@ -92,23 +92,27 @@ end
|
|||
---@param y number The Y position of the box
|
||||
---@param width number The width/length of the box
|
||||
---@param action function|string A function or `run` event to call when a key is pressed
|
||||
---@param placeholder string|nil A string that's set as the placeholder when nothing is written
|
||||
---@param fgColor color|nil The color of the text (defaults to white)
|
||||
---@param bgColor color|nil The color of the background (defaults to black)
|
||||
---@param placeholderFg color|nil The color of the placeholder text (defaults to lightGray)
|
||||
---@param replacement string|nil A character to replace typed characters with
|
||||
---@param history string[]|nil A list of previous entries to provide
|
||||
---@param completion function|nil A function to call to provide completion
|
||||
function PrimeUI.inputBox(win, x, y, width, action, fgColor, bgColor, replacement, history, completion, default)
|
||||
function PrimeUI.inputBox(win, x, y, width, action, placeholder, fgColor, bgColor, placeholderFg, replacement, history, completion, default)
|
||||
expect(1, win, "table")
|
||||
expect(2, x, "number")
|
||||
expect(3, y, "number")
|
||||
expect(4, width, "number")
|
||||
expect(5, action, "function", "string")
|
||||
fgColor = expect(6, fgColor, "number", "nil") or colors.white
|
||||
bgColor = expect(7, bgColor, "number", "nil") or colors.black
|
||||
expect(8, replacement, "string", "nil")
|
||||
expect(9, history, "table", "nil")
|
||||
expect(10, completion, "function", "nil")
|
||||
expect(11, default, "string", "nil")
|
||||
expect(6, placeholder, "string", "nil")
|
||||
fgColor = expect(7, fgColor, "number", "nil") or colors.white
|
||||
bgColor = expect(8, bgColor, "number", "nil") or colors.black
|
||||
placeholderFg = expect(9, placeholderFg, "number", "nil") or colors.lightGray
|
||||
expect(10, replacement, "string", "nil")
|
||||
expect(11, history, "table", "nil")
|
||||
expect(12, completion, "function", "nil")
|
||||
expect(13, default, "string", "nil")
|
||||
|
||||
local box = window.create(win, x, y, width, 1)
|
||||
box.setTextColor(fgColor)
|
||||
|
|
@ -135,7 +139,13 @@ function PrimeUI.inputBox(win, x, y, width, action, fgColor, bgColor, replacemen
|
|||
if replacement then
|
||||
box.write(string.rep(replacement, #text))
|
||||
else
|
||||
box.write(text)
|
||||
if #text == 0 and placeholder then
|
||||
box.setTextColor(placeholderFg)
|
||||
box.write(placeholder)
|
||||
box.setTextColor(fgColor)
|
||||
else
|
||||
box.write(text)
|
||||
end
|
||||
end
|
||||
box.setCursorPos(cursor, 1)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue