From 8c1abb21ca569a36536b3b254c075284c7589dee Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Fri, 8 Feb 2019 19:21:20 -0500 Subject: [PATCH] resizing + injector fixes --- sys/apis/injector.lua | 18 +++++++++++------- sys/apis/terminal.lua | 9 +++++++-- sys/apis/ui.lua | 4 +--- sys/apis/ui/canvas.lua | 27 +++++++++++++++++---------- sys/apis/ui/components/SlideOut.lua | 13 +++++++------ sys/apis/ui/components/Viewport.lua | 10 +++++++--- sys/apps/Lua.lua | 6 +++++- sys/apps/Overview.lua | 3 ++- sys/apps/PackageManager.lua | 1 + sys/extensions/4.user.lua | 1 + 10 files changed, 59 insertions(+), 33 deletions(-) diff --git a/sys/apis/injector.lua b/sys/apis/injector.lua index 17e27d5..7f6fc37 100644 --- a/sys/apis/injector.lua +++ b/sys/apis/injector.lua @@ -103,17 +103,21 @@ return function(env) local sPath = string.gsub(pattern, "%?", fname) -- TODO: if there's no shell, we should not be checking relative paths below -- as they will resolve to root directory - if env.shell and type(env.shell.getRunningProgram) == 'function' and sPath:sub(1, 1) ~= "/" then - sPath = fs.combine(fs.getDir(env.shell.getRunningProgram() or ''), sPath) - end - if fs.exists(sPath) and not fs.isDir(sPath) then - return loadfile(sPath, env) - elseif sPath:match("^(https?:)") then - print('loading ' .. sPath) + if sPath:match("^(https?:)") then local c = loadUrl(sPath) if c then return load(c, modname, nil, env) end + else + if env.shell and + type(env.shell.getRunningProgram) == 'function' and + sPath:sub(1, 1) ~= "/" then + + sPath = fs.combine(fs.getDir(env.shell.getRunningProgram() or ''), sPath) + end + if fs.exists(sPath) and not fs.isDir(sPath) then + return loadfile(sPath, env) + end end end end diff --git a/sys/apis/terminal.lua b/sys/apis/terminal.lua index 5d2ccdd..5755d52 100644 --- a/sys/apis/terminal.lua +++ b/sys/apis/terminal.lua @@ -101,12 +101,17 @@ function Terminal.window(parent, sx, sy, w, h, isVisible) win.setTextColour = win.setTextColor function win.getPaletteColor(n) - return parent.getPaletteColor(n) + if parent.getPaletteColor then + return parent.getPaletteColor(n) + end + return 0, 0, 0 end win.getPaletteColour = win.getPaletteColor function win.setPaletteColor(n, r, g, b) - return parent.setPaletteColor(n, r, g, b) + if parent.setPaletteColor then + return parent.setPaletteColor(n, r, g, b) + end end win.setPaletteColour = win.setPaletteColor diff --git a/sys/apis/ui.lua b/sys/apis/ui.lua index 36e4bc1..f9e8602 100644 --- a/sys/apis/ui.lua +++ b/sys/apis/ui.lua @@ -504,9 +504,7 @@ function UI.Window:layout() end end --- bad name... should be called something like postInit --- normally used to determine sizes since the parent is --- only known at this point +-- Called when the window's parent has be assigned function UI.Window:setParent() self.oh, self.ow = self.height, self.width self.ox, self.oy = self.x, self.y diff --git a/sys/apis/ui/canvas.lua b/sys/apis/ui/canvas.lua index 01328dc..c0f62e6 100644 --- a/sys/apis/ui/canvas.lua +++ b/sys/apis/ui/canvas.lua @@ -66,6 +66,7 @@ function Canvas:resize(w, h) for i = 1, self.height do self.lines[i] = { dirty = true } end + self:clear() end self.ex = self.x + w - 1 @@ -261,10 +262,20 @@ function Canvas:applyPalette(palette) end function Canvas:render(device) + local offset = { x = 0, y = 0 } + local parent = self.parent + while parent do + offset.x = offset.x + parent.x - 1 + offset.y = offset.y + parent.y - 1 + parent = parent.parent + end if #self.layers > 0 then - self:__renderLayers(device, { x = 0, y = 0 }) + self:__renderLayers(device, offset) else - self:__blitRect(device) + self:__blitRect(device, nil, { + x = self.x + offset.x, + y = self.y + offset.y + }) self:clean() end end @@ -316,14 +327,10 @@ function Canvas:__renderLayers(device, offset) self.regions = nil else - offset = { x = self.x, y = self.y } - local parent = self.parent - while parent do - offset.x = offset.x + parent.x - 1 - offset.y = offset.y + parent.y - 1 - parent = parent.parent - end - self:__blitRect(device, nil, offset) + self:__blitRect(device, nil, { + x = self.x + offset.x, + y = self.y + offset.y + }) self.regions = nil end self:clean() diff --git a/sys/apis/ui/components/SlideOut.lua b/sys/apis/ui/components/SlideOut.lua index 5994c69..9e85251 100644 --- a/sys/apis/ui/components/SlideOut.lua +++ b/sys/apis/ui/components/SlideOut.lua @@ -7,12 +7,13 @@ UI.SlideOut.defaults = { UIElement = 'SlideOut', pageType = 'modal', } -function UI.SlideOut:setParent() - -- TODO: size should be set at this point - self:layout() - self.canvas = self:addLayer() - - UI.Window.setParent(self) +function UI.SlideOut:layout() + UI.Window.layout(self) + if not self.canvas then + self.canvas = self:addLayer() + else + self.canvas:resize(self.width, self.height) + end end function UI.SlideOut:enable() diff --git a/sys/apis/ui/components/Viewport.lua b/sys/apis/ui/components/Viewport.lua index e8289bd..b0e2a30 100644 --- a/sys/apis/ui/components/Viewport.lua +++ b/sys/apis/ui/components/Viewport.lua @@ -19,9 +19,13 @@ UI.Viewport.defaults = { [ 'control-f' ] = 'scroll_pageDown', }, } -function UI.Viewport:setParent() - UI.Window.setParent(self) - self.canvas = self:addLayer() +function UI.Viewport:layout() + UI.Window.layout(self) + if not self.canvas then + self.canvas = self:addLayer() + else + self.canvas:resize(self.width, self.height) + end end function UI.Viewport:enable() diff --git a/sys/apps/Lua.lua b/sys/apps/Lua.lua index 78e3a13..4414475 100644 --- a/sys/apps/Lua.lua +++ b/sys/apps/Lua.lua @@ -1,4 +1,8 @@ -_G.requireInjector(_ENV) +if not _G.requireInjector then + local BASE ='https://raw.githubusercontent.com/kepler155c/opus/develop-1.8/sys/apis' + _ENV.LUA_PATH=BASE .. '/?.lua' + load(_G.http.get(BASE .. '/injector.lua').readAll())()(_ENV) +end local History = require('history') local UI = require('ui') diff --git a/sys/apps/Overview.lua b/sys/apps/Overview.lua index 797a1a7..7deedda 100644 --- a/sys/apps/Overview.lua +++ b/sys/apps/Overview.lua @@ -100,10 +100,11 @@ local page = UI.Page { newApp = UI.Button { text = '+', event = 'new', }, + --[[ volume = UI.Button { x = 3, text = '\15', event = 'volume', - } + },]] }, editor = UI.SlideOut { y = -12, height = 12, diff --git a/sys/apps/PackageManager.lua b/sys/apps/PackageManager.lua index ea4bab9..73cd78b 100644 --- a/sys/apps/PackageManager.lua +++ b/sys/apps/PackageManager.lua @@ -57,6 +57,7 @@ local page = UI.Page { }, output = UI.Embedded { y = 5, ey = -2, x = 2, ex = -2, + visible = true, }, }, statusBar = UI.StatusBar { }, diff --git a/sys/extensions/4.user.lua b/sys/extensions/4.user.lua index 96953bf..169155d 100644 --- a/sys/extensions/4.user.lua +++ b/sys/extensions/4.user.lua @@ -44,5 +44,6 @@ end shell.setPath(table.concat(path, ':')) _G.LUA_PATH = config.lua_path +_G.settings.set('require.path', config.lua_path) fs.loadTab('usr/config/fstab')