From 14057c2bf9a06ee5f2aebeeda28d3e39df890af8 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Thu, 14 Nov 2019 15:43:20 -0700 Subject: [PATCH] moar ui examples --- sys/modules/opus/ui/components/Embedded.lua | 23 ++++++++++++++ .../opus/ui/components/Notification.lua | 2 +- sys/modules/opus/ui/components/SlideOut.lua | 26 ++++++++++++++++ sys/modules/opus/ui/components/Slider.lua | 3 +- sys/modules/opus/ui/components/StatusBar.lua | 17 ++++++++++ sys/modules/opus/ui/components/TextEntry.lua | 7 ++++- sys/modules/opus/ui/components/Wizard.lua | 31 +++++++++++++++++++ 7 files changed, 105 insertions(+), 4 deletions(-) diff --git a/sys/modules/opus/ui/components/Embedded.lua b/sys/modules/opus/ui/components/Embedded.lua index fcdee82..e15df33 100644 --- a/sys/modules/opus/ui/components/Embedded.lua +++ b/sys/modules/opus/ui/components/Embedded.lua @@ -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 diff --git a/sys/modules/opus/ui/components/Notification.lua b/sys/modules/opus/ui/components/Notification.lua index bf02256..7b11543 100644 --- a/sys/modules/opus/ui/components/Notification.lua +++ b/sys/modules/opus/ui/components/Notification.lua @@ -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, } diff --git a/sys/modules/opus/ui/components/SlideOut.lua b/sys/modules/opus/ui/components/SlideOut.lua index 37f5e37..c5779dd 100644 --- a/sys/modules/opus/ui/components/SlideOut.lua +++ b/sys/modules/opus/ui/components/SlideOut.lua @@ -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 diff --git a/sys/modules/opus/ui/components/Slider.lua b/sys/modules/opus/ui/components/Slider.lua index 09325b4..9a58cdb 100644 --- a/sys/modules/opus/ui/components/Slider.lua +++ b/sys/modules/opus/ui/components/Slider.lua @@ -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 diff --git a/sys/modules/opus/ui/components/StatusBar.lua b/sys/modules/opus/ui/components/StatusBar.lua index a92c0c2..96a1943 100644 --- a/sys/modules/opus/ui/components/StatusBar.lua +++ b/sys/modules/opus/ui/components/StatusBar.lua @@ -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 diff --git a/sys/modules/opus/ui/components/TextEntry.lua b/sys/modules/opus/ui/components/TextEntry.lua index 75665a6..523208c 100644 --- a/sys/modules/opus/ui/components/TextEntry.lua +++ b/sys/modules/opus/ui/components/TextEntry.lua @@ -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 diff --git a/sys/modules/opus/ui/components/Wizard.lua b/sys/modules/opus/ui/components/Wizard.lua index e6bce7e..549669e 100644 --- a/sys/modules/opus/ui/components/Wizard.lua +++ b/sys/modules/opus/ui/components/Wizard.lua @@ -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