From 43c86c263ba80f5647bd9a6caf797edfa0ae6764 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Thu, 11 Jul 2019 10:36:17 -0600 Subject: [PATCH] upper/lowercase transformations for TextEntry --- sys/apps/Help.lua | 1 + sys/modules/opus/ui/components/TextEntry.lua | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sys/apps/Help.lua b/sys/apps/Help.lua index abb6099..72b5308 100644 --- a/sys/apps/Help.lua +++ b/sys/apps/Help.lua @@ -21,6 +21,7 @@ local page = UI.Page { filter = UI.TextEntry { x = 10, y = 2, ex = -3, limit = 32, + transform = 'lowercase', }, grid = UI.ScrollingGrid { y = 4, diff --git a/sys/modules/opus/ui/components/TextEntry.lua b/sys/modules/opus/ui/components/TextEntry.lua index 512f668..09631ef 100644 --- a/sys/modules/opus/ui/components/TextEntry.lua +++ b/sys/modules/opus/ui/components/TextEntry.lua @@ -5,6 +5,8 @@ local Util = require('opus.util') local colors = _G.colors local _rep = string.rep +local _lower = string.lower +local _upper = string.upper UI.TextEntry = class(UI.Window) UI.TextEntry.defaults = { @@ -104,12 +106,21 @@ function UI.TextEntry:focus() end end +function UI.TextEntry:_transform(text) + if self.transform == 'lowercase' then + return _lower(text) + elseif self.transform == 'uppercase' then + return _upper(text) + end + return text +end + function UI.TextEntry:eventHandler(event) local text = self.value self.entry.value = tostring(text) if event.ie and self.entry:process(event.ie) then if self.entry.textChanged then - self.value = self.entry.value + self.value = self:_transform(self.entry.value) self:draw() if text ~= self.value then self:emit({ type = 'text_change', text = self.value, element = self })