UI inspector
This commit is contained in:
@@ -64,3 +64,23 @@ function UI.Button:eventHandler(event)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function UI.Button.example()
|
||||
return UI.Window {
|
||||
button1 = UI.Button {
|
||||
x = 2, y = 2,
|
||||
text = 'Press',
|
||||
},
|
||||
button2 = UI.Button {
|
||||
x = 2, y = 4,
|
||||
backgroundColor = colors.green,
|
||||
event = 'custom_event',
|
||||
},
|
||||
button3 = UI.Button {
|
||||
x = 12, y = 2,
|
||||
height = 5,
|
||||
event = 'big_event',
|
||||
text = 'large button'
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
54
sys/modules/opus/ui/components/CheckboxGrid.lua
Normal file
54
sys/modules/opus/ui/components/CheckboxGrid.lua
Normal file
@@ -0,0 +1,54 @@
|
||||
local class = require('opus.class')
|
||||
local UI = require('opus.ui')
|
||||
|
||||
local function safeValue(v)
|
||||
local t = type(v)
|
||||
if t == 'string' or t == 'number' then
|
||||
return v
|
||||
end
|
||||
return tostring(v)
|
||||
end
|
||||
|
||||
UI.CheckboxGrid = class(UI.Grid)
|
||||
UI.CheckboxGrid.defaults = {
|
||||
UIElement = 'CheckboxGrid',
|
||||
checkedKey = 'checked',
|
||||
accelerators = {
|
||||
space = 'grid_toggle',
|
||||
},
|
||||
}
|
||||
function UI.CheckboxGrid:drawRow(sb, row, focused, bg, fg)
|
||||
local ind = focused and self.focusIndicator or ' '
|
||||
|
||||
for _,col in pairs(self.columns) do
|
||||
sb:write(ind .. safeValue(row[col.key] or ''),
|
||||
col.cw + 1,
|
||||
col.align,
|
||||
col.backgroundColor or bg,
|
||||
col.textColor or fg)
|
||||
ind = ' '
|
||||
end
|
||||
end
|
||||
|
||||
function UI.CheckboxGrid:eventHandler(event)
|
||||
if event.type == 'key_enter' and self.selected then
|
||||
self.selected.checked = not self.selected.checked
|
||||
self:draw()
|
||||
self:emit({ type = 'grid_check', checked = self.selected, element = self })
|
||||
else
|
||||
return UI.Grid.eventHandler(self, event)
|
||||
end
|
||||
end
|
||||
|
||||
function UI.CheckboxGrid.example()
|
||||
return UI.CheckboxGrid {
|
||||
values = {
|
||||
{ checked = false, name = 'unchecked' },
|
||||
{ checked = true, name = 'checked' },
|
||||
},
|
||||
columns = {
|
||||
{ heading = 'Checked', key = 'checked' },
|
||||
{ heading = 'Data', key = 'name', }
|
||||
},
|
||||
}
|
||||
end
|
||||
@@ -87,3 +87,19 @@ function UI.Tabs:eventHandler(event)
|
||||
tab:draw()
|
||||
end
|
||||
end
|
||||
|
||||
function UI.Tabs.example()
|
||||
return UI.Tabs {
|
||||
[1] = UI.Tab {
|
||||
tabTitle = 'tab1',
|
||||
entry = UI.TextEntry { y = 3, shadowText = 'text' },
|
||||
},
|
||||
[2] = UI.Tab {
|
||||
tabTitle = 'tab2',
|
||||
button = UI.Button { y = 3 },
|
||||
},
|
||||
[3] = UI.Tab {
|
||||
tabTitle = 'tab3',
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
@@ -34,3 +34,9 @@ function UI.TextArea:draw()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function UI.TextArea.example()
|
||||
return UI.TextArea {
|
||||
value = 'sample text\nabc'
|
||||
}
|
||||
end
|
||||
@@ -134,3 +134,35 @@ function UI.TextEntry:eventHandler(event)
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function UI.TextEntry.example()
|
||||
return UI.Window {
|
||||
text = UI.TextEntry {
|
||||
x = 2, y = 2,
|
||||
width = 12,
|
||||
limit = 36,
|
||||
shadowText = 'normal',
|
||||
},
|
||||
upper = UI.TextEntry {
|
||||
x = 2, y = 3,
|
||||
width = 12,
|
||||
limit = 36,
|
||||
shadowText = 'upper',
|
||||
transform = 'uppercase',
|
||||
},
|
||||
lower = UI.TextEntry {
|
||||
x = 2, y = 4,
|
||||
width = 12,
|
||||
limit = 36,
|
||||
shadowText = 'lower',
|
||||
transform = 'lowercase',
|
||||
},
|
||||
number = UI.TextEntry {
|
||||
x = 2, y = 5,
|
||||
width = 12,
|
||||
limit = 36,
|
||||
transform = 'number',
|
||||
shadowText = 'number',
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user