better colors - resizing

This commit is contained in:
kepler155c@gmail.com 2017-09-30 20:35:36 -04:00
parent 5681b01810
commit c0baa00668
8 changed files with 84 additions and 89 deletions

View File

@ -2,7 +2,7 @@ local json = require('json')
local Util = require('util')
local TREE_URL = 'https://api.github.com/repos/%s/%s/git/trees/%s?recursive=1'
local FILE_URL = 'https://raw.github.com/%s/%s/%s/%s'
local FILE_URL = 'https://raw.githubusercontent.com/%s/%s/%s/%s'
local git = { }

View File

@ -608,6 +608,19 @@ function UI.Window:setParent()
self:initChildren()
end
function UI.Window:resize()
self.height, self.width = self.oh, self.ow
self.x, self.y = self.ox, self.oy
setSize(self)
if self.children then
for _,child in ipairs(self.children) do
child:resize()
end
end
end
function UI.Window:add(children)
UI.setProperties(self, children)
self:initChildren()
@ -630,7 +643,7 @@ end
function UI.Window:draw()
self:clear(self.backgroundColor)
if self.children then
for k,child in pairs(self.children) do
for _,child in pairs(self.children) do
if child.enabled then
child:draw()
end
@ -644,26 +657,10 @@ function UI.Window:sync()
end
end
function UI.Window:resize()
self.height = self.oh
self.width = self.ow
self.x = self.ox
self.y = self.oy
setSize(self)
if self.children then
for _,child in ipairs(self.children) do
child:resize()
end
end
end
function UI.Window:enable()
self.enabled = true
if self.children then
for k,child in pairs(self.children) do
for _,child in pairs(self.children) do
child:enable()
end
end
@ -672,7 +669,7 @@ end
function UI.Window:disable()
self.enabled = false
if self.children then
for k,child in pairs(self.children) do
for _,child in pairs(self.children) do
child:disable()
end
end
@ -1305,8 +1302,6 @@ function UI.Device:runTransitions(transitions, canvas)
canvas:blitClipped(self.device) -- and blit the remainder
canvas:reset()
local queue = { } -- don't miss events while transition is running
-- especially timers
while true do
for _,k in ipairs(Util.keys(transitions)) do
local transition = transitions[k]
@ -1318,20 +1313,7 @@ function UI.Device:runTransitions(transitions, canvas)
break
end
os.sleep(0)
--[[
local timerId = os.startTimer(0)
while true do
local e = { os.pullEvent() }
if e[1] == 'timer' and e[2] == timerId then
break
end
table.insert(queue, e)
end
--]]
end
-- for _, e in ipairs(queue) do
-- Event.processEvent(e)
-- end
end
function UI.Device:sync()
@ -1359,6 +1341,7 @@ function UI.Device:sync()
end
--[[-- StringBuffer --]]--
-- justs optimizes string concatenations
UI.StringBuffer = class()
function UI.StringBuffer:init(bufSize)
self.bufSize = bufSize
@ -1384,7 +1367,7 @@ function UI.StringBuffer:clear()
self.buffer = { }
end
-- alternate - better ?
-- For manipulating text in a fixed width string
local SB = { }
function SB:new(width)
return setmetatable({
@ -1476,7 +1459,6 @@ function UI.Page:focusPrevious()
end
local focused = getPreviousFocus(self.focused)
if focused then
self:setFocus(focused)
end
@ -1639,11 +1621,14 @@ function UI.Grid:adjustWidth()
else
for k,c in ipairs(t) do
c.cw = #(t[1].heading or '')
c.cw = #(c.heading or '')
w = w - c.cw
end
-- adjust the size to the length of the value
for key,row in pairs(self.values) do
if w <= 0 then
break
end
row = self:getDisplayValues(row, key)
for _,col in pairs(t) do
local value = row[col.key]
@ -1659,9 +1644,6 @@ function UI.Grid:adjustWidth()
end
end
end
if w <= 0 then
break
end
end
-- last column does not get padding (right alignment)
@ -2274,22 +2256,22 @@ function UI.MenuBar:init(args)
local buttonProperties = {
x = x,
width = #button.text + self.spacing,
backgroundColor = self.backgroundColor,
backgroundFocusColor = colors.gray,
textColor = self.textColor,
-- backgroundColor = self.backgroundColor,
-- backgroundFocusColor = colors.gray,
-- textColor = self.textColor,
centered = false,
}
x = x + buttonProperties.width
UI.setProperties(buttonProperties, button)
if button.name then
self[button.name] = UI.Button(buttonProperties)
self[button.name] = UI.MenuItem(buttonProperties)
else
table.insert(self.children, UI.Button(buttonProperties))
table.insert(self.children, UI.MenuItem(buttonProperties))
end
end
end
if self.showBackButton then
table.insert(self.children, UI.Button({
table.insert(self.children, UI.MenuItem({
x = UI.term.width - 2,
width = 3,
backgroundColor = self.backgroundColor,
@ -2324,7 +2306,7 @@ end
UI.DropMenu = class(UI.MenuBar)
UI.DropMenu.defaults = {
UIElement = 'DropMenu',
backgroundColor = colors.white,
backgroundColor = colors.lightGray,
}
function UI.DropMenu:init(args)
local defaults = UI:getDefaults(UI.DropMenu, args)
@ -2332,7 +2314,6 @@ function UI.DropMenu:init(args)
end
function UI.DropMenu:setParent()
UI.MenuBar.setParent(self)
local maxWidth = 1
@ -2868,7 +2849,8 @@ UI.Button.defaults = {
text = 'button',
backgroundColor = colors.gray,
backgroundFocusColor = colors.lightGray,
textFocusColor = colors.black,
textFocusColor = colors.white,
textColor = colors.white,
centered = true,
height = 1,
focusIndicator = '>',
@ -2924,6 +2906,21 @@ function UI.Button:eventHandler(event)
return false
end
--[[-- MenuItem --]]--
UI.MenuItem = class(UI.Button)
UI.MenuItem.defaults = {
UIElement = 'MenuItem',
textColor = colors.black,
backgroundColor = colors.lightGray,
textFocusColor = colors.white,
backgroundFocusColor = colors.lightGray,
}
function UI.MenuItem:init(args)
local defaults = UI:getDefaults(UI.MenuItem, args)
UI.Button.init(self, defaults)
end
--[[-- TextEntry --]]--
UI.TextEntry = class(UI.Window)
UI.TextEntry.defaults = {

View File

@ -1,16 +1,15 @@
local Util = require('util')
local UI = require('ui')
local UI = require('ui')
local Util = require('util')
return function(args)
local columns = {
{ heading = 'Name', key = 'name', width = UI.term.width - 9 },
{ heading = 'Name', key = 'name' },
}
if UI.term.width > 28 then
columns[1].width = UI.term.width - 16
table.insert(columns,
{ heading = 'Size', key = 'size', width = 6 }
{ heading = 'Size', key = 'size', width = 5 }
)
end

View File

@ -7,42 +7,39 @@ multishell.setTitle(multishell.getCurrent(), 'Help')
UI:configure('Help', ...)
local files = { }
for _,f in pairs(fs.list('/rom/help')) do
for _,f in pairs(help.topics()) do
table.insert(files, { name = f })
end
local page = UI.Page({
labelText = UI.Text({
y = 2,
x = 3,
local page = UI.Page {
labelText = UI.Text {
x = 3, y = 2,
value = 'Search',
}),
filter = UI.TextEntry({
y = 2,
x = 10,
width = UI.term.width - 13,
},
filter = UI.TextEntry {
x = 10, y = 2, ex = -3,
limit = 32,
}),
grid = UI.ScrollingGrid({
},
grid = UI.ScrollingGrid {
y = 4,
height = UI.term.height - 4,
values = files,
columns = {
{ heading = 'Name', key = 'name', width = 12 },
{ heading = 'Name', key = 'name' },
},
sortColumn = 'name',
}),
statusBar = UI.StatusBar(),
accelerators = {
q = 'quit',
},
})
accelerators = {
q = 'quit',
enter = 'grid_select',
},
}
local function showHelp(name)
UI.term:reset()
shell.run('help ' .. name)
print('Press enter to return')
repeat
os.pullEvent('key')
local _, k = os.pullEvent('key_up')
until k == keys.enter
end
@ -52,18 +49,13 @@ function page:eventHandler(event)
if event.type == 'quit' then
Event.exitPullEvents()
elseif event.type == 'key' and event.key == 'enter' then
elseif event.type == 'grid_select' then
if self.grid:getSelected() then
showHelp(self.grid:getSelected().name)
self:setFocus(self.filter)
self:draw()
end
elseif event.type == 'grid_select' then
showHelp(event.selected.name)
self:setFocus(self.filter)
self:draw()
elseif event.type == 'text_change' then
local text = event.text
if #text == 0 then

View File

@ -15,7 +15,7 @@ local gridColumns = {
}
if UI.term.width >= 30 then
table.insert(gridColumns, { heading = 'Fuel', key = 'fuel' })
table.insert(gridColumns, { heading = 'Fuel', key = 'fuel', width = 5 })
table.insert(gridColumns, { heading = 'Uptime', key = 'uptime' })
end

View File

@ -94,8 +94,8 @@ local systemPage = UI.Page {
},
selectable = false,
columns = {
{ key = 'name', width = 12 },
{ key = 'value', width = UI.term.width - 15 },
{ key = 'name', width = 12 },
{ key = 'value' },
},
},
},

View File

@ -53,7 +53,7 @@ function shell.run(...)
if path then
tProgramStack[#tProgramStack + 1] = path
local oldTitle
if multishell and multishell.getTitle then
oldTitle = multishell.getTitle(multishell.getCurrent())
multishell.setTitle(multishell.getCurrent(), fs.getName(path))
@ -67,11 +67,9 @@ function shell.run(...)
else
result, err = Util.run(env, path, unpack(args))
end
tProgramStack[#tProgramStack] = nil
if multishell and multishell.getTitle then
local title = 'shell'
if #tProgramStack > 0 then
title = fs.getName(tProgramStack[#tProgramStack])
end
multishell.setTitle(multishell.getCurrent(), oldTitle or 'shell')
end
@ -257,6 +255,7 @@ if #tArgs > 0 then
if not fn then
error(err)
end
tProgramStack[#tProgramStack + 1] = path
return fn(table.unpack(args))
end

View File

@ -231,7 +231,15 @@
icon = "\030f\031f \03131\0308\031f \030f\031d2\
\030f\031f \031d2\03131\0308\031f \030f\03131\
\030f\03131\0308\031f \030f\03131\031e3",
run = "http://pastebin.com/raw/nsKrHTbN",
run = "https://pastebin.com/raw/nsKrHTbN",
},
[ "48d6857f6b2869d031f463b13aa34df47e18c548" ] = {
title = "Breakout",
category = "Games",
icon = "\0301\031f \0309 \030c \030b \030e \030c \0306 \
\030 \031f \
\030 \031f \0300 \0310 ",
run = "https://pastebin.com/raw/LTRYaSKt",
},
[ "8d59207c8a84153b3e9f035cc3b6ec7a23671323" ] = {
title = "Micropaint",