This commit is contained in:
kepler155c@gmail.com
2019-11-16 22:12:02 -07:00
parent efa1a5bbf5
commit a3a8c64be8
18 changed files with 123 additions and 46 deletions

View File

@@ -21,21 +21,20 @@ UI.Checkbox.defaults = {
mouse_click = 'checkbox_toggle',
}
}
UI.Checkbox.inherits = {
labelBackgroundColor = 'backgroundColor',
}
function UI.Checkbox:postInit()
self.width = self.label and #self.label + 4 or 3
end
function UI.Checkbox:draw()
local bg = self.backgroundColor
if self.focused then
bg = self.backgroundFocusColor
end
if type(self.value) == 'string' then
self.value = nil -- TODO: fix form
end
local text = string.format('[%s]', not self.value and ' ' or self.checkedIndicator)
local bg = self.focused and self.backgroundFocusColor or self.backgroundColor
local x = 1
if self.label then
self:write(1, 1, self.label)
self:write(1, 1, self.label, self.labelBackgroundColor)
x = #self.label + 2
end
self:write(x, 1, text, bg)
self:write(x, 1, self.leftMarker, self.backgroundColor, self.textColor)
self:write(x + 1, 1, not self.value and ' ' or self.checkedIndicator, bg)
self:write(x + 2, 1, self.rightMarker, self.backgroundColor, self.textColor)
@@ -46,11 +45,12 @@ function UI.Checkbox:focus()
end
function UI.Checkbox:setValue(v)
self.value = v
self.value = not not v
end
function UI.Checkbox:reset()
self.value = false
self:draw()
end
function UI.Checkbox:eventHandler(event)
@@ -63,7 +63,13 @@ function UI.Checkbox:eventHandler(event)
end
function UI.Checkbox.example()
return UI.Checkbox {
x = 2, y = 2,
return UI.Window {
ex1 = UI.Checkbox {
label = 'test',
x = 2, y = 2,
},
ex2 = UI.Checkbox {
x = 2, y = 4,
},
}
end

View File

@@ -3,7 +3,6 @@ local UI = require('opus.ui')
local colors = _G.colors
--[[-- DropMenuItem --]]--
UI.DropMenuItem = class(UI.Button)
UI.DropMenuItem.defaults = {
UIElement = 'DropMenuItem',

View File

@@ -1,7 +1,6 @@
local class = require('opus.class')
local UI = require('opus.ui')
--[[-- Menu --]]--
UI.Menu = class(UI.Grid)
UI.Menu.defaults = {
UIElement = 'Menu',

View File

@@ -51,6 +51,7 @@ function UI.MenuBar:addButtons(buttons)
x = self.lastx,
width = #(button.text or 'button') + self.spacing,
centered = false,
backgroundColor = self.backgroundColor,
}
self.lastx = self.lastx + buttonProperties.width
UI:mergeProperties(buttonProperties, button)

View File

@@ -3,7 +3,6 @@ local UI = require('opus.ui')
local colors = _G.colors
--[[-- MenuItem --]]--
UI.MenuItem = class(UI.Button)
UI.MenuItem.defaults = {
UIElement = 'MenuItem',

View File

@@ -92,25 +92,26 @@ function UI.Notification:eventHandler(event)
end
function UI.Notification.example()
return UI.Window {
notify = UI.Notification {
return UI.ActiveLayer {
notify1 = UI.Notification {
anchor = 'top',
},
notify2 = UI.Notification { },
button1 = UI.Button {
x = 2, y = 3,
text = 'success',
text = 'example 1',
event = 'test_success',
},
button2 = UI.Button {
x = 2, y = 5,
text = 'error',
text = 'example 2',
event = 'test_error',
},
eventHandler = function (self, event)
if event.type == 'test_success' then
self.notify:success('Example text')
self.notify1:success('Example text')
elseif event.type == 'test_error' then
self.notify:error('Example text', 0)
self.notify2:error('Example text', 0)
end
end,
}

View File

@@ -2,7 +2,6 @@ local class = require('opus.class')
local UI = require('opus.ui')
local Util = require('opus.util')
--[[-- ScrollingGrid --]]--
UI.ScrollingGrid = class(UI.Grid)
UI.ScrollingGrid.defaults = {
UIElement = 'ScrollingGrid',

View File

@@ -1,7 +1,6 @@
local class = require('opus.class')
local UI = require('opus.ui')
--[[-- SlideOut --]]--
UI.SlideOut = class(UI.Window)
UI.SlideOut.defaults = {
UIElement = 'SlideOut',
@@ -62,9 +61,12 @@ end
function UI.SlideOut.example()
-- for the transistion to work properly, the parent must have a canvas
return UI.ActiveLayer {
y = 1, -- TODO: if this is set to anything greater than 1, then
-- the layer is not rendered in the correct location
-- a general issue in canvas layers
backgroundColor = colors.cyan,
button = UI.Button {
x = 2, y = 2,
x = 2, y = 5,
text = 'show',
},
slideOut = UI.SlideOut {

View File

@@ -1,12 +1,9 @@
local class = require('opus.class')
local UI = require('opus.ui')
local colors = _G.colors
UI.Tab = class(UI.ActiveLayer)
UI.Tab.defaults = {
UIElement = 'Tab',
tabTitle = 'tab',
backgroundColor = colors.cyan,
y = 2,
}

View File

@@ -2,13 +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 = colors.cyan,
}
UI.TabBar.inherits = {
selectedBackgroundColor = 'backgroundColor',
}
function UI.TabBar:enable()
UI.MenuBar.enable(self)

View File

@@ -3,7 +3,6 @@ local UI = require('opus.ui')
local colors = _G.colors
--[[-- TabBarMenuItem --]]--
UI.TabBarMenuItem = class(UI.Button)
UI.TabBarMenuItem.defaults = {
UIElement = 'TabBarMenuItem',
@@ -13,6 +12,9 @@ UI.TabBarMenuItem.defaults = {
unselectedBackgroundColor = colors.lightGray,
backgroundColor = colors.lightGray,
}
UI.TabBarMenuItem.inherits = {
selectedBackgroundColor = 'selectedBackgroundColor',
}
function UI.TabBarMenuItem:draw()
if self.selected then
self.backgroundColor = self.selectedBackgroundColor

View File

@@ -3,6 +3,7 @@ local UI = require('opus.ui')
local Util = require('opus.util')
UI.Tabs = class(UI.Window)
UI.Tabs.docs = { }
UI.Tabs.defaults = {
UIElement = 'Tabs',
}
@@ -37,6 +38,8 @@ function UI.Tabs:add(children)
end
end
UI.Tabs.docs.selectTab = [[selectTab(TAB)
Make to the passed tab active.]]
function UI.Tabs:selectTab(tab)
local menuItem = Util.find(self.tabBar.children, 'tabUid', tab.uid)
if menuItem then

View File

@@ -1,7 +1,6 @@
local class = require('opus.class')
local UI = require('opus.ui')
--[[-- TextArea --]]--
UI.TextArea = class(UI.Viewport)
UI.TextArea.defaults = {
UIElement = 'TextArea',

View File

@@ -16,6 +16,7 @@ local function transform(directive)
end
UI.TextEntry = class(UI.Window)
UI.TextEntry.docs = { }
UI.TextEntry.defaults = {
UIElement = 'TextEntry',
--value = '',
@@ -92,6 +93,8 @@ function UI.TextEntry:draw()
end
end
UI.TextEntry.docs.reset = [[reset()
Clears the value and resets the cursor.]]
function UI.TextEntry:reset()
self.entry:reset()
self.value = nil--''

View File

@@ -3,7 +3,6 @@ local UI = require('opus.ui')
local colors = _G.colors
--[[-- Viewport --]]--
UI.Viewport = class(UI.Window)
UI.Viewport.defaults = {
UIElement = 'Viewport',