New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TextViewer: add dialog to set font size and justify text #11210
Conversation
frontend/ui/widget/textviewer.lua
Outdated
local ratio = self.scroll_text_w:getCurrentRatio() -- try to keep position | ||
self:init() | ||
self:onShow() | ||
self.scroll_text_w:scrollToRatio(ratio) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you don't need a ratio (scrollToRatio would scroll to some line ratio, while your getCurrentRatio gives the ratio of a charpos among the full text length) : you could just save some current charpos, and I think there are methods in TextBoxWidget to focus on a charpos (moveCursorToCharPos, moveCursorToCharPosKeepingViewCentered...)
frontend/ui/widget/textviewer.lua
Outdated
@@ -161,6 +162,8 @@ function TextViewer:init() | |||
title_face = self.title_face, | |||
title_multilines = self.title_multilines, | |||
title_shrink_font_to_fit = self.title_shrink_font_to_fit, | |||
left_icon = not self.no_set_font and "appbar.menu", | |||
left_icon_tap_callback = function() self:setFontSize() end, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this SpinWidget which hosts this somehow unrelated Justify toggle, this could be a popup menu (like we have in Page browser and Book map), with more features & checkboxes.
Set font size
Monospace ✔
Justify ✔
which could maybe host other features in the future (I think I once missed in TextViewer some feature available in Text editor - but I can't remember what it was :/).
Maybe with tap to apply it just here, and long-press to set it as default for TextViewer?
frontend/ui/widget/textviewer.lua
Outdated
@@ -57,6 +57,7 @@ local TextViewer = InputContainer:extend{ | |||
title_multilines = nil, -- see TitleBar for details | |||
title_shrink_font_to_fit = nil, -- see TitleBar for details | |||
|
|||
no_set_font = false, -- set to true to hide titlebar left icon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would sound better if named allow_set_font = true
or allow_menu = true
or show_menu = true
.
frontend/ui/widget/textviewer.lua
Outdated
text_font_face = nil, -- default "x_smallinfofont" | ||
text_font_size = nil, | ||
monospace_font = nil, -- "infont" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially read that as we could provide (in TextViewer callers, or via user patch) an alternative font to use as the monospace font - your comment "infont"
feels like I could provide "foobarfont" or "Consolas".
But below you use self.monospace_font = not self.monospace_font
, so it's actually a boolean/toggle.
So maybe rename this to use_monospace_font
, or update the comment -- if true, use the "infont" monospace font
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
monospace_font = false, |
I'll update the comment.
frontend/ui/widget/textviewer.lua
Outdated
text_func = function() | ||
return _("Monospace font") .. (self.monospace_font and " \u{2713}" or " \u{2003}") | ||
end, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dunno if you witnessed some odd stuff while testing, but sure you don't need the ugly trick I had to use with this checkbox:
koreader/frontend/ui/widget/bookmapwidget.lua
Lines 1204 to 1229 in 13a521c
text_func = function(no_size_trick) | |
-- A bit tricky to update the text in the callback, as this button, | |
-- being sized by ButtonTable, can't be rebuilt. We will update its | |
-- text, and we want to be sure it will fit in the initial width, | |
-- which may be with the checkmark or not. | |
local text = _("Page browser on tap") | |
if G_reader_settings:nilOrTrue("book_map_tap_to_page_browser") then | |
text = text .. " \u{2713}" -- checkmark | |
else | |
if not no_size_trick then | |
-- Initial call, make it wide enough so the checkmark text will fit | |
text = text .. " \u{2003}" -- wide em space | |
end | |
-- Otherwise, keep it small without the checkmark, which will fit | |
end | |
return text | |
end, | |
id = "tap_to_page_browser", | |
align = "left", | |
callback = function() | |
G_reader_settings:flipNilOrTrue("book_map_tap_to_page_browser") | |
local b = button_dialog:getButtonById("tap_to_page_browser") | |
b:setText(b.text_func(true), b.width) | |
b:refresh() | |
end, | |
}}, |
Or is it because all such checkboxes calls :reinit(), which will rebuilt this popup menu ?
(If yes, I guess everything is rebuild and redrawn, and that the menu popup is closed as soon as you toggle/change things ? Which is a bit different than the behaviour in PageBrowser/Bookmap where we just update the content, and the popup menu stays open. But ok if it's too complicated to get this same behaviour?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I saw the trick)
Yes, the menu is closed on tap.
If we tap Font size, we see the SpinWidget (that remains open on apply) and we need to see more text to choose the size.
If we tap Monospace or Justify, we see the immediate effect on text, and what is our most frequent next action?
If it is reading, that's okay to close the menu.
If it is switching the setting back, it's better to keep it open.
If it is long-pressing to set the setting as default, it's better to keep it open.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is switching the setting back, it's better to keep it open.
As a dev, this is my most frequent next action :)
I get your train of thoughts.
But there's also your other famous bigger train of thoughts: consistency :) (in the common behaviour of such top left menu with checkboxes).
That popup menu is small and in a corner, so it shouldn't be in the way of appreciating the change, and one tap away from closing.
But if it is much more complicated codewise to implement the "classic" behaviour, I'm ok with it.
Menu remains open on tapping Monospace and Justify. |
I see you moved the checkmark logic in Button - and that maybe we won't have to use my sizing trick in Pagebrowser and Bookmap. |
Empty space is reserved with "wide em space" as you did. |
I didn't test long texts with checkmark, I suppose the checkmark will be truncated. |
Oh, right, didn't catch my eyes :)
I guess no need to test for text longer than the screen.
Not sure I would prefer that: in such top left popup menu, where items are left aligned, there might be 3 kinds of items:
I think it looks better if all the text are aligned on the left. If you put the checkmark on the left for the 2nd kind, it would feel quite unaligned/ragged/odd. |
We would need a left margin for all the items (again, like in the touchmenu). |
Yes, some indentation even when it is not needed, that may look odd, and could make that popup menu a bit wider, hiding a bit more of the content below. It works on our TouchMenu as it takes the full width, and there's blank on the right of most items, so it may balance the blank at start. In this popup anchored at top left, it may look odd, or we may need to add the same right marging for visual niceness, making it even wider.
Good ! :) |
Do I fix your widgets here? |
I guess I would have liked it to result in an individual commit in master once merged (which you can't do the way you work via github web), but I guess it will be mostly code removal, so it might be ok if it all happens in one commit. So, as you feel. Tested on my Kobo, and the checkmark and sizing look fine, and the fact that it is kept open is really practical :) But i noticed this: if you set font size (from 20 to 16), it is displayed in 16. Then, if you toggle |
Here is the question: if a caller sets font_face but does not set font_size, should TextViewer use font_size from G_settings, or use the default size of font_face? |
I think that's not really it. And it's that thing below TextViewer that you would need to pass as a reference as show_parent, so only it get repainted. But if you don't have it, using "all" will do all widgets, which might do a bit more useless work, but will work. |
But closing the popup menu fixes the issue without "all". |
Because closing a widget marks every widget behind it as dirty, forcing a repaint ;). (The net effect being similar to The stuff quoted in #11210 (comment) is tricky exactly because of that: it's the same widget instance that changes dimensions, so there's no close anywhere, hence the need for creative thinking ^^. I'd kinda lost the plot on that distinction, but it is very much key, my bad ;). |
"Em space" is wider than the checkmark, causes truncation, will look at it tomorrow. |
frontend/ui/widget/textviewer.lua
Outdated
file_content = { monospace_font = false, font_size = 20, justified = false }, | ||
book_info = { monospace_font = false, font_size = 20, justified = true }, | ||
bookmark = { monospace_font = false, font_size = 20, justified = true }, | ||
dictionary = { monospace_font = false, font_size = 20, justified = false }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This "dictionary" does not impact any dictionary result I think (we don't use TextViewer for them). It would be used only for translator currently.
So, may be "lookup_result" or "lookup" ?
BookInfo module will get text types in the forthcoming PR introducing "set screenshot as book cover". |
Current text types: code (16, m+, j-) lookup (20, m-, j-) book_info (20, m-, j+) bookmark (20, m-, j+) file_content (20, m-, j-) general (default) (20, m-, j-) |
Just noticed that if we launch Book description from the long-press on a file in FM, we get the text justified - but if we launch it from the Book information KeyValuePage when in Reader, we get the text non-justified. |
It is shown as long KVP value, text_type = "general". |
This change is