mirror of
https://github.com/kepler155c/opus
synced 2025-01-29 08:34:46 +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 {
|
filter = UI.TextEntry {
|
||||||
x = 10, y = 2, ex = -3,
|
x = 10, y = 2, ex = -3,
|
||||||
limit = 32,
|
limit = 32,
|
||||||
|
transform = 'lowercase',
|
||||||
},
|
},
|
||||||
grid = UI.ScrollingGrid {
|
grid = UI.ScrollingGrid {
|
||||||
y = 4,
|
y = 4,
|
||||||
|
@ -5,6 +5,8 @@ local Util = require('opus.util')
|
|||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local _rep = string.rep
|
local _rep = string.rep
|
||||||
|
local _lower = string.lower
|
||||||
|
local _upper = string.upper
|
||||||
|
|
||||||
UI.TextEntry = class(UI.Window)
|
UI.TextEntry = class(UI.Window)
|
||||||
UI.TextEntry.defaults = {
|
UI.TextEntry.defaults = {
|
||||||
@ -104,12 +106,21 @@ function UI.TextEntry:focus()
|
|||||||
end
|
end
|
||||||
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)
|
function UI.TextEntry:eventHandler(event)
|
||||||
local text = self.value
|
local text = self.value
|
||||||
self.entry.value = tostring(text)
|
self.entry.value = tostring(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
|
||||||
self.value = self.entry.value
|
self.value = self:_transform(self.entry.value)
|
||||||
self:draw()
|
self:draw()
|
||||||
if text ~= self.value then
|
if text ~= self.value then
|
||||||
self:emit({ type = 'text_change', text = self.value, element = self })
|
self:emit({ type = 'text_change', text = self.value, element = self })
|
||||||
|
Loading…
Reference in New Issue
Block a user