mirror of https://github.com/kepler155c/opus
moar ui examples
This commit is contained in:
parent
3241326a2f
commit
14057c2bf9
|
@ -74,3 +74,26 @@ end
|
||||||
function UI.Embedded:focus()
|
function UI.Embedded:focus()
|
||||||
-- allow scrolling
|
-- allow scrolling
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UI.Embedded.example()
|
||||||
|
local Event = require('opus.event')
|
||||||
|
local Util = require('opus.util')
|
||||||
|
local term = _G.term
|
||||||
|
|
||||||
|
return UI.Embedded {
|
||||||
|
visible = true,
|
||||||
|
enable = function (self)
|
||||||
|
UI.Embedded.enable(self)
|
||||||
|
Event.addRoutine(function()
|
||||||
|
local oterm = term.redirect(self.win)
|
||||||
|
Util.run(_ENV, '/sys/apps/shell.lua')
|
||||||
|
term.redirect(oterm)
|
||||||
|
end)
|
||||||
|
end,
|
||||||
|
eventHandler = function(_, event)
|
||||||
|
if event.type == 'key' then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
|
@ -110,7 +110,7 @@ function UI.Notification.example()
|
||||||
if event.type == 'test_success' then
|
if event.type == 'test_success' then
|
||||||
self.notify:success('Example text')
|
self.notify:success('Example text')
|
||||||
elseif event.type == 'test_error' then
|
elseif event.type == 'test_error' then
|
||||||
self.notify:error('Example text')
|
self.notify:error('Example text', 0)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,3 +50,29 @@ function UI.SlideOut:eventHandler(event)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UI.SlideOut.example()
|
||||||
|
return UI.Window {
|
||||||
|
button = UI.Button {
|
||||||
|
x = 2, y = 2,
|
||||||
|
text = 'show',
|
||||||
|
},
|
||||||
|
slideOut = UI.SlideOut {
|
||||||
|
backgroundColor = colors.yellow,
|
||||||
|
y = -4, height = 4,
|
||||||
|
button = UI.Button {
|
||||||
|
x = 2, y = 2,
|
||||||
|
text = 'hide',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
eventHandler = function (self, event)
|
||||||
|
if event.type == 'button_press' then
|
||||||
|
if self.slideOut.enabled then
|
||||||
|
self.slideOut:hide()
|
||||||
|
else
|
||||||
|
self.slideOut:show()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
|
@ -49,7 +49,7 @@ function UI.Slider:draw()
|
||||||
i == self.width and self.rightBorder or
|
i == self.width and self.rightBorder or
|
||||||
self.barChar
|
self.barChar
|
||||||
|
|
||||||
table.insert(bar, filler)
|
table.insert(bar, filler)
|
||||||
end
|
end
|
||||||
self:write(1, 1, table.concat(bar), nil, self.barColor)
|
self:write(1, 1, table.concat(bar), nil, self.barColor)
|
||||||
self:write(progress, 1, self.sliderChar, nil, self.focused and self.sliderFocusColor or self.sliderColor)
|
self:write(progress, 1, self.sliderChar, nil, self.focused and self.sliderFocusColor or self.sliderColor)
|
||||||
|
@ -80,6 +80,5 @@ function UI.Slider.example()
|
||||||
return UI.Slider {
|
return UI.Slider {
|
||||||
y = 2, x = 2, ex = -2,
|
y = 2, x = 2, ex = -2,
|
||||||
min = 0, max = 1,
|
min = 0, max = 1,
|
||||||
help = 'Volume setting',
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -96,3 +96,20 @@ function UI.StatusBar:draw()
|
||||||
self:write(1, 1, Util.widthify(s, self.width))
|
self:write(1, 1, Util.widthify(s, self.width))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UI.StatusBar.example()
|
||||||
|
return UI.Window {
|
||||||
|
status1 = UI.StatusBar { values = 'standard' },
|
||||||
|
status2 = UI.StatusBar {
|
||||||
|
ey = -3,
|
||||||
|
columns = {
|
||||||
|
{ key = 'field1' },
|
||||||
|
{ key = 'field2', width = 6 },
|
||||||
|
},
|
||||||
|
values = {
|
||||||
|
field1 = 'test',
|
||||||
|
field2 = '42',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
|
@ -117,9 +117,14 @@ function UI.TextEntry:eventHandler(event)
|
||||||
self.entry.value = text
|
self.entry.value = text
|
||||||
if event.ie and self.entry:process(event.ie) then
|
if event.ie and self.entry:process(event.ie) then
|
||||||
if self.entry.textChanged then
|
if self.entry.textChanged then
|
||||||
|
local changed = self.value ~= self.entry.value
|
||||||
self.value = self.entry.value
|
self.value = self.entry.value
|
||||||
self:draw()
|
self:draw()
|
||||||
self:emit({ type = 'text_change', text = self.value, element = self })
|
if changed then
|
||||||
|
-- we get entry.textChanged when marking is updated
|
||||||
|
-- no need to emit in that case
|
||||||
|
self:emit({ type = 'text_change', text = self.value, element = self })
|
||||||
|
end
|
||||||
elseif self.entry.posChanged then
|
elseif self.entry.posChanged then
|
||||||
self:updateCursor()
|
self:updateCursor()
|
||||||
end
|
end
|
||||||
|
|
|
@ -122,3 +122,34 @@ function UI.Wizard:eventHandler(event)
|
||||||
self:draw()
|
self:draw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UI.Wizard.example()
|
||||||
|
return UI.Wizard {
|
||||||
|
ey = -2,
|
||||||
|
pages = {
|
||||||
|
splash = UI.WizardPage {
|
||||||
|
index = 1,
|
||||||
|
intro = UI.TextArea {
|
||||||
|
inactive = true,
|
||||||
|
x = 3, ex = -3, y = 2, ey = -2,
|
||||||
|
value = 'sample text',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
label = UI.WizardPage {
|
||||||
|
index = 2,
|
||||||
|
intro = UI.TextArea {
|
||||||
|
inactive = true,
|
||||||
|
x = 3, ex = -3, y = 2, ey = -2,
|
||||||
|
value = 'sample more text',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
password = UI.WizardPage {
|
||||||
|
index = 3,
|
||||||
|
text = UI.TextEntry {
|
||||||
|
x = 12, ex = -3, y = 2,
|
||||||
|
shadowText = 'tet',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue