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:
@@ -1,29 +1,25 @@
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
local RenderText = require("ui/rendertext")
|
||||
local Geom = require("ui/geometry")
|
||||
local Screen = require("device").screen
|
||||
|
||||
--[[
|
||||
FixedTextWidget
|
||||
--]]
|
||||
local FixedTextWidget = TextWidget:new{}
|
||||
|
||||
function FixedTextWidget:getSize()
|
||||
local tsize = RenderText:sizeUtf8Text(0, Screen:getWidth(), self.face, self.text, true, self.bold)
|
||||
if tsize.x == 0 then
|
||||
return Geom:new{}
|
||||
end
|
||||
self._length = tsize.x
|
||||
function FixedTextWidget:updateSize()
|
||||
TextWidget.updateSize(self)
|
||||
-- Only difference from TextWidget:
|
||||
-- no vertical padding, baseline is height
|
||||
self._height = self.face.size
|
||||
return Geom:new{
|
||||
w = self._length,
|
||||
h = self._height,
|
||||
}
|
||||
self._baseline_h = self.face.size
|
||||
end
|
||||
|
||||
function FixedTextWidget:paintTo(bb, x, y)
|
||||
RenderText:renderUtf8Text(bb, x, y+self._height, self.face, self.text, true, self.bold,
|
||||
self.fgcolor)
|
||||
function FixedTextWidget:getSize()
|
||||
self:updateSize()
|
||||
if self._length == 0 then
|
||||
return Geom:new{}
|
||||
end
|
||||
return TextWidget.getSize(self)
|
||||
end
|
||||
|
||||
return FixedTextWidget
|
||||
|
||||
Reference in New Issue
Block a user