remove debug output

pull/2028/head
union2find 8 years ago
parent 9ea56827dc
commit 3d89b27e59

@ -48,16 +48,13 @@ if Device.isTouchDevice() then
end end
function InputText:onTapTextBox(arg, ges) function InputText:onTapTextBox(arg, ges)
print("TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT Text widget", self.text_widget)
if self.parent.onSwitchFocus then if self.parent.onSwitchFocus then
self.parent:onSwitchFocus(self) self.parent:onSwitchFocus(self)
else else
local x = ges.pos.x - self.dimen.x - self.bordersize - self.padding local x = ges.pos.x - self.dimen.x - self.bordersize - self.padding
local y = ges.pos.y - self.dimen.y - self.bordersize - self.padding local y = ges.pos.y - self.dimen.y - self.bordersize - self.padding
if x > 0 and y > 0 then if x > 0 and y > 0 then
print("Move to ", x, y)
self.charpos = self.text_widget:moveCursor(x, y) self.charpos = self.text_widget:moveCursor(x, y)
print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX charpos now at", self.charpos)
UIManager:setDirty(self.parent, function() UIManager:setDirty(self.parent, function()
return "ui", self[1].dimen return "ui", self[1].dimen
end) end)
@ -78,7 +75,6 @@ end
function InputText:initTextBox(text) function InputText:initTextBox(text)
self.text = text self.text = text
util.splitToChars(text, self.charlist) util.splitToChars(text, self.charlist)
print("XXXXXX", self.charlist, #self.charlist)
if self.charpos == nil then if self.charpos == nil then
self.charpos = #self.charlist + 1 self.charpos = #self.charlist + 1
end end
@ -112,7 +108,6 @@ function InputText:initTextBox(text)
height = self.height, height = self.height,
} }
end end
print("IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII InputText: text_widget", self.text_widget)
self[1] = FrameContainer:new{ self[1] = FrameContainer:new{
bordersize = self.bordersize, bordersize = self.bordersize,
padding = self.padding, padding = self.padding,

@ -29,7 +29,6 @@ local ScrollTextWidget = InputContainer:new{
} }
function ScrollTextWidget:init() function ScrollTextWidget:init()
print("####################################################### ScrollTextWidget width", self.width)
self.text_widget = TextBoxWidget:new{ self.text_widget = TextBoxWidget:new{
text = self.text, text = self.text,
charlist = self.charlist, charlist = self.charlist,

@ -29,7 +29,6 @@ local TextBoxWidget = Widget:new{
} }
function TextBoxWidget:init() function TextBoxWidget:init()
print("XXXXXXXXXXXXXXXXXXXX TextBoxWidget:init() ", self.height)
local line_height = (1 + self.line_height) * self.face.size local line_height = (1 + self.line_height) * self.face.size
local font_height = self.face.size local font_height = self.face.size
self.cursor_line = LineWidget:new{ self.cursor_line = LineWidget:new{
@ -38,27 +37,15 @@ function TextBoxWidget:init()
h = line_height, h = line_height,
} }
} }
print("########################### Rendering text", self.text)
print("########################### charlist", self.charlist)
self:_evalCharWidthList() self:_evalCharWidthList()
print("########################### char_width_list", self.char_width_list)
for k, v in ipairs(self.char_width_list) do
print("############################", k, v.char, v.width)
end
self:_splitCharWidthList() self:_splitCharWidthList()
print("######################### Text Widget vetical_string_list", self.vertical_string_list)
for k, v in ipairs(self.vertical_string_list) do
print("############################", k, v.text, v.offset)
end
if self.height == nil then if self.height == nil then
self:_renderText(1, #self.vertical_string_list) self:_renderText(1, #self.vertical_string_list)
else else
print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ scorlling widget", self:getVisLineCount())
self:_renderText(1, self:getVisLineCount()) self:_renderText(1, self:getVisLineCount())
end end
if self.editable then if self.editable then
x, y = self:_findCharPos() x, y = self:_findCharPos()
print("####################### Drawing cursor at ", x, y, self.charpos)
self.cursor_line:paintTo(self._bb, x, y) self.cursor_line:paintTo(self._bb, x, y)
end end
self.dimen = Geom:new(self:getSize()) self.dimen = Geom:new(self:getSize())
@ -107,16 +94,12 @@ function TextBoxWidget:_splitCharWidthList()
break break
end end
cur_line_width = cur_line_width + self.char_width_list[idx].width cur_line_width = cur_line_width + self.char_width_list[idx].width
print("++++++++", cur_line_width, idx, self.char_width_list[idx].width, self.char_width_list[idx].char)
if cur_line_width > self.width then break else idx = idx + 1 end if cur_line_width > self.width then break else idx = idx + 1 end
end end
print("xxxxxxx Beofre ", cur_line_width, offset, idx, "++++++++++ self.width", self.width)
if cur_line_width <= self.width then -- a hard newline or end of string if cur_line_width <= self.width then -- a hard newline or end of string
cur_line_text = table.concat(self.charlist, "", offset, idx - 1) cur_line_text = table.concat(self.charlist, "", offset, idx - 1)
print("XXX nature end", cur_line_text, "?????", #self.charlist)
else else
-- Backtrack the string until the length fit into one line. -- Backtrack the string until the length fit into one line.
print("XXX overbounded")
local c = self.char_width_list[idx].char local c = self.char_width_list[idx].char
if util.isSplitable(c) then if util.isSplitable(c) then
cur_line_text = table.concat(self.charlist, "", offset, idx - 1) cur_line_text = table.concat(self.charlist, "", offset, idx - 1)
@ -125,7 +108,6 @@ function TextBoxWidget:_splitCharWidthList()
local adjusted_idx = idx local adjusted_idx = idx
local adjusted_width = cur_line_width local adjusted_width = cur_line_width
repeat repeat
print("<----", self.char_width_list[adjusted_idx])
adjusted_width = adjusted_width - self.char_width_list[adjusted_idx].width adjusted_width = adjusted_width - self.char_width_list[adjusted_idx].width
adjusted_idx = adjusted_idx - 1 adjusted_idx = adjusted_idx - 1
c = self.char_width_list[adjusted_idx].char c = self.char_width_list[adjusted_idx].char
@ -133,11 +115,9 @@ function TextBoxWidget:_splitCharWidthList()
if adjusted_idx == offset then -- a very long english word ocuppying more than one line if adjusted_idx == offset then -- a very long english word ocuppying more than one line
cur_line_text = table.concat(self.charlist, "", offset, idx - 1) cur_line_text = table.concat(self.charlist, "", offset, idx - 1)
cur_line_width = cur_line_width - self.char_width_list[idx].width cur_line_width = cur_line_width - self.char_width_list[idx].width
print("!!!!! A very long word cut to ", cur_line_text)
else else
cur_line_text = table.concat(self.charlist, "", offset, adjusted_idx) cur_line_text = table.concat(self.charlist, "", offset, adjusted_idx)
cur_line_width = adjusted_line_width cur_line_width = adjusted_line_width
print("now the text is ", cur_line_text, "(", adjusted_line_width, ")", offset, adjusted_idx)
idx = adjusted_idx + 1 idx = adjusted_idx + 1
end end
end -- endif util.isSplitable(c) end -- endif util.isSplitable(c)
@ -153,7 +133,6 @@ function TextBoxWidget:_splitCharWidthList()
end end
function TextBoxWidget:_renderText(start_row_idx, end_row_idx) function TextBoxWidget:_renderText(start_row_idx, end_row_idx)
print("@@@@@@@@@@@@@@@@@@@", start_row_idx, end_row_idx)
local font_height = self.face.size local font_height = self.face.size
local line_height = (1 + self.line_height) * font_height local line_height = (1 + self.line_height) * font_height
if start_row_idx < 1 then start_row_idx = 1 end if start_row_idx < 1 then start_row_idx = 1 end
@ -162,10 +141,8 @@ function TextBoxWidget:_renderText(start_row_idx, end_row_idx)
local h = line_height * row_count local h = line_height * row_count
self._bb = Blitbuffer.new(self.width, h) self._bb = Blitbuffer.new(self.width, h)
self._bb:fill(Blitbuffer.COLOR_WHITE) self._bb:fill(Blitbuffer.COLOR_WHITE)
print("XXXX rendering height", h, line_height, start_row_idx, end_row_idx)
local y = font_height local y = font_height
for i = start_row_idx, end_row_idx do for i = start_row_idx, end_row_idx do
print("printing row", i, self.vertical_string_list[i].text)
local line = self.vertical_string_list[i] local line = self.vertical_string_list[i]
local pen_x = self.alignment == "center" and (self.width - line.width)/2 or 0 local pen_x = self.alignment == "center" and (self.width - line.width)/2 or 0
--@TODO Don't use kerning for monospaced fonts. (houqp) --@TODO Don't use kerning for monospaced fonts. (houqp)
@ -182,24 +159,18 @@ end
-- Return the position of the cursor corresponding to `self.charpos`, -- Return the position of the cursor corresponding to `self.charpos`,
-- Be aware of virtual line number of the scorllTextWidget. -- Be aware of virtual line number of the scorllTextWidget.
function TextBoxWidget:_findCharPos() function TextBoxWidget:_findCharPos()
print("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF findCharPos", self.charpos)
-- Find the line number. -- Find the line number.
local ln = self.height == nil and 1 or self.virtual_line_num local ln = self.height == nil and 1 or self.virtual_line_num
while ln + 1 <= #self.vertical_string_list do while ln + 1 <= #self.vertical_string_list do
if self.vertical_string_list[ln + 1].offset > self.charpos then break else ln = ln + 1 end if self.vertical_string_list[ln + 1].offset > self.charpos then break else ln = ln + 1 end
print("XXXXXX", ln, self.vertical_string_list[ln].offset, self.charpos)
end end
print("^^^^^^^^^^^^locating at real line", ln, "virutal line", ln - self.virtual_line_num + 1)
-- Find the offset at the current line. -- Find the offset at the current line.
local x = 0 local x = 0
print("self.char_width_list", self.char_width_list)
local offset = self.vertical_string_list[ln].offset local offset = self.vertical_string_list[ln].offset
while offset < self.charpos do while offset < self.charpos do
print("+++", offset, self.charpos)
x = x + self.char_width_list[offset].width x = x + self.char_width_list[offset].width
offset = offset + 1 offset = offset + 1
end end
print("^^^^^^^^^^^locating at width ", x)
local line_height = (1 + self.line_height) * self.face.size local line_height = (1 + self.line_height) * self.face.size
return x + 1, (ln - 1) * line_height -- offset `x` by 1 to avoid overlap return x + 1, (ln - 1) * line_height -- offset `x` by 1 to avoid overlap
end end
@ -213,28 +184,21 @@ function TextBoxWidget:moveCursor(x, y)
local ln = self.height == nil and 1 or self.virtual_line_num local ln = self.height == nil and 1 or self.virtual_line_num
ln = ln + math.ceil(y / line_height) - 1 ln = ln + math.ceil(y / line_height) - 1
if ln > #self.vertical_string_list then if ln > #self.vertical_string_list then
print("&&&&&&&&&&&& Press some empty area....")
ln = #self.vertical_string_list ln = #self.vertical_string_list
x = self.width x = self.width
end end
print("Real line number", ln, "virtual line number", ln - self.virtual_line_num + 1)
local offset = self.vertical_string_list[ln].offset local offset = self.vertical_string_list[ln].offset
local idx = ln == #self.vertical_string_list and #self.char_width_list or self.vertical_string_list[ln + 1].offset - 1 local idx = ln == #self.vertical_string_list and #self.char_width_list or self.vertical_string_list[ln + 1].offset - 1
print("XXXX", offset, idx)
while offset <= idx do while offset <= idx do
w = w + self.char_width_list[offset].width w = w + self.char_width_list[offset].width
print("XXXXX", offset, idx, w)
if w > x then break else offset = offset + 1 end if w > x then break else offset = offset + 1 end
end end
print("XXXX After loop", offset, idx, w)
if w > x then if w > x then
local w_prev = w - self.char_width_list[offset].width local w_prev = w - self.char_width_list[offset].width
if x - w_prev < w - x then -- the previous one is more closer if x - w_prev < w - x then -- the previous one is more closer
w = w_prev w = w_prev
end end
end end
print("$$$$$$$$$$$$$$$$$$$$$$$$ adjusted", w)
print("painting", w, ln - self.virtual_line_num + 1)
self:free() self:free()
self:_renderText(1, #self.vertical_string_list) self:_renderText(1, #self.vertical_string_list)
self.cursor_line:paintTo(self._bb, w + 1, (ln - self.virtual_line_num) * line_height) self.cursor_line:paintTo(self._bb, w + 1, (ln - self.virtual_line_num) * line_height)

@ -106,7 +106,6 @@ function util.splitToChars(text, tab)
for k, v in pairs(tab) do for k, v in pairs(tab) do
tab[k] = nil tab[k] = nil
end end
print("table", tab)
local prevcharcode, charcode = 0 local prevcharcode, charcode = 0
for uchar in string.gfind(text, "([%z\1-\127\194-\244][\128-\191]*)") do for uchar in string.gfind(text, "([%z\1-\127\194-\244][\128-\191]*)") do
charcode = BaseUtil.utf8charcode(uchar) charcode = BaseUtil.utf8charcode(uchar)
@ -115,7 +114,6 @@ function util.splitToChars(text, tab)
end end
prevcharcode = charcode prevcharcode = charcode
end end
print(table.concat(tab, ","))
end end
-- Test whether a string could be separated by a char for multi-line rendering -- Test whether a string could be separated by a char for multi-line rendering

Loading…
Cancel
Save