Initial commit

This commit is contained in:
Patrick Alvin Alcala 2025-06-26 16:53:43 +08:00
commit 209ba130c0
4852 changed files with 1517959 additions and 0 deletions

View file

@ -0,0 +1,102 @@
--
-- Basic floating example.
--
local core = require "core"
local Widget = require "libraries.widget"
local Button = require "libraries.widget.button"
local CheckBox = require "libraries.widget.checkbox"
local Line = require "libraries.widget.line"
local Label = require "libraries.widget.label"
local TextBox = require "libraries.widget.textbox"
local function on_button_click(self)
system.show_fatal_error("Clicked:", self.label)
end
---@type widget
local widget = Widget()
widget.size.x = 300
widget.size.y = 300
widget.position.x = 100
widget.draggable = true
widget.scrollable = true
---@type widget.button
local button = Button(widget, "Button1")
button:set_position(10, 10)
button:set_tooltip("Description 1")
button.on_click = on_button_click
---@type widget.button
local button2 = Button(widget, "Button2")
button2:set_position(10, button:get_bottom() + 10)
button2:set_tooltip("Description 2")
---@type widget.button
local button3 = Button(widget, "Button2")
button3:set_position(button:get_right() + 10, 10)
button3:set_tooltip("Description 2")
button3.on_click = on_button_click
---@type widget.button
local button23 = Button(widget, "Button23")
button23:set_position(button:get_right() / 2, 10)
button23:set_tooltip("Description 22")
button23.on_click = on_button_click
---@type widget.checkbox
local checkbox = CheckBox(widget, "Some Checkbox")
checkbox:set_position(10, button2:get_bottom() + 10)
checkbox:set_tooltip("Description checkbox")
checkbox.on_checked = function(_, checked)
core.log_quiet(tostring(checked))
end
---@type widget.label
local label = Label(widget, "Label:")
label:set_position(10, checkbox:get_bottom() + 10)
---@type widget.textbox
local textbox = TextBox(widget, "", "enter text...")
textbox:set_position(10, label:get_bottom() + 10)
textbox:set_tooltip("Texbox")
---@type widget.button
local button4 = Button(widget, "Button4")
button4:set_position(10, textbox:get_bottom() + 10)
button4:set_tooltip("Description 4")
button4.on_click = on_button_click
local button5 = Button(widget, "Button5")
button5:set_position(10, button4:get_bottom() + 10)
button5:set_tooltip("Description 5")
button5.on_click = on_button_click
local button6 = Button(widget, "Button6")
button6:set_position(10, button5:get_bottom() + 10)
button6:set_tooltip("Description 6")
button6.on_click = on_button_click
---@type widget.line
local line = Line(widget)
line:set_position(0, button6:get_bottom() + 10)
-- reposition items on scale changes
widget.update = function(self)
if Widget.update(self) then
button:set_position(10, 10)
button2:set_position(10, button:get_bottom() + 10)
button23:set_position(button:get_right() / 2, 10)
button3:set_position(button:get_right() + 10, 10)
checkbox:set_position(10, button2:get_bottom() + 10)
label:set_position(10, checkbox:get_bottom() + 10)
textbox:set_position(10, label:get_bottom() + 10)
button4:set_position(10, textbox:get_bottom() + 10)
button5:set_position(10, button4:get_bottom() + 10)
button6:set_position(10, button5:get_bottom() + 10)
line:set_position(0, button6:get_bottom() + 10)
end
end
widget:show()

View file

@ -0,0 +1,53 @@
--
-- Basic listbox example.
--
local style = require "core.style"
local command = require "core.command"
local Widget = require "libraries.widget"
local ListBox = require "libraries.widget.listbox"
---@type widget
local widget = Widget()
widget.size.x = 400
widget.size.y = 150
widget.position.x = 100
widget.draggable = true
widget.scrollable = false
widget:centered()
---@type widget.listbox
local listbox = ListBox(widget)
listbox.size.y = widget.size.y - widget.border.width*2
listbox:centered()
listbox:add_row({
style.icon_font, style.syntax.string, "!", style.font, style.text, " Error, ",
ListBox.COLEND,
"A message."
})
for i=1, 10000 do
listbox:add_row({
tostring(i) .. ". Good ",
ListBox.COLEND,
"Hi!."
})
end
listbox:add_row({
"More ",
ListBox.COLEND,
"Final message."
})
listbox.on_row_click = function(self, idx, data)
system.show_fatal_error("Clicked a row", idx)
end
widget:show()
command.add(nil,{
["listbox-widget:toggle"] = function()
widget:toggle_visible()
end
})

View file

@ -0,0 +1,51 @@
--
-- MessageBox example.
--
local MessageBox = require "libraries.widget.messagebox"
---@type widget.messagebox
local messagebox = MessageBox(
nil,
"Multiline",
{
"Some multiline message\nTo see how it works."
}
)
messagebox.size.x = 250
messagebox.size.y = 300
messagebox:add_button("Ok")
messagebox:add_button("Cancel")
messagebox:show()
MessageBox.info(
"Feeling",
"Are you feeling well?",
function(self, button_id, button)
if button_id == 3 then
MessageBox.error(
"Error", {"No response was received!\nNo points for you!"}
)
elseif button_id == 2 then
MessageBox.warning(
"Warning",
"We have to do something about that!",
nil,
MessageBox.BUTTONS_YES_NO
)
elseif button_id == 1 then
MessageBox.info(
"Info",
"We are two now :)"
)
end
end,
MessageBox.BUTTONS_YES_NO_CANCEL
)
function messagebox:on_close(button_id, button)
MessageBox.on_close(self, button_id, button)
self:destroy()
end

View file

@ -0,0 +1,134 @@
--
-- NoteBook example.
--
local core = require "core"
local keymap = require "core.keymap"
local command = require "core.command"
local style = require "core.style"
local NoteBook = require "libraries.widget.notebook"
local Button = require "libraries.widget.button"
local TextBox = require "libraries.widget.textbox"
local NumberBox = require "libraries.widget.numberbox"
local Toggle = require "libraries.widget.toggle"
local ProgressBar = require "libraries.widget.progressbar"
local CheckBox = require "libraries.widget.checkbox"
local ListBox = require "libraries.widget.listbox"
---@type widget.notebook
local notebook = NoteBook()
notebook.size.x = 250
notebook.size.y = 300
notebook.border.width = 0
local log = notebook:add_pane("log", "Messages")
local build = notebook:add_pane("build", "Build")
local errors = notebook:add_pane("errors", "Errors")
local diagnostics = notebook:add_pane("diagnostics", "Diagnostics")
notebook:set_pane_icon("log", "i")
notebook:set_pane_icon("build", "P")
notebook:set_pane_icon("errors", "!")
---@type widget.textbox
local textbox = TextBox(log, "", "placeholder...")
textbox:set_position(10, 20)
---@type widget.numberbox
local numberbox = NumberBox(log, 10)
numberbox:set_position(10, textbox:get_bottom() + 20)
---@type widget.toggle
local toggle = Toggle(log, "The Toggle:", true)
toggle:set_position(10, numberbox:get_bottom() + 20)
---@type widget.progressbar
local progress = ProgressBar(log, 33)
progress:set_position(textbox:get_right() + 50, 20)
---@type widget.checkbox
local checkbox = CheckBox(build, "Child checkbox")
checkbox:set_position(10, 20)
---@type widget.button
local button = Button(errors, "A test button")
button:set_position(10, 20)
button.on_click = function()
system.show_fatal_error("Message", "Hello World")
end
---@type widget.checkbox
local checkbox2 = CheckBox(errors, "Child checkbox2")
checkbox2:set_position(10, button:get_bottom() + 30)
---@type widget.listbox
diagnostics.scrollable = false
local listbox = ListBox(diagnostics)
listbox.border.width = 0
listbox:enable_expand(true)
listbox:add_column("Severity")
listbox:add_column("Message")
listbox:add_row({
style.icon_font, style.syntax.string, "!", style.font, style.text, " Error",
ListBox.COLEND,
"A message to display to the user."
})
listbox:add_row({
style.icon_font, style.syntax.string, "!", style.font, style.text, " Error",
ListBox.COLEND,
"Another message to display to the user\nwith new line characters\nfor the win."
})
core.add_thread(function()
for num=1, 1000 do
listbox:add_row({
style.icon_font, style.syntax.string, "!", style.font, style.text, " Error",
ListBox.COLEND,
tostring(num),
" Another message to display to the user\nwith new line characters\nfor the win."
}, num)
if num % 100 == 0 then
coroutine.yield()
end
end
listbox:add_row({
style.icon_font, style.syntax.string, "!", style.font, style.text, " Error",
ListBox.COLEND,
"Final message to display."
})
end)
listbox.on_row_click = function(self, idx, data)
if data then
system.show_fatal_error("Row Data", data)
end
self:remove_row(idx)
end
-- defer draw needs to be set to false when adding widget as a lite-xl node
notebook.border.width = 0
notebook.draggable = false
notebook.defer_draw = false
local inside_node = false
-- You can add the widget as a lite-xl node
command.add(nil,{
["notebook-widget:toggle"] = function()
if inside_node then
notebook:toggle_visible()
else
local node = core.root_view:get_primary_node()
node:split("down", notebook, {y=true}, true)
notebook:show()
inside_node = true
end
end
})
keymap.add {
["alt+shift+m"] = "notebook-widget:toggle",
}

View file

@ -0,0 +1,129 @@
--
-- A basic search layout example.
--
local core = require "core"
local command = require "core.command"
local Widget = require "libraries.widget"
local Button = require "libraries.widget.button"
local CheckBox = require "libraries.widget.checkbox"
local Line = require "libraries.widget.line"
local Label = require "libraries.widget.label"
local TextBox = require "libraries.widget.textbox"
local MessageBox = require "libraries.widget.messagebox"
local SelectBox = require "libraries.widget.selectbox"
local function on_button_click(self)
MessageBox.info("Clicked:", self.label)
end
---@type widget
local widget = Widget()
widget.name = "Search and Replace"
widget.size.x = 300
widget.size.y = 300
widget.position.x = 100
widget.draggable = true
widget.scrollable = true
---@type widget.label
local label = Label(widget, "Find and Replace")
label:set_position(10, 10)
---@type widget.line
local line = Line(widget)
line:set_position(0, label:get_bottom() + 10)
---@type widget.textbox
local findtext = TextBox(widget, "", "search...")
findtext:set_position(10, line:get_bottom() + 10)
findtext:set_tooltip("Text to search")
---@type widget.textbox
local replacetext = TextBox(widget, "", "replace...")
replacetext:set_position(10, findtext:get_bottom() + 10)
replacetext:set_tooltip("Text to replace")
---@type widget.button
local findprev = Button(widget, "Find Prev")
findprev:set_position(10, replacetext:get_bottom() + 10)
findprev:set_tooltip("Find backwards")
findprev.on_click = on_button_click
---@type widget.button
local findnext = Button(widget, "Find Next")
findnext:set_position(findprev:get_right() + 5, replacetext:get_bottom() + 10)
findnext:set_tooltip("Find forward")
findnext.on_click = on_button_click
---@type widget.button
local replace = Button(widget, "Replace All")
replace:set_position(10, findnext:get_bottom() + 10)
replace:set_tooltip("Replace all matching results")
replace.on_click = on_button_click
---@type widget.line
local line_options = Line(widget)
line_options:set_position(0, replace:get_bottom() + 10)
---@type widget.checkbox
local insensitive = CheckBox(widget, "Insensitive")
insensitive:set_position(10, line_options:get_bottom() + 10)
insensitive:set_tooltip("Case insensitive search")
insensitive.on_checked = function(_, checked)
core.log_quiet(tostring(checked))
end
---@type widget.checkbox
local regex = CheckBox(widget, "Regex")
regex:set_position(10, insensitive:get_bottom() + 10)
regex:set_tooltip("Treat search text as a regular expression")
regex.on_checked = function(_, checked)
core.log_quiet(tostring(checked))
end
---@type widget.selectbox
local scope = SelectBox(widget, "scope")
scope:set_position(10, regex:get_bottom() + 10)
scope:add_option("current file")
scope:add_option("project files")
scope:add_option("some really long option to see")
scope:add_option("other item")
scope:add_option("other option")
-- reposition items on scale changes
widget.update = function(self)
if Widget.update(self) then
label:set_position(10, 10)
line:set_position(0, label:get_bottom() + 10)
findtext:set_position(10, line:get_bottom() + 10)
findtext.size.x = self.size.x - 20
replacetext:set_position(10, findtext:get_bottom() + 10)
replacetext.size.x = self.size.x - 20
findprev:set_position(10, replacetext:get_bottom() + 10)
findnext:set_position(findprev:get_right() + 5, replacetext:get_bottom() + 10)
replace:set_position(10, findnext:get_bottom() + 10)
line_options:set_position(0, replace:get_bottom() + 10)
insensitive:set_position(10, line_options:get_bottom() + 10)
regex:set_position(10, insensitive:get_bottom() + 10)
scope:set_position(10, regex:get_bottom() + 10)
scope.size.x = self.size.x - 20
end
end
widget:show()
-- You can add the widget as a lite-xl node
widget.border.width = 0
widget.draggable = false
widget.defer_draw = false
widget.target_size = 250
local node = core.root_view:get_primary_node()
node:split("right", widget, {x=true}, true)
command.add(nil,{
["find-widget:toggle"] = function()
widget:toggle_visible()
end
})