mirror of https://github.com/kepler155c/opus
new checkbox control
This commit is contained in:
parent
c75938bef9
commit
7220b372bd
|
@ -2948,6 +2948,8 @@ UI.Chooser.defaults = {
|
||||||
choices = { },
|
choices = { },
|
||||||
nochoice = 'Select',
|
nochoice = 'Select',
|
||||||
backgroundFocusColor = colors.lightGray,
|
backgroundFocusColor = colors.lightGray,
|
||||||
|
leftIndicator = '<',
|
||||||
|
rightIndicator = '>',
|
||||||
height = 1,
|
height = 1,
|
||||||
}
|
}
|
||||||
function UI.Chooser:setParent()
|
function UI.Chooser:setParent()
|
||||||
|
@ -2973,9 +2975,9 @@ function UI.Chooser:draw()
|
||||||
if choice then
|
if choice then
|
||||||
value = choice.name
|
value = choice.name
|
||||||
end
|
end
|
||||||
self:write(1, 1, '<', bg, colors.black)
|
self:write(1, 1, self.leftIndicator, self.backgroundColor, colors.black)
|
||||||
self:write(2, 1, ' ' .. Util.widthify(tostring(value), self.width-4) .. ' ', bg)
|
self:write(2, 1, ' ' .. Util.widthify(tostring(value), self.width-4) .. ' ', bg)
|
||||||
self:write(self.width, 1, '>', bg, colors.black)
|
self:write(self.width, 1, self.rightIndicator, self.backgroundColor, colors.black)
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.Chooser:focus()
|
function UI.Chooser:focus()
|
||||||
|
@ -3016,6 +3018,57 @@ function UI.Chooser:eventHandler(event)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[-- Chooser --]]--
|
||||||
|
UI.Checkbox = class(UI.Window)
|
||||||
|
UI.Checkbox.defaults = {
|
||||||
|
UIElement = 'Checkbox',
|
||||||
|
nochoice = 'Select',
|
||||||
|
checkedIndicator = 'X',
|
||||||
|
leftMarker = '[',
|
||||||
|
rightMarker = ']',
|
||||||
|
value = false,
|
||||||
|
textColor = colors.white,
|
||||||
|
backgroundColor = colors.black,
|
||||||
|
backgroundFocusColor = colors.lightGray,
|
||||||
|
height = 1,
|
||||||
|
width = 3,
|
||||||
|
accelerators = {
|
||||||
|
space = 'checkbox_toggle',
|
||||||
|
mouse_click = 'checkbox_toggle',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
self:write(1, 1, text, bg)
|
||||||
|
self:write(1, 1, self.leftMarker, self.backgroundColor, self.textColor)
|
||||||
|
self:write(2, 1, not self.value and ' ' or self.checkedIndicator, bg)
|
||||||
|
self:write(3, 1, self.rightMarker, self.backgroundColor, self.textColor)
|
||||||
|
end
|
||||||
|
|
||||||
|
function UI.Checkbox:focus()
|
||||||
|
self:draw()
|
||||||
|
end
|
||||||
|
|
||||||
|
function UI.Checkbox:reset()
|
||||||
|
self.value = false
|
||||||
|
end
|
||||||
|
|
||||||
|
function UI.Checkbox:eventHandler(event)
|
||||||
|
if event.type == 'checkbox_toggle' then
|
||||||
|
self.value = not self.value
|
||||||
|
self:emit({ type = 'checkbox_change', checked = self.value, element = self })
|
||||||
|
self:draw()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--[[-- Text --]]--
|
--[[-- Text --]]--
|
||||||
UI.Text = class(UI.Window)
|
UI.Text = class(UI.Window)
|
||||||
UI.Text.defaults = {
|
UI.Text.defaults = {
|
||||||
|
|
|
@ -8,6 +8,15 @@
|
||||||
Button = {
|
Button = {
|
||||||
--focusIndicator = '\183',
|
--focusIndicator = '\183',
|
||||||
},
|
},
|
||||||
|
Checkbox = {
|
||||||
|
checkedIndicator = '\4',
|
||||||
|
leftMarker = '\124',
|
||||||
|
rightMarker = '\124',
|
||||||
|
},
|
||||||
|
Chooser = {
|
||||||
|
leftIndicator = '\17',
|
||||||
|
rightIndicator = '\16',
|
||||||
|
},
|
||||||
Grid = {
|
Grid = {
|
||||||
focusIndicator = '\183',
|
focusIndicator = '\183',
|
||||||
inverseSortIndicator = '\24',
|
inverseSortIndicator = '\24',
|
||||||
|
|
|
@ -150,11 +150,13 @@ local function sendInfo()
|
||||||
end
|
end
|
||||||
if device.neuralInterface then
|
if device.neuralInterface then
|
||||||
info.status = device.neuralInterface.status
|
info.status = device.neuralInterface.status
|
||||||
if not info.status and device.neuralInterface.getMetaOwner then
|
pcall(function()
|
||||||
info.status = 'health: ' ..
|
if not info.status and device.neuralInterface.getMetaOwner then
|
||||||
math.floor(device.neuralInterface.getMetaOwner().health /
|
info.status = 'health: ' ..
|
||||||
device.neuralInterface.getMetaOwner().maxHealth * 100)
|
math.floor(device.neuralInterface.getMetaOwner().health /
|
||||||
end
|
device.neuralInterface.getMetaOwner().maxHealth * 100)
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
device.wireless_modem.transmit(999, os.getComputerID(), info)
|
device.wireless_modem.transmit(999, os.getComputerID(), info)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue