1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-28 00:39:30 +00:00

Renamed item.fileSize to item.size in fs.list() return value, enabled 3D in the editor, added a lot of missing documentation

For the return values, I followed this rule: if the fuction returns true on success, it should return false, error on error; for every other case it should return nil, error on error.

Also, who doesn't want to edit code in 3D ? The line depth depends on the indentation level.
This commit is contained in:
Reuh 2016-04-22 13:42:59 +02:00
parent 2b7d37304d
commit 358b68c643
13 changed files with 143 additions and 72 deletions

View file

@ -44,9 +44,36 @@ local fileModified = false
local function displayedText(text)
return text:gsub("\t", " "), nil
end
local function drawTop(eye)
-- Depth multiplicator. Multiply by a positive and add to x to add depth; multiply by a negative and add to x to go out of the screen.
local function d(mul) return math.floor(mul * hid.pos3d() * eye) end
-- Lines
local sI = math.floor(scrollY / lineHeight)
if sI < 1 then sI = 1 end
local eI = math.ceil((scrollY + gfx.TOP_HEIGHT) / lineHeight)
if eI > #lines then eI = #lines end
for i = sI, eI, 1 do
local x = -scrollX
local y = -scrollY+ (i-1)*lineHeight
for _,colored in ipairs(coloredLines[i]) do
local str = displayedText(colored[1])
gfx.text(x + d(#(lines[i]:match("^%s+") or "")*3), y, str, fontSize, colored[2])
x = x + font:width(str)
end
end
-- Cursor
local curline = lines[cursorY]
gfx.rectangle(-scrollX+ font:width(displayedText(curline:sub(1, (utf8.offset(curline, cursorX) or 0)-1))) + d(#(curline:match("^%s+") or "")*3),
-scrollY+ (cursorY-1)*lineHeight, 1, lineHeight, 0, color.cursor)
end
-- Set defaults
gfx.set3D(false)
gfx.set3D(true)
gfx.color.setDefault(color.default)
gfx.color.setBackground(color.background)
gfx.font.setDefault(font)
@ -178,32 +205,17 @@ while ctr.run() do
end
-- Draw
gfx.start(gfx.TOP)
-- Lines
local sI = math.floor(scrollY / lineHeight)
if sI < 1 then sI = 1 end
local eI = math.ceil((scrollY + gfx.TOP_HEIGHT) / lineHeight)
if eI > #lines then eI = #lines end
for i = sI, eI, 1 do
local x = -scrollX
local y = -scrollY+ (i-1)*lineHeight
for _,colored in ipairs(coloredLines[i]) do
local str = displayedText(colored[1])
gfx.text(x, y, str, fontSize, colored[2])
x = x + font:width(str)
end
end
-- Cursor
local curline = lines[cursorY]
gfx.rectangle(-scrollX+ font:width(displayedText(curline:sub(1, (utf8.offset(curline, cursorX) or 0)-1))),
-scrollY+ (cursorY-1)*lineHeight, 1, lineHeight, 0, color.cursor)
local is3D = hid.pos3d() > 0
gfx.start(gfx.TOP, gfx.LEFT)
drawTop(is3D and 0 or -1)
gfx.stop()
if is3D then
gfx.start(gfx.TOP, gfx.RIGHT)
drawTop(1)
gfx.stop()
end
gfx.start(gfx.BOTTOM)

View file

@ -115,7 +115,7 @@ local function drawBottom(externalConfig, workingDirectoryScroll, selected)
gfx.text(1, 15, selectedFile.name, 12)
if not selectedFile.isDirectory then
gfx.text(1, 45, tostring(selectedFile.fileSize) .. "B", 12, 0xFF727272)
gfx.text(1, 45, tostring(selectedFile.size) .. "B", 12, 0xFF727272)
end
local binding, pattern = getBinding(selectedFile, bindings)