mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
TextWidget: small refactoring, better handle max_width (#5503)
Lots of code was doing some renderText calls to get the size of some text string, and truncate it to some width if needed, with or without an added ellipsis, before instantiating a TextWidget with that tweaked text string. This PR fixes/adds some properties and methods to TextWidget so all that can be done by it. It makes the calling code simpler, as they don't need to use RenderText directly. (Additionally, when we go at using Harfbuzz for text rendering, we'll just have to update or replace textwidget.lua without the need to update any higher level code.) Also: - RenderText: removed the space added by truncateTextByWidth after the ellipsis, as it doesn't feel needed, and break right alignment of the ellipsis with other texts. - KeyValuePage: fix some subtle size and alignment issues. - NumberPickerWidget: fix font size (provided font size was not used)
This commit is contained in:
@@ -12,7 +12,6 @@ local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local LineWidget = require("ui/widget/linewidget")
|
||||
local NumberPickerWidget = require("ui/widget/numberpickerwidget")
|
||||
local OverlapGroup = require("ui/widget/overlapgroup")
|
||||
local RenderText = require("ui/rendertext")
|
||||
local Size = require("ui/size")
|
||||
local TextBoxWidget = require("ui/widget/textboxwidget")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
@@ -90,24 +89,16 @@ function SpinWidget:update()
|
||||
|
||||
local close_button = CloseButton:new{ window = self, padding_top = Size.margin.title, }
|
||||
local btn_width = close_button:getSize().w + Size.padding.default * 2
|
||||
local title_txt_width = RenderText:sizeUtf8Text(
|
||||
0, self.width, self.title_face, self.title_text).x
|
||||
local show_title_txt
|
||||
if self.width < (title_txt_width + btn_width) then
|
||||
show_title_txt = RenderText:truncateTextByWidth(
|
||||
self.title_text, self.title_face, self.width - btn_width)
|
||||
else
|
||||
show_title_txt = self.title_text
|
||||
end
|
||||
|
||||
local value_title = FrameContainer:new{
|
||||
padding = Size.padding.default,
|
||||
margin = Size.margin.title,
|
||||
bordersize = 0,
|
||||
TextWidget:new{
|
||||
text = show_title_txt,
|
||||
text = self.title_text,
|
||||
max_width = self.width - btn_width,
|
||||
face = self.title_face,
|
||||
bold = true,
|
||||
width = self.width,
|
||||
},
|
||||
}
|
||||
local value_line = LineWidget:new{
|
||||
|
||||
Reference in New Issue
Block a user