moar ui examples

This commit is contained in:
kepler155c@gmail.com 2019-11-14 15:43:20 -07:00
parent 3241326a2f
commit 14057c2bf9
7 changed files with 105 additions and 4 deletions

View File

@ -74,3 +74,26 @@ end
function UI.Embedded:focus()
-- allow scrolling
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

View File

@ -110,7 +110,7 @@ function UI.Notification.example()
if event.type == 'test_success' then
self.notify:success('Example text')
elseif event.type == 'test_error' then
self.notify:error('Example text')
self.notify:error('Example text', 0)
end
end,
}

View File

@ -50,3 +50,29 @@ function UI.SlideOut:eventHandler(event)
return true
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

View File

@ -49,7 +49,7 @@ function UI.Slider:draw()
i == self.width and self.rightBorder or
self.barChar
table.insert(bar, filler)
table.insert(bar, filler)
end
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)
@ -80,6 +80,5 @@ function UI.Slider.example()
return UI.Slider {
y = 2, x = 2, ex = -2,
min = 0, max = 1,
help = 'Volume setting',
}
end

View File

@ -96,3 +96,20 @@ function UI.StatusBar:draw()
self:write(1, 1, Util.widthify(s, self.width))
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

View File

@ -117,9 +117,14 @@ function UI.TextEntry:eventHandler(event)
self.entry.value = text
if event.ie and self.entry:process(event.ie) then
if self.entry.textChanged then
local changed = self.value ~= self.entry.value
self.value = self.entry.value
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
self:updateCursor()
end

View File

@ -122,3 +122,34 @@ function UI.Wizard:eventHandler(event)
self:draw()
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