Merge pull request #438 from chrox/master

process new line symbol in TextBoxWidget
pull/440/head
Paulo Matias 11 years ago
commit 9262b17bab

@ -30,7 +30,7 @@ local DictQuickLookup = InputContainer:new{
definition = nil,
dict_index = 1,
title_face = Font:getFace("tfont", 22),
word_face = Font:getFace("tfont", 20),
word_face = Font:getFace("tfont", 22),
content_face = Font:getFace("cfont", 20),
width = nil,
height = nil,
@ -108,7 +108,7 @@ function DictQuickLookup:update()
text = self.definition,
face = self.content_face,
width = self.width,
height = self.height*0.6,
height = self.height*0.7,
dialog = self,
},
}

@ -40,14 +40,21 @@ function TextBoxWidget:_wrapGreedyAlg(h_list)
for k,w in ipairs(h_list) do
cur_line_width = cur_line_width + w.width
if cur_line_width <= self.width then
table.insert(cur_line, w)
else
if w.word == "\n" then
if cur_line_width > 0 then
-- hard line break
table.insert(v_list, cur_line)
cur_line = {}
cur_line_width = 0
end
elseif cur_line_width > self.width then
-- wrap to next line
table.insert(v_list, cur_line)
cur_line = {}
cur_line_width = w.width
table.insert(cur_line, w)
else
table.insert(cur_line, w)
end
end
-- handle last line
@ -101,15 +108,19 @@ function TextBoxWidget:_getVerticalList(alg)
end
-- build horizontal list
local h_list = {}
for words in self.text:gmatch("[\32-\127\192-\255]+[\128-\191]*") do
for word in words:gsplit("%s+", true) do
for w in word:gsplit("%p+", true) do
local word_box = {}
word_box.word = w
word_box.width = RenderText:sizeUtf8Text(0, Screen:getWidth(), self.face, w, true).x
table.insert(h_list, word_box)
local line_count = 0
for line in self.text:gsplit("\n", true) do
for words in line:gmatch("[\32-\127\192-\255]+[\128-\191]*") do
for word in words:gsplit("%s+", true) do
for w in word:gsplit("%p+", true) do
local word_box = {}
word_box.word = w
word_box.width = RenderText:sizeUtf8Text(0, Screen:getWidth(), self.face, w, true).x
table.insert(h_list, word_box)
end
end
end
if line:sub(-1) == "\n" then table.insert(h_list, {word = '\n', width = 0}) end
end
-- @TODO check alg here 25.04 2012 (houqp)

Loading…
Cancel
Save