diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..fe5d952 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "src/Basalt"] + path = src/Basalt + url = https://github.com/Pyroxenium/Basalt diff --git a/src/Basalt b/src/Basalt new file mode 160000 index 0000000..8b3b6f3 --- /dev/null +++ b/src/Basalt @@ -0,0 +1 @@ +Subproject commit 8b3b6f3490243c9d62ddf9e616534a9499c73689 diff --git a/src/gui/label.lua b/src/gui/label.lua deleted file mode 100644 index 8bec77a..0000000 --- a/src/gui/label.lua +++ /dev/null @@ -1,43 +0,0 @@ -return { - new = function(str) - return { - type="label", - content=str - } - end, - draw = function(label,ctx) - local w,_ = term.getSize() - local _,y = term.getCursorPos() - term.setTextColor(ctx.color.secondary) - - -- split words - local content = {} - for word in label.content:gmatch('([^ ]+)') do - table.insert(content,word) - end - - -- Split lines - local len = 0 - local splits = {} - for i=1,#content do - len = len+#content[i]+1 - if len > w/2 or i==#content then - table.insert(splits,{i,len}) - len = 0 - end - end - - -- Render - for i=1,#splits do - term.setCursorPos((w-splits[i][2])/2,y+i-1) - local begin = 1 - if i > 1 then - begin = splits[i-1][1]+1 - end - - for j=begin,splits[i][1] do - term.write(' '..content[j]) - end - end - end -} \ No newline at end of file diff --git a/src/gui/render.lua b/src/gui/render.lua deleted file mode 100644 index 535ee05..0000000 --- a/src/gui/render.lua +++ /dev/null @@ -1,38 +0,0 @@ -return { - new = function(name) - return {name=name} - end, - draw = function(page,ctx) - local w,h = term.getSize() - - if ctx.redraw then - term.setBackgroundColor(ctx.color.bg) - term.clear() - ctx.redraw = false - end - - -- Widgets - term.setBackgroundColor(ctx.color.bg) - local y = 3+ctx.scroll - for i=1,#page do - term.setCursorPos(0,y+2) - if page[i].type then - if ctx.gui[page[i].type] then - ctx.gui[page[i].type].draw(page[i], ctx) - end - end - _,y = term.getCursorPos() - end - - page.length = y-(4+ctx.scroll) - if page.length < 3 then page.length = 3 end - - -- Header - local line = (' '):rep(w) - term.setBackgroundColor(ctx.color.primary) - for y=1,3 do - term.setCursorPos(1,y+ctx.scroll) - term.write(line) - end - end -} \ No newline at end of file diff --git a/src/init.lua b/src/init.lua index 2175097..8aea740 100644 --- a/src/init.lua +++ b/src/init.lua @@ -1,6 +1,8 @@ -- make a copy of package.path local old_path = package.path local sPath = fs.getDir(shell.getRunningProgram()) +local sData = fs.combine(sPath,"data") +local basalt = require("basalt") local ctx package.path = string.format( @@ -8,39 +10,13 @@ ) local function init(...) ctx = {gui={},pages={},current=1,scroll=0,redraw=true} - local sGui = fs.combine(sPath,"gui") - local sData = fs.combine(sPath,"data") - local sPages = fs.combine(sData,"pages") - -- load widgets - local widgets = fs.list(sGui) - for i=1,#widgets do - local _,nX = widgets[i]:find('%.') - if nX then widgets[i] = widgets[i]:sub(1,nX-1) end - - local tmp = require(fs.combine(sGui,widgets[i])) - ctx.gui[widgets[i]] = {} - for k,v in pairs(tmp) do - ctx.gui[widgets[i]][k] = v - end - end - -- load pages - local pages = fs.list(sPages) + local pages = fs.list(fs.combine(sData,"pages")) for i=1,#pages do - local f = fs.open(fs.combine(sPages,pages[i]), 'r') - local content = f.readAll() + local f = fs.open(fs.combine(sData,"pages",pages[i]), 'r') + ctx.pages[pages[i]] = f.readAll() f.close() - - content = textutils.unserialise(content) - if type(content) == "table" then - content.length = 0 - if pages[i] == "index.table" then - table.insert(ctx.pages, 1, content) - else - table.insert(ctx.pages, content) - end - end end -- load colors @@ -65,36 +41,47 @@ end,function(err) printError(err) end) + -- MAIN -xpcall(function() - parallel.waitForAny( - function() - while true do - ctx.gui.render.draw(ctx.pages[1],ctx) - sleep() - end - end, - function() - while true do - local _,h = term.getSize() - local event = {os.pullEvent()} -- CHANGE TO pullEventRaw later!!!!! - ctx.redraw = true - if event[1] == "mouse_scroll" then - if ctx.pages[1].length > h then - ctx.scroll = ctx.scroll-event[2] - if ctx.scroll > 0 then - ctx.scroll = 0 - elseif ctx.scroll < -(ctx.pages[1].length) then - ctx.scroll = -(ctx.pages[1].length) - end - end +local base = basalt.createFrame() + :setTheme({ + FrameBG = colors.black, + MenubarBG = colors.cyan, + MenubarText = colors.white, + SelectionText = colors.white, + SelectionBG = colors.black, + ListBG = colors.gray, + ListText = colors.black, + LabelBG = colors.black, + LabelText = colors.white + }) + :addLayout(fs.combine(sData,"index.xml")) + +local displayPage =base:getDeepObject("main-content") +local sCurPage = "" +parallel.waitForAny( + basalt.autoUpdate, + function() + while true do + local scrollbar = base:getDeepObject("main-scroll") + local menubar = base:getDeepObject("main-menubar") + + local tmpPage = menubar:getItem(menubar:getItemIndex()).text + if tmpPage ~= sCurPage then + sCurPage = tmpPage + local oldLayout = displayPage:getLastLayout() + for _,v in pairs(oldLayout) do + displayPage:removeObject(v) end + displayPage:addLayoutFromString(ctx.pages[sCurPage:lower()..".xml"]) end + + displayPage:setOffset(0, scrollbar:getIndex()-1) + sleep() end - ) -end,function(err) - printError(err) -end) + end +) + -- restores package path to original package.path = old_path \ No newline at end of file