diff --git a/frontend/ui/widget/dictquicklookup.lua b/frontend/ui/widget/dictquicklookup.lua index d1c23ddf6..92c219638 100644 --- a/frontend/ui/widget/dictquicklookup.lua +++ b/frontend/ui/widget/dictquicklookup.lua @@ -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, }, } diff --git a/frontend/ui/widget/textboxwidget.lua b/frontend/ui/widget/textboxwidget.lua index c06d6a96c..205f61d32 100644 --- a/frontend/ui/widget/textboxwidget.lua +++ b/frontend/ui/widget/textboxwidget.lua @@ -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)