cleanup + theme editor

This commit is contained in:
kepler155c@gmail.com
2020-04-14 14:12:04 -06:00
parent 9eeec8719c
commit 3e41996b9b
16 changed files with 199 additions and 95 deletions

View File

@@ -21,6 +21,9 @@ function UI.Embedded:layout()
if not self.win then
function self.render()
self:sync()
if self.focused then
self:setCursorPos(self.win.getCursorPos())
end
end
self.win = Terminal.window(UI.term.device, self.x, self.y, self.width, self.height, false)
self.win.canvas = self
@@ -38,6 +41,9 @@ end
function UI.Embedded:focus()
-- allow scrolling
if self.focused then
self:setCursorBlink(self.win.getCursorBlink())
end
end
function UI.Embedded:enable()
@@ -67,6 +73,7 @@ function UI.Embedded.example()
local term = _G.term
return UI.Embedded {
y = 2, x = 2, ex = -2, ey = -2,
enable = function (self)
UI.Embedded.enable(self)
Event.addRoutine(function()
@@ -75,10 +82,11 @@ function UI.Embedded.example()
term.redirect(oterm)
end)
end,
eventHandler = function(_, event)
eventHandler = function(self, event)
if event.type == 'key' then
return true
end
return UI.Embedded.eventHandler(self, event)
end
}
end

View File

@@ -0,0 +1,18 @@
local class = require('opus.class')
local UI = require('opus.ui')
local colors = _G.colors
UI.FlatButton = class(UI.Button)
UI.FlatButton.defaults = {
UIElement = 'FlatButton',
textColor = colors.black,
textFocusColor = colors.white,
noPadding = true,
}
function UI.FlatButton:setParent()
self.backgroundColor = self.parent:getProperty('backgroundColor')
self.backgroundFocusColor = self.backgroundColor
UI.Button.setParent(self)
end

View File

@@ -60,7 +60,7 @@ UI.Grid.defaults = {
textSelectedColor = colors.white,
backgroundColor = colors.black,
backgroundSelectedColor = colors.gray,
headerBackgroundColor = UI.colors.tertiary,
headerBackgroundColor = UI.colors.primary,
headerTextColor = colors.white,
headerSortColor = colors.yellow,
unfocusedTextSelectedColor = colors.white,

View File

@@ -8,7 +8,7 @@ UI.MenuBar.defaults = {
UIElement = 'MenuBar',
buttons = { },
height = 1,
backgroundColor = colors.lightGray,
backgroundColor = UI.colors.secondary,
textColor = colors.black,
spacing = 2,
lastx = 1,

View File

@@ -1,11 +1,8 @@
local class = require('opus.class')
local UI = require('opus.ui')
local colors = _G.colors
UI.MenuItem = class(UI.Button)
UI.MenuItem = class(UI.FlatButton)
UI.MenuItem.defaults = {
UIElement = 'MenuItem',
textFocusColor = colors.white,
backgroundFocusColor = colors.lightGray,
noPadding = false,
}

View File

@@ -24,17 +24,10 @@ function UI.Page:postInit()
self.__target = self
end
function UI.Page:enable()
UI.Window.enable(self)
if not self.focused or not self.focused.enabled then
self:focusFirst()
end
end
function UI.Page:sync()
if self.enabled then
self:checkFocus()
self.parent:setCursorBlink(self.focused and self.focused.cursorBlink)
self.parent:sync()
end
end
@@ -137,15 +130,7 @@ end
function UI.Page:checkFocus()
if not self.focused or not self.focused.enabled then
local el = self.__target
while el do
local focusables = el:getFocusables()
if focusables[1] then
self:setFocus(focusables[1])
break
end
el = el.parent
end
self.__target:focusFirst()
end
end

View File

@@ -2,14 +2,13 @@ local class = require('opus.class')
local UI = require('opus.ui')
local Util = require('opus.util')
local colors = _G.colors
UI.TabBar = class(UI.MenuBar)
UI.TabBar.defaults = {
UIElement = 'TabBar',
buttonClass = 'TabBarMenuItem',
selectedBackgroundColor = UI.colors.secondary,
unselectedBackgroundColor = colors.lightGray,
backgroundColor = UI.colors.tertiary,
selectedBackgroundColor = UI.colors.primary,
unselectedBackgroundColor = UI.colors.tertiary,
}
function UI.TabBar:enable()
UI.MenuBar.enable(self)

View File

@@ -28,6 +28,7 @@ UI.TextEntry.defaults = {
backgroundFocusColor = colors.black, --lightGray,
height = 1,
limit = 6,
cursorBlink = true,
accelerators = {
[ 'control-c' ] = 'copy',
}
@@ -114,11 +115,6 @@ end
function UI.TextEntry:focus()
self:draw()
if self.focused then
self:setCursorBlink(true)
else
self:setCursorBlink(false)
end
end
function UI.TextEntry:eventHandler(event)