color rework + cleanup

This commit is contained in:
kepler155c@gmail.com
2020-04-16 23:13:19 -06:00
parent 3e41996b9b
commit 9d2a76f4ea
28 changed files with 364 additions and 238 deletions

View File

@@ -7,8 +7,7 @@ UI.Dialog = class(UI.SlideOut)
UI.Dialog.defaults = {
UIElement = 'Dialog',
height = 7,
textColor = colors.black,
backgroundColor = colors.white,
noFill = true,
okEvent ='dialog_ok',
cancelEvent = 'dialog_cancel',
}
@@ -17,19 +16,6 @@ function UI.Dialog:postInit()
self.titleBar = UI.TitleBar({ event = self.cancelEvent, title = self.title })
end
function UI.Dialog:show(...)
local canvas = self.parent
self.oldPalette = canvas.palette
canvas:applyPalette(self.darkPalette)
UI.SlideOut.show(self, ...)
end
function UI.Dialog:hide(...)
self.parent.palette = self.oldPalette
UI.SlideOut.hide(self, ...)
self.parent:draw()
end
function UI.Dialog:eventHandler(event)
if event.type == 'dialog_cancel' then
self:hide()

View File

@@ -1,4 +1,5 @@
local class = require('opus.class')
local Event = require('opus.event')
local Terminal = require('opus.terminal')
local UI = require('opus.ui')
@@ -19,10 +20,16 @@ function UI.Embedded:layout()
UI.Window.layout(self)
if not self.win then
local t
function self.render()
self:sync()
if self.focused then
self:setCursorPos(self.win.getCursorPos())
if not t then
t = Event.onTimeout(0, function()
t = nil
if self.focused then
self:setCursorPos(self.win.getCursorPos())
end
self:sync()
end)
end
end
self.win = Terminal.window(UI.term.device, self.x, self.y, self.width, self.height, false)
@@ -68,7 +75,6 @@ function UI.Embedded:eventHandler(event)
end
function UI.Embedded.example()
local Event = require('opus.event')
local Util = require('opus.util')
local term = _G.term

View File

@@ -93,7 +93,8 @@ function UI.MenuBar.example()
return UI.MenuBar {
buttons = {
{ text = 'Choice1', event = 'event1' },
{ text = 'Choice2', event = 'event2' },
{ text = 'Choice2', event = 'event2', inactive = true },
{ text = 'Choice3', event = 'event3' },
}
}
end

View File

@@ -5,4 +5,5 @@ UI.MenuItem = class(UI.FlatButton)
UI.MenuItem.defaults = {
UIElement = 'MenuItem',
noPadding = false,
textInactiveColor = colors.gray,
}

View File

@@ -20,7 +20,7 @@ UI.Page.defaults = {
textColor = colors.white,
}
function UI.Page:postInit()
self.parent = self.parent or UI.defaultDevice
self.parent = self.parent or UI.term
self.__target = self
end

View File

@@ -22,6 +22,9 @@ function UI.ScrollBar:draw()
self:clear()
-- ...
self:write(1, 1, ' ', view.fill)
if view.totalHeight > view.height then
local maxScroll = view.totalHeight - view.height
local percent = view.offsetY / maxScroll

View File

@@ -29,6 +29,7 @@ function UI.ScrollingGrid:getViewArea()
height = self.pageSize, -- viewable height
totalHeight = Util.size(self.values), -- total height
offsetY = self.scrollOffset, -- scroll offset
fill = not self.disableHeader and self.headerBackgroundColor,
}
end

View File

@@ -6,7 +6,7 @@ UI.TabBar = class(UI.MenuBar)
UI.TabBar.defaults = {
UIElement = 'TabBar',
buttonClass = 'TabBarMenuItem',
backgroundColor = UI.colors.tertiary,
backgroundColor = colors.black,
selectedBackgroundColor = UI.colors.primary,
unselectedBackgroundColor = UI.colors.tertiary,
}
@@ -32,7 +32,7 @@ function UI.TabBar:eventHandler(event)
self:emit({ type = 'tab_change', current = si, last = pi, tab = selected })
end
end
UI.MenuBar.draw(self)
self:draw(self)
end
return UI.MenuBar.eventHandler(self, event)
end

View File

@@ -5,6 +5,7 @@ UI.TabBarMenuItem = class(UI.Button)
UI.TabBarMenuItem.defaults = {
UIElement = 'TabBarMenuItem',
event = 'tab_select',
textInactiveColor = colors.lightGray,
}
function UI.TabBarMenuItem:draw()
if self.selected then

View File

@@ -117,5 +117,9 @@ function UI.Tabs.example()
index = 3,
tabTitle = 'tab3',
},
enable = function(self)
UI.Tabs.enable(self)
self:setActive(self.tab3, false)
end,
}
end

View File

@@ -20,7 +20,6 @@ end
function UI.TextArea:draw()
self:clear()
self.cursorX, self.cursorY = 1, 1
self:print(self.value)
self:drawChildren()
end

View File

@@ -47,11 +47,18 @@ function UI.Viewport:setScrollPosition(offy, offx) -- argh - reverse
end
end
function UI.Viewport:write(x, y, text, bg, tc)
function UI.Viewport:blit(x, y, text, bg, fg)
if y > #self.lines then
self:resizeBuffer(self.width, y)
end
return UI.Window.write(self, x, y, text, bg, tc)
return UI.Window.blit(self, x, y, text, bg, fg)
end
function UI.Viewport:write(x, y, text, bg, fg)
if y > #self.lines then
self:resizeBuffer(self.width, y)
end
return UI.Window.write(self, x, y, text, bg, fg)
end
function UI.Viewport:setViewHeight(h)