And fix several other bugs introduced in #2028:
1. hint messages are back instead of the "Demo hint"
2. cursor now only presents in the focused inputbox in a multiinput dialog
3. moving cursor now works in multiinput dialog
pull/2106/head
chrox 8 years ago
parent eb2d4e9ede
commit 6b43233c4a

@ -50,15 +50,14 @@ if Device.isTouchDevice() then
function InputText:onTapTextBox(arg, ges)
if self.parent.onSwitchFocus then
self.parent:onSwitchFocus(self)
else
local x = ges.pos.x - self.dimen.x - self.bordersize - self.padding
local y = ges.pos.y - self.dimen.y - self.bordersize - self.padding
if x > 0 and y > 0 then
self.charpos = self.text_widget:moveCursor(x, y)
UIManager:setDirty(self.parent, function()
return "ui", self[1].dimen
end)
end
end
local x = ges.pos.x - self.dimen.x - self.bordersize - self.padding
local y = ges.pos.y - self.dimen.y - self.bordersize - self.padding
if x > 0 and y > 0 then
self.charpos = self.text_widget:moveCursor(x, y)
UIManager:setDirty(self.parent, function()
return "ui", self[1].dimen
end)
end
end
else
@ -84,13 +83,15 @@ function InputText:initTextBox(text)
if self.text_type == "password" and show_text ~= "" then
show_text = self.text:gsub("(.-).", function() return "*" end)
show_text = show_text:gsub("(.)$", function() return self.text:sub(-1) end)
elseif show_text == "" then
show_text = self.hint
end
if self.scroll then
self.text_widget = ScrollTextWidget:new{
text = show_text,
charlist = self.charlist,
charpos = self.charpos,
editable = true,
editable = self.focused,
face = self.face,
fgcolor = fgcolor,
width = self.width,
@ -101,7 +102,7 @@ function InputText:initTextBox(text)
text = show_text,
charlist = self.charlist,
charpos = self.charpos,
editable = true,
editable = self.focused,
face = self.face,
fgcolor = fgcolor,
width = self.width,
@ -136,11 +137,13 @@ end
function InputText:unfocus()
self.focused = false
self.text_widget:unfocus()
self[1].color = Blitbuffer.gray(0.5)
end
function InputText:focus()
self.focused = true
self.text_widget:focus()
self[1].color = Blitbuffer.COLOR_BLACK
end
@ -185,6 +188,7 @@ function InputText:getText()
end
function InputText:setText(text)
self.charpos = nil
self:initTextBox(text)
UIManager:setDirty(self.parent, function()
return "partial", self[1].dimen

@ -72,6 +72,14 @@ function ScrollTextWidget:init()
end
end
function ScrollTextWidget:unfocus()
self.text_widget:unfocus()
end
function ScrollTextWidget:focus()
self.text_widget:focus()
end
function ScrollTextWidget:scrollText(direction)
if direction == 0 then return end
local low, high

@ -61,6 +61,16 @@ function TextBoxWidget:init()
self.dimen = Geom:new(self:getSize())
end
function TextBoxWidget:unfocus()
self.editable = false
self:init()
end
function TextBoxWidget:focus()
self.editable = true
self:init()
end
-- Split `self.text` into `self.charlist` and evaluate the width of each char in it.
function TextBoxWidget:_evalCharWidthList()
if self.charlist == nil then
@ -77,7 +87,7 @@ end
-- Split the text into logical lines to fit into the text box.
function TextBoxWidget:_splitCharWidthList()
self.vertical_string_list = {
{text = "Demo hint", offset = 1, width = 0} -- hint for empty string
{text = self.text, offset = 1, width = 0} -- hint for empty string
}
local idx = 1

Loading…
Cancel
Save