Ui enhancements 2.0 (#31)
* canvas overhaul * minor tweaks * list mode for overview * bugfixes + tweaks for editor 2.0 * minor tweaks * more editor work * refactor + new transitions * use layout() where appropriate and cleanup * mouse triple click + textEntry scroll ind * cleanup * cleanup + theme editor * color rework + cleanup * changes for deprecated ui methods * can now use named colors
This commit was merged in pull request #31.
This commit is contained in:
@@ -2,32 +2,30 @@ local class = require('opus.class')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local colors = _G.colors
|
||||
|
||||
UI.Button = class(UI.Window)
|
||||
UI.Button.defaults = {
|
||||
UIElement = 'Button',
|
||||
text = 'button',
|
||||
backgroundColor = colors.lightGray,
|
||||
backgroundFocusColor = colors.gray,
|
||||
textFocusColor = colors.white,
|
||||
textInactiveColor = colors.gray,
|
||||
textColor = colors.black,
|
||||
backgroundColor = 'lightGray',
|
||||
backgroundFocusColor = 'gray',
|
||||
textFocusColor = 'white',
|
||||
textInactiveColor = 'gray',
|
||||
textColor = 'black',
|
||||
centered = true,
|
||||
height = 1,
|
||||
focusIndicator = ' ',
|
||||
event = 'button_press',
|
||||
accelerators = {
|
||||
space = 'button_activate',
|
||||
[ ' ' ] = 'button_activate',
|
||||
enter = 'button_activate',
|
||||
mouse_click = 'button_activate',
|
||||
}
|
||||
}
|
||||
function UI.Button:setParent()
|
||||
function UI.Button:layout()
|
||||
if not self.width and not self.ex then
|
||||
self.width = #self.text + 2
|
||||
self.width = self.noPadding and #self.text or #self.text + 2
|
||||
end
|
||||
UI.Window.setParent(self)
|
||||
UI.Window.layout(self)
|
||||
end
|
||||
|
||||
function UI.Button:draw()
|
||||
@@ -35,13 +33,13 @@ function UI.Button:draw()
|
||||
local bg = self.backgroundColor
|
||||
local ind = ' '
|
||||
if self.focused then
|
||||
bg = self.backgroundFocusColor
|
||||
fg = self.textFocusColor
|
||||
bg = self:getProperty('backgroundFocusColor')
|
||||
fg = self:getProperty('textFocusColor')
|
||||
ind = self.focusIndicator
|
||||
elseif self.inactive then
|
||||
fg = self.textInactiveColor
|
||||
fg = self:getProperty('textInactiveColor')
|
||||
end
|
||||
local text = ind .. self.text .. ' '
|
||||
local text = self.noPadding and self.text or ind .. self.text .. ' '
|
||||
if self.centered then
|
||||
self:clear(bg)
|
||||
self:centeredWrite(1 + math.floor(self.height / 2), text, bg, fg)
|
||||
@@ -59,7 +57,7 @@ end
|
||||
|
||||
function UI.Button:eventHandler(event)
|
||||
if event.type == 'button_activate' then
|
||||
self:emit({ type = self.event, button = self })
|
||||
self:emit({ type = self.event, button = self, element = self })
|
||||
return true
|
||||
end
|
||||
return false
|
||||
@@ -73,7 +71,7 @@ function UI.Button.example()
|
||||
},
|
||||
button2 = UI.Button {
|
||||
x = 2, y = 4,
|
||||
backgroundColor = colors.green,
|
||||
backgroundColor = 'green',
|
||||
event = 'custom_event',
|
||||
},
|
||||
button3 = UI.Button {
|
||||
|
||||
Reference in New Issue
Block a user