resizing + injector fixes

This commit is contained in:
kepler155c@gmail.com 2019-02-08 19:21:20 -05:00
parent 72b3c7bac9
commit 8c1abb21ca
10 changed files with 59 additions and 33 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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')

View File

@ -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,

View File

@ -57,6 +57,7 @@ local page = UI.Page {
},
output = UI.Embedded {
y = 5, ey = -2, x = 2, ex = -2,
visible = true,
},
},
statusBar = UI.StatusBar { },

View File

@ -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')