minor cleanup

This commit is contained in:
kepler155c@gmail.com
2020-05-30 20:05:53 -06:00
parent b6f439e8dc
commit 2105799524
9 changed files with 104 additions and 13 deletions

View File

@@ -277,6 +277,79 @@ function Terminal.window(parent, sx, sy, w, h, isVisible)
return parent
end
function win.writeX(sText)
-- expect(1, sText, "string", "number")
local nLinesPrinted = 0
local function newLine()
if cy + 1 <= win.canvas.height then
cx, cy = 1, cy + 1
else
cx, cy = 1, win.canvas.height
win.scroll(1)
end
nLinesPrinted = nLinesPrinted + 1
end
-- Print the line with proper word wrapping
sText = tostring(sText)
while #sText > 0 do
local whitespace = string.match(sText, "^[ \t]+")
if whitespace then
-- Print whitespace
win.write(whitespace)
sText = string.sub(sText, #whitespace + 1)
end
local newline = string.match(sText, "^\n")
if newline then
-- Print newlines
newLine()
sText = string.sub(sText, 2)
end
local text = string.match(sText, "^[^ \t\n]+")
if text then
sText = string.sub(sText, #text + 1)
if #text > win.canvas.width then
-- Print a multiline word
while #text > 0 do
if cx > win.canvas.width then
newLine()
end
win.write(text)
text = string.sub(text, win.canvas.width - cx + 2)
end
else
-- Print a word normally
if cx + #text - 1 > win.canvas.width then
newLine()
end
win.write(text)
end
end
end
return nLinesPrinted
end
function win.print(...)
local vis = isVisible
isVisible = false
local nLinesPrinted = 0
local nLimit = select("#", ...)
for n = 1, nLimit do
local s = tostring(select(n, ...))
if n < nLimit then
s = s .. "\t"
end
nLinesPrinted = nLinesPrinted + win.writeX(s)
end
nLinesPrinted = nLinesPrinted + win.writeX("\n")
isVisible = vis
update()
return nLinesPrinted
end
win.canvas:clear()
return win

View File

@@ -763,7 +763,7 @@ function UI.Window:fillArea(x, y, width, height, fillChar, bg, fg)
end
end
UI.Window.docs.write = [[write(NUMBER x, NUMBER y, String text, opt COLOR bg, opt COLOR fg)
UI.Window.docs.write = [[write(NUMBER x, NUMBER y, STRING text, opt COLOR bg, opt COLOR fg)
Write text to the canvas.
If colors are not specified, the colors from the base class will be used.
If the base class does not have colors defined, colors will be inherited from the parent container.]]

View File

@@ -7,8 +7,6 @@ UI.TabBar.defaults = {
UIElement = 'TabBar',
buttonClass = 'TabBarMenuItem',
backgroundColor = 'black',
selectedBackgroundColor = 'primary',
unselectedBackgroundColor = 'tertiary',
}
function UI.TabBar:enable()
UI.MenuBar.enable(self)

View File

@@ -5,15 +5,16 @@ UI.TabBarMenuItem = class(UI.Button)
UI.TabBarMenuItem.defaults = {
UIElement = 'TabBarMenuItem',
event = 'tab_select',
textInactiveColor = 'lightGray',
}
function UI.TabBarMenuItem:draw()
if self.selected then
self.backgroundColor = self:getProperty('selectedBackgroundColor')
self.backgroundFocusColor = self.backgroundColor
self.textColor = self:getProperty('selectedTextColor')
else
self.backgroundColor = self:getProperty('unselectedBackgroundColor')
self.backgroundFocusColor = self.backgroundColor
self.textColor = self:getProperty('unselectedTextColor')
end
UI.Button.draw(self)
end

View File

@@ -6,6 +6,10 @@ UI.Tabs = class(UI.Window)
UI.Tabs.docs = { }
UI.Tabs.defaults = {
UIElement = 'Tabs',
selectedBackgroundColor = 'primary',
unselectedBackgroundColor = 'tertiary',
unselectedTextColor = 'lightGray',
selectedTextColor = 'black',
}
function UI.Tabs:postInit()
self:add(self)