Reduce sleep screen message's font size to fit one line#13026
Conversation
| if self.shrink_to_fit then | ||
| self:shrinkFontToFit(frame, text_widget, 0.07) | ||
| elseif not self.height then | ||
| self:shrinkFontToFit(frame, text_widget, 0.95) |
There was a problem hiding this comment.
I don't mind moving the code into its own method.
But the 0.07 here feels a bit random in relation to a property name "shrink_to_fit"...
It looks like this makes the infomessage not take more than 0.07 x screen_height - and you hope it will stick on one line (which may not be the case if we provide a smaller font?). Anyway, none of these 2 aims sounds like "shrink to fit".
I guess a more proper way would be to have max_lines = N, and may be you guessing the height taken by N lines of the current font & size - and you would provide max_lines = 1.
There was a problem hiding this comment.
Yes the 7pc is a bit of a guesstimate, it comes from measuring the frame at one line with default font (53px on a 800px screen, that is roughly 6.625%, so 7 to give it some wiggle room). I guess it could be instead of boolean, a number (percentage) at which you cap the size of the frame... regardless of font size or other.
There was a problem hiding this comment.
if not self.height then
if self.max_lines then
max_height = self.max_lines * text_widget:getLineHeight()
else
max_height = screen height * 0.95
end
-- and provide directly that max_height to shrinkFontToFitThere was a problem hiding this comment.
and then, you wouldn't need to separate the code into its own function (as you don't really know what would happen if we call it from elsewhere than from :init() - that a separate function invites us to think we can).
There was a problem hiding this comment.
I took it a slightly different way, I hope you like it...
There was a problem hiding this comment.
I am all for making it simpler if possible, however, I don't like the max_lines implementation since it still needs me to figure out a way to guess then the size for values >2. I'd rather keep it a simple on/off boolean if it's all the same to you.
There was a problem hiding this comment.
it still needs me to figure out a way to guess then the size for values >2
Isn't it just a matter of:
- max_height = math.max(text_widget:getLineHeight(), icon_height) + 2*frame.bordersize + 2*frame.padding + 3
+ max_height = math.max(self.max_lines * text_widget:getLineHeight(), icon_height) + 2*frame.bordersize + 2*frame.padding + 3 There was a problem hiding this comment.
but then we would have to account for all the spacing between the different lines, as I said, I'd rather do it boolean if it's all the same to you.
There was a problem hiding this comment.
What "spacing between the different lines" ? getLineHeight() should return something that is used for all y and h computations, so there's no room/space in between.
if it's all the same to you
Guess it's not all the same to me :) If it's not more complicated to handle a number than a boolean, it will feel more generic and less adhoc.
Even if I don't really see why one would use it with wanting more than 1 line.
There was a problem hiding this comment.
what if I want n = 100? there are a lot more cases to handle there, and as you, yourself said, why would anyone want to use it with anything other than one? it should be all the same to you :)
| local max_height | ||
| if self.cap_height_to_one_line then | ||
| local icon_height = self.show_icon and image_widget:getSize().h or 0 | ||
| -- calculate the size of the frame container when it's only displaying one line, and add a magic number (3) to give it some wiggle room |
There was a problem hiding this comment.
Does KOReader wiggle ?!!! It shouldn't ! If it does, fix that :)
And don't use magic numbers, KOReader should be deterministic, if you need magic, your reality is poor. Fix it !
I believe you shouldn't need any addition - if you need a +1, it's maybe because there's a < somewhere that could be a <= ?
There was a problem hiding this comment.
is not really need it, is just me giving it an extra 3 pixels just in case. I can remove it though.
There was a problem hiding this comment.
what I mean by wiggle room is that if we have a large enough font and the text is aaaa, that would be a smaller value than that of bbbb for example. So add those extra pixels in case something like was the case.
There was a problem hiding this comment.
Yes, remove it. The "just in case" means you're not sure you don't need it. I'd rather you to be sure :)
There was a problem hiding this comment.
that if we have a large enough font and the text is aaaa, that would be a smaller value than that of bbbb for example
This is not the case, the height we get is constant, from the font metrics, a fixed thing - it's not the max of "blackbox/inkbox" of each letter that compose the line.
| _timeout_func = nil, | ||
| width = nil, -- The width of the InfoMessage. Keep it nil to use default value. | ||
| height = nil, -- The height of the InfoMessage. If this field is set, a scrollbar may be shown. | ||
| cap_height_to_one_line = false, -- Attempt to show text in one single line. This setting and height are not to be used conjointly. |
There was a problem hiding this comment.
Feels this is still not a good name.
It explains the how we achieve one line (explanation which is not really needed) and moreover it's wrong (we don't cap the height - which could invoke crop & scroll -, we reduce the font size).
So, single_line or force_one_line.
| local max_height | ||
| if self.force_one_line then | ||
| local icon_height = self.show_icon and image_widget:getSize().h or 0 | ||
| -- calculate the size of the frame container when it's only displaying one line. |
There was a problem hiding this comment.
(If a sentence ends with a dot, it should start with an uppercase.)
| text = screensaver_message, | ||
| readonly = true, | ||
| dismissable = false, | ||
| force_one_line = true, |
There was a problem hiding this comment.
What happens when there's a \n involved?
There was a problem hiding this comment.
Nothing, besides the fact that you get a literal \n as part of the message. What i mean is, \n is not recognised as new line neither pre PR nor post PR.
Edit: i don’t think that the founding fathers intended to have a sleep screen message with multiple lines ;)
There was a problem hiding this comment.
Let's make the question more generic :) What happens if we call InfoMessage with force_one_line=true and a normal multiline message ? Does it go at displaying it with the minimal font size ?
Just curious - as it would be a coder error.
There was a problem hiding this comment.
you cheeky ferrets, may I ask why would anyone so obtusely try and do just that? I mean is like wondering why your feet are wet after taking off your shoes during a storm.
but I understand the sentiment, I imagine it would in fact loop all the way to end of the font size (10 or whatever) and then show it like that. I'll see if I can test it though.
Co-authored-by: David <97603719+Commodore64user@users.noreply.github.com>
Why is there a |
Yes, no one ever envisioned it might be broken on purpose. My point is the same thing applies to every InfoMessage ever. |
|
I'd say its a 100% @Commodore64user oversight. |
|
Well, in any case it's now automatically ignored when it comes across \n. Seems good enough to me. :-) |
|
@poire-z acting like the kid in the classroom that upon agreeing for everyone to take the blame for some mischief, immediately points and accuses the kid whose grandiose free kick broke the classroom window. How was I to know that the emulator had that? ;) I can make the change if you want anyway |
By looking around ? By thinking about the world and not only your little self / use-case ? :) Anyway, let it be - I'm just mentionning all that so my point of view is remembered by the future humanity. |
I only want to Make Kindle Great Again. ;) |

what's new
force_one_lineproperty to theInfoMessageclass to attempt to show text in a single line.InfoMessage:init()function to calculate the maximum height of the widget based on theforce_one_lineproperty, ensuring that the text fits within the specified constraints.force_one_lineproperty to theScreensaver:show()function to ensure the sleep screen message is displayed in a single line.screenshots
before/after
fix #12109
This change is