can now use named colors
This commit is contained in:
@@ -1,39 +1,6 @@
|
||||
local class = require('opus.class')
|
||||
local UI = require('opus.ui')
|
||||
|
||||
local colors = _G.colors
|
||||
local _rep = string.rep
|
||||
local _sub = string.sub
|
||||
|
||||
-- For manipulating text in a fixed width string
|
||||
local SB = class()
|
||||
function SB:init(width)
|
||||
self.width = width
|
||||
self.buf = _rep(' ', width)
|
||||
end
|
||||
function SB:insert(x, str, width)
|
||||
if x < 1 then
|
||||
x = self.width + x + 1
|
||||
end
|
||||
width = width or #str
|
||||
if x + width - 1 > self.width then
|
||||
width = self.width - x
|
||||
end
|
||||
if width > 0 then
|
||||
self.buf = _sub(self.buf, 1, x - 1) .. _sub(str, 1, width) .. _sub(self.buf, x + width)
|
||||
end
|
||||
end
|
||||
function SB:fill(x, ch, width)
|
||||
width = width or self.width - x + 1
|
||||
self:insert(x, _rep(ch, width))
|
||||
end
|
||||
function SB:center(str)
|
||||
self:insert(math.max(1, math.ceil((self.width - #str + 1) / 2)), str)
|
||||
end
|
||||
function SB:get()
|
||||
return self.buf
|
||||
end
|
||||
|
||||
UI.TitleBar = class(UI.Window)
|
||||
UI.TitleBar.defaults = {
|
||||
UIElement = 'TitleBar',
|
||||
@@ -43,15 +10,11 @@ UI.TitleBar.defaults = {
|
||||
closeInd = UI.extChars and '\215' or '*',
|
||||
}
|
||||
function UI.TitleBar:draw()
|
||||
local sb = SB(self.width)
|
||||
sb:fill(2, self.frameChar, sb.width - 3)
|
||||
sb:center(string.format(' %s ', self.title))
|
||||
self:fillArea(2, 1, self.width - 2, 1, self.frameChar)
|
||||
self:centeredWrite(1, string.format(' %s ', self.title))
|
||||
if self.previousPage or self.event then
|
||||
sb:insert(-1, self.closeInd)
|
||||
else
|
||||
sb:insert(-2, self.frameChar)
|
||||
self:write(self.width - 1, 1, ' ' .. self.closeInd)
|
||||
end
|
||||
self:write(1, 1, sb:get())
|
||||
end
|
||||
|
||||
function UI.TitleBar:eventHandler(event)
|
||||
@@ -78,7 +41,7 @@ function UI.TitleBar:eventHandler(event)
|
||||
self.parent:reposition(self.parent.x, self.anchor.oy + event.dy, self.width, self.anchor.h - d)
|
||||
end
|
||||
|
||||
else --if self.moveable then
|
||||
elseif self.moveable then
|
||||
local d = event.dy
|
||||
if self.anchor.oy + d > 0 and self.anchor.oy + d <= self.parent.parent.height then
|
||||
self.parent:move(self.anchor.ox + event.dx, self.anchor.oy + event.dy)
|
||||
@@ -91,9 +54,9 @@ function UI.TitleBar.example()
|
||||
return UI.Window {
|
||||
win1 = UI.Window {
|
||||
x = 9, y = 2, ex = -7, ey = -3,
|
||||
backgroundColor = colors.green,
|
||||
backgroundColor = 'green',
|
||||
titleBar = UI.TitleBar {
|
||||
title = 'test', moveable = true,
|
||||
title = 'A really, really, really long title', moveable = true,
|
||||
},
|
||||
button1 = UI.Button {
|
||||
x = 2, y = 3,
|
||||
@@ -105,9 +68,10 @@ function UI.TitleBar.example()
|
||||
},
|
||||
win2 = UI.Window {
|
||||
x = 7, y = 3, ex = -9, ey = -2,
|
||||
backgroundColor = colors.orange,
|
||||
backgroundColor = 'orange',
|
||||
titleBar = UI.TitleBar {
|
||||
title = 'test', moveable = true,
|
||||
event = 'none',
|
||||
},
|
||||
button1 = UI.Button {
|
||||
x = 2, y = 3,
|
||||
|
||||
Reference in New Issue
Block a user