Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upNew algorithm to show items in menu widget #5496
Conversation
local offset_prev = item_name_orig.vertical_string_list[num_lines - 1].offset | ||
text_last_line = table.concat(item_name_orig.charlist, '', offset_prev, offset) |
This comment has been minimized.
This comment has been minimized.
poire-z
Oct 16, 2019
Contributor
One of the things I intend to do is to move that kind of stuff into TextBoxWidget.
It already has a "private" TextBoxWidget:_getLineText(vertical_string)
which does what you do, so I guess it just have to have a "public" TextBoxWidget:getLineText(line_num)
to give you that.
So, not asking you to do it :) This is fine for now.
This comment has been minimized.
This comment has been minimized.
-- try to add chars to better align | ||
while item_name.width > text_size_increase + ellipsis_size and offset < max_offset do |
This comment has been minimized.
This comment has been minimized.
poire-z
Oct 16, 2019
Contributor
What's the reason for this to be needed?
I wondered for a few minutes - but is it just because TextBoxWidget wrap by words, so the last line you keep may be shorter than the textboxwidget width because a wrap happened and a long word has been pushed onto the next line. So, here, you're trying to grab some chars from that long word to put it at end of last line, before the "...", so the "..." touches the screen right border.
Is it that? Is that the only reason for this to be needed and work?
This comment has been minimized.
This comment has been minimized.
-- remove chars when text is too long | ||
while item_name.width <= text_size + ellipsis_size do |
This comment has been minimized.
This comment has been minimized.
poire-z
Oct 16, 2019
Contributor
And the, why does it happen you need to remove chars? (because you added some and made sure they fitted with the ellipsis)?
Or does this happen and is only needed when you actually did not have to add some chars? So, just to get rid of the orignal chars on that last line, to make room for the ellipsis?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Another thing I noticed earlier. koreader/frontend/ui/widget/menu.lua Lines 933 to 936 in bae69c0 I think the same should apply for the multiline main name font size - so that decreasing of font size, in this PR that displays only one line (but not before this PR), might be just a precaution in case the above formulae is a bit wrong and would find out a too large font size. So, we could get rid of the mandatory font size loop in any case. |
This comment has been minimized.
This comment has been minimized.
It's also used in Bookmark.
Yes. I wanted to stay with fixed size, as long as possible. I think it looks prettier than every element looks similar (but it's only my opinion :))
If user want to see more text he/she can always decrease font size in At the end. This is only my propose. If you have better implementation or another idea I don't insist on my solution :) |
This comment has been minimized.
This comment has been minimized.
Oh, right. Seeing more of the text is more useful there :) (But I'm not a heavy bookmarker, so not minding either).
Valid opinion (and it was my argument in #5435 - so I suddently agree with you :)
No better idea (nor any real interest in having one). |
This comment has been minimized.
This comment has been minimized.
While testing bookmarks, I got a reproducible infinite loop (I have to Ctrl-C) with just this PR:
(600x610 emulator, 12 items per page, Font size: 16) |
This comment has been minimized.
This comment has been minimized.
gerhaher
commented
Oct 17, 2019
Yeah, as you said, I (sometimes) use classic, but then always 24 items/page, so I never see the multi-lines. But I guess I find equal font size looks prettier. |
This comment has been minimized.
This comment has been minimized.
Should be fixed now. It was problem with ending new line '\n'
Yep, we see only one line (with per-page=24) but we use algorithm for "multiline" so we shoudn't now see items truncated too short like in #5388. See my first and second screenshot :) |
This comment has been minimized.
This comment has been minimized.
@Frenzie @NiLuJe @pazos : any opinion on this change? I don't mind it (previous algo was @robert00s too, so his choice :) I find some bits in this code a bit convoluted - but I don't want to request any change, as I'll probably soon have to look at TextBoxWidget, so, now that we know what kind of stuff callers expect, we can integrate a bit of that code into new TextBoxWidget methods, and clean a bit of this in Menu (just like in I did for TextWidget in #5503). |
end | ||
-- remove last line and try again to fit | ||
offset = item_name.vertical_string_list[num_lines].offset - 1 | ||
-- remove ending '\n' (new line) to prevent infinity loop |
This comment has been minimized.
This comment has been minimized.
-- remove last line and try again to fit | ||
offset = item_name.vertical_string_list[num_lines].offset - 1 | ||
-- remove ending '\n' (new line) to prevent infinity loop | ||
if item_name.charlist[offset] == '\n' then |
This comment has been minimized.
This comment has been minimized.
if item_name.charlist[offset] == '\n' then | ||
offset = offset - 1 | ||
end | ||
self.text = table.concat(item_name.charlist, '', 1, offset) |
This comment has been minimized.
This comment has been minimized.
local offset_prev = item_name_orig.vertical_string_list[num_lines - 1].offset | ||
text_last_line = table.concat(item_name_orig.charlist, '', offset_prev, offset) |
This comment has been minimized.
This comment has been minimized.
local max_offset = #item_name_orig.charlist | ||
-- try to add chars to better align | ||
while item_name.width > text_size_increase + ellipsis_size and offset < max_offset | ||
and item_name_orig.charlist[offset] ~= '\n' do |
This comment has been minimized.
This comment has been minimized.
-- when finally after manipulation we have all original text we don't need to add ellipsis | ||
self.text = table.concat(item_name_orig.charlist, '', 1, offset) | ||
else | ||
-- remove ending '\n' (new line) to prevent increase number of lines |
This comment has been minimized.
This comment has been minimized.
self.text = table.concat(item_name_orig.charlist, '', 1, offset) | ||
else | ||
-- remove ending '\n' (new line) to prevent increase number of lines | ||
if item_name_orig.charlist[offset] == '\n' then |
This comment has been minimized.
This comment has been minimized.
-- If we don't fit, decrease font size | ||
self.font_size = self.font_size - 2 | ||
-- add ellipsis to show that text was truncated | ||
self.text = table.concat(item_name_orig.charlist, '', 1, offset) .. "…" |
This comment has been minimized.
This comment has been minimized.
item_name_orig:free() | ||
end | ||
--final item_name that fits | ||
item_name = TextBoxWidget:new { |
This comment has been minimized.
This comment has been minimized.
Frenzie
Oct 20, 2019
Member
item_name = TextBoxWidget:new { | |
item_name = TextBoxWidget:new{ |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Done in #5509 |
robert00s commentedOct 16, 2019
See: #5388
New algorithm:
When text is too long or too height:
And at the end we try to add or remove at least one letter to better fit text.
Needs to be tested. Shouldn't be merge before 2019.10.
Close: #5388