mirror of
https://github.com/kepler155c/opus
synced 2025-01-16 18:32:52 +00:00
upper/lowercase transformations for TextEntry
This commit is contained in:
parent
e9559165a4
commit
43c86c263b
@ -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,
|
||||
|
@ -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 })
|
||||
|
Loading…
Reference in New Issue
Block a user