1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-17 16:57:39 +00:00

Overview update

This commit is contained in:
kepler155c@gmail.com
2019-01-28 17:54:00 -05:00
parent dddb2a6b97
commit 02629e266b
4 changed files with 131 additions and 317 deletions

View File

@@ -583,11 +583,11 @@ function UI.Window:sync()
end
end
function UI.Window:enable()
function UI.Window:enable(...)
self.enabled = true
if self.children then
for _,child in pairs(self.children) do
child:enable()
child:enable(...)
end
end
end
@@ -607,10 +607,12 @@ function UI.Window:setTextScale(textScale)
end
function UI.Window:clear(bg, fg)
if self.canvas then
self.canvas:clear(bg or self.backgroundColor, fg or self.textColor)
else
self:clearArea(1 + self.offx, 1 + self.offy, self.width, self.height, bg)
if self.enabled then
if self.canvas then
self.canvas:clear(bg or self.backgroundColor, fg or self.textColor)
else
self:clearArea(1 + self.offx, 1 + self.offy, self.width, self.height, bg)
end
end
end
@@ -628,16 +630,18 @@ function UI.Window:clearArea(x, y, width, height, bg)
end
function UI.Window:write(x, y, text, bg, tc)
bg = bg or self.backgroundColor
tc = tc or self.textColor
x = x - self.offx
y = y - self.offy
if y <= self.height and y > 0 then
if self.canvas then
self.canvas:write(x, y, text, bg, tc)
else
self.parent:write(
self.x + x - 1, self.y + y - 1, tostring(text), bg, tc)
if self.enabled then
bg = bg or self.backgroundColor
tc = tc or self.textColor
x = x - self.offx
y = y - self.offy
if y <= self.height and y > 0 then
if self.canvas then
self.canvas:write(x, y, text, bg, tc)
else
self.parent:write(
self.x + x - 1, self.y + y - 1, tostring(text), bg, tc)
end
end
end
end
@@ -2056,6 +2060,7 @@ function UI.MenuBar:eventHandler(event)
if event.type == 'button_press' and event.button.dropmenu then
if event.button.dropmenu.enabled then
event.button.dropmenu:hide()
self:refocus()
return true
else
local x, y = getPosition(event.button)
@@ -2123,7 +2128,6 @@ function UI.DropMenu:setParent()
end
function UI.DropMenu:enable()
self.enabled = false
end
function UI.DropMenu:show(x, y)
@@ -2131,10 +2135,7 @@ function UI.DropMenu:show(x, y)
self.canvas:move(x, y)
self.canvas:setVisible(true)
self.enabled = true
for _,child in pairs(self.children) do
child:enable()
end
UI.Window.enable(self)
self:draw()
self:capture(self)
@@ -2442,16 +2443,12 @@ function UI.SlideOut:setParent()
end
function UI.SlideOut:enable()
self.enabled = false
end
function UI.SlideOut:show(...)
self:addTransition('expandUp')
self.canvas:setVisible(true)
self.enabled = true
for _,child in pairs(self.children) do
child:enable(...)
end
UI.Window.enable(self, ...)
self:draw()
self:capture(self)
self:focusFirst()
@@ -2459,12 +2456,7 @@ end
function UI.SlideOut:disable()
self.canvas:setVisible(false)
self.enabled = false
if self.children then
for _,child in pairs(self.children) do
child:disable()
end
end
UI.Window.disable(self)
end
function UI.SlideOut:hide()
@@ -2553,7 +2545,6 @@ function UI.Notification:draw()
end
function UI.Notification:enable()
self.enabled = false
end
function UI.Notification:error(value, timeout)

View File

@@ -1,145 +0,0 @@
local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local fs = _G.fs
return function(args)
local columns = {
{ heading = 'Name', key = 'name' },
}
if UI.term.width > 28 then
table.insert(columns,
{ heading = 'Size', key = 'size', width = 5 }
)
end
args = args or { }
local selectFile = UI.Dialog {
x = args.x or 3,
y = args.y or 2,
z = args.z or 2,
-- rex = args.rex or -3,
-- rey = args.rey or -3,
height = args.height,
width = args.width,
title = 'Select File',
grid = UI.ScrollingGrid {
x = 2,
y = 2,
ex = -2,
ey = -4,
path = '',
sortColumn = 'name',
columns = columns,
},
path = UI.TextEntry {
x = 2,
y = -2,
ex = -11,
limit = 256,
accelerators = {
enter = 'path_enter',
}
},
cancel = UI.Button {
text = 'Cancel',
x = -9,
y = -2,
event = 'cancel',
},
}
function selectFile:enable(path, fn)
self:setPath(path)
self.fn = fn
UI.Dialog.enable(self)
end
function selectFile:setPath(path)
self.grid.dir = path
while not fs.isDir(self.grid.dir) do
self.grid.dir = fs.getDir(self.grid.dir)
end
self.path.value = self.grid.dir
end
function selectFile.grid:draw()
local files = fs.listEx(self.dir)
if #self.dir > 0 then
table.insert(files, {
name = '..',
isDir = true,
})
end
self:setValues(files)
self:setIndex(1)
UI.Grid.draw(self)
end
function selectFile.grid:getDisplayValues(row)
if row.size then
row = Util.shallowCopy(row)
row.size = Util.toBytes(row.size)
end
return row
end
function selectFile.grid:getRowTextColor(file)
if file.isDir then
return colors.cyan
end
if file.isReadOnly then
return colors.pink
end
return colors.white
end
function selectFile.grid:sortCompare(a, b)
if self.sortColumn == 'size' then
return a.size < b.size
end
if a.isDir == b.isDir then
return a.name:lower() < b.name:lower()
end
return a.isDir
end
function selectFile:eventHandler(event)
if event.type == 'grid_select' then
self.grid.dir = fs.combine(self.grid.dir, event.selected.name)
self.path.value = self.grid.dir
if event.selected.isDir then
self.grid:draw()
self.path:draw()
else
UI:setPreviousPage()
self.fn(self.path.value)
end
elseif event.type == 'path_enter' then
if fs.isDir(self.path.value) then
self:setPath(self.path.value)
self.grid:draw()
self.path:draw()
else
UI:setPreviousPage()
self.fn(self.path.value)
end
elseif event.type == 'cancel' then
UI:setPreviousPage()
self.fn()
else
return UI.Dialog.eventHandler(self, event)
end
return true
end
return selectFile
end