cleanup + theme editor
This commit is contained in:
@@ -165,7 +165,7 @@ function input:translate(event, code, p1, p2)
|
||||
self.mch = 'mouse_up'
|
||||
self.mfired = input:toCode(self.mch, 255)
|
||||
end
|
||||
_syslog(self.mfired)
|
||||
|
||||
return {
|
||||
code = self.mfired,
|
||||
button = code,
|
||||
|
||||
@@ -209,6 +209,15 @@ end
|
||||
|
||||
function Manager:generateTheme(filename)
|
||||
local t = { }
|
||||
|
||||
local function getName(d)
|
||||
for c, n in pairs(colors) do
|
||||
if n == d then
|
||||
return 'colors.' .. c
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for k,v in pairs(self) do
|
||||
if type(v) == 'table' then
|
||||
if v._preload then
|
||||
@@ -221,17 +230,17 @@ function Manager:generateTheme(filename)
|
||||
if not t[k] then
|
||||
t[k] = { }
|
||||
end
|
||||
for c, n in pairs(colors) do
|
||||
if n == d then
|
||||
t[k][p] = 'colors.' .. c
|
||||
break
|
||||
end
|
||||
end
|
||||
t[k][p] = getName(d)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
t.colors = {
|
||||
primary = getName(self.colors.primary),
|
||||
secondary = getName(self.colors.secondary),
|
||||
tertiary = getName(self.colors.tertiary),
|
||||
}
|
||||
Util.writeFile(filename, textutils.serialize(t):gsub('(")', ''))
|
||||
end
|
||||
|
||||
@@ -409,8 +418,8 @@ end
|
||||
|
||||
Manager.colors = {
|
||||
primary = colors.cyan,
|
||||
secondary = colors.blue,
|
||||
tertiary = colors.blue,
|
||||
secondary = colors.lightGray,
|
||||
tertiary = colors.gray,
|
||||
}
|
||||
|
||||
Manager.exitPullEvents = Event.exitPullEvents
|
||||
@@ -652,7 +661,7 @@ function UI.Window:setCursorPos(x, y)
|
||||
end
|
||||
|
||||
function UI.Window:setCursorBlink(blink)
|
||||
self.parent:setCursorBlink(blink)
|
||||
self.cursorBlink = blink
|
||||
end
|
||||
|
||||
UI.Window.docs.draw = [[draw(VOID)
|
||||
@@ -1072,7 +1081,6 @@ end
|
||||
|
||||
function UI.Device:setCursorBlink(blink)
|
||||
self.cursorBlink = blink
|
||||
self.device.setCursorBlink(blink)
|
||||
end
|
||||
|
||||
function UI.Device:setTextScale(textScale)
|
||||
@@ -1130,9 +1138,7 @@ function UI.Device:sync()
|
||||
local transitions = self.effectsEnabled and self.transitions
|
||||
self.transitions = nil
|
||||
|
||||
if self:getCursorBlink() then
|
||||
self.device.setCursorBlink(false)
|
||||
end
|
||||
self.device.setCursorBlink(false)
|
||||
|
||||
if transitions then
|
||||
self:runTransitions(transitions)
|
||||
@@ -1182,6 +1188,7 @@ end
|
||||
loadComponents()
|
||||
UI:loadTheme('usr/config/ui.theme')
|
||||
Util.merge(UI.Window.defaults, UI.theme.Window)
|
||||
Util.merge(UI.colors, UI.theme.colors)
|
||||
UI:setDefaultDevice(UI.Device({ device = term.current() }))
|
||||
|
||||
return UI
|
||||
|
||||
@@ -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
|
||||
|
||||
18
sys/modules/opus/ui/components/FlatButton.lua
Normal file
18
sys/modules/opus/ui/components/FlatButton.lua
Normal 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
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user