mirror of
https://github.com/kepler155c/opus
synced 2025-01-03 20:30:28 +00:00
TextEntry number transform
This commit is contained in:
parent
e084c733f8
commit
cd2024d7ce
@ -11,7 +11,7 @@ local _upper = string.upper
|
|||||||
UI.TextEntry = class(UI.Window)
|
UI.TextEntry = class(UI.Window)
|
||||||
UI.TextEntry.defaults = {
|
UI.TextEntry.defaults = {
|
||||||
UIElement = 'TextEntry',
|
UIElement = 'TextEntry',
|
||||||
value = '',
|
--value = '',
|
||||||
shadowText = '',
|
shadowText = '',
|
||||||
focused = false,
|
focused = false,
|
||||||
textColor = colors.white,
|
textColor = colors.white,
|
||||||
@ -25,7 +25,6 @@ UI.TextEntry.defaults = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
function UI.TextEntry:postInit()
|
function UI.TextEntry:postInit()
|
||||||
self.value = tostring(self.value) -- is this right ? shouldnt raw numbers be allowed
|
|
||||||
self.entry = entry({ limit = self.limit, offset = 2 })
|
self.entry = entry({ limit = self.limit, offset = 2 })
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ function UI.TextEntry:layout()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function UI.TextEntry:setValue(value)
|
function UI.TextEntry:setValue(value)
|
||||||
self.value = value or ''
|
self.value = value --or ''
|
||||||
self.entry:unmark()
|
self.entry:unmark()
|
||||||
self.entry.value = tostring(value)
|
self.entry.value = tostring(value)
|
||||||
self.entry:updateScroll()
|
self.entry:updateScroll()
|
||||||
@ -43,7 +42,7 @@ end
|
|||||||
|
|
||||||
function UI.TextEntry:setPosition(pos)
|
function UI.TextEntry:setPosition(pos)
|
||||||
self.entry.pos = pos
|
self.entry.pos = pos
|
||||||
self.entry.value = tostring(self.value)
|
self.entry.value = tostring(self.value or '')
|
||||||
self.entry:updateScroll()
|
self.entry:updateScroll()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -54,7 +53,7 @@ function UI.TextEntry:draw()
|
|||||||
bg = self.backgroundFocusColor
|
bg = self.backgroundFocusColor
|
||||||
end
|
end
|
||||||
|
|
||||||
local text = tostring(self.value)
|
local text = tostring(self.value or '')
|
||||||
if #text > 0 then
|
if #text > 0 then
|
||||||
if self.entry.scroll > 0 then
|
if self.entry.scroll > 0 then
|
||||||
text = text:sub(1 + self.entry.scroll)
|
text = text:sub(1 + self.entry.scroll)
|
||||||
@ -88,7 +87,7 @@ end
|
|||||||
|
|
||||||
function UI.TextEntry:reset()
|
function UI.TextEntry:reset()
|
||||||
self.entry:reset()
|
self.entry:reset()
|
||||||
self.value = ''
|
self.value = nil--''
|
||||||
self:draw()
|
self:draw()
|
||||||
self:updateCursor()
|
self:updateCursor()
|
||||||
end
|
end
|
||||||
@ -111,13 +110,15 @@ function UI.TextEntry:_transform(text)
|
|||||||
return _lower(text)
|
return _lower(text)
|
||||||
elseif self.transform == 'uppercase' then
|
elseif self.transform == 'uppercase' then
|
||||||
return _upper(text)
|
return _upper(text)
|
||||||
|
elseif self.transform == 'number' then
|
||||||
|
return tonumber(text) --or 0
|
||||||
end
|
end
|
||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.TextEntry:eventHandler(event)
|
function UI.TextEntry:eventHandler(event)
|
||||||
local text = self.value
|
local text = self.value --or ''
|
||||||
self.entry.value = tostring(text)
|
self.entry.value = tostring(text or '')
|
||||||
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:_transform(self.entry.value)
|
self.value = self:_transform(self.entry.value)
|
||||||
|
Loading…
Reference in New Issue
Block a user