Skip to content
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

Give more control over CRe margins #4945

Merged
merged 36 commits into from May 1, 2019
Merged
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3ea5073
Never use partial in the keyboard.
NiLuJe Apr 19, 2019
8ba3d91
Allow omitting the status bar height from the bottom margin, even when
NiLuJe Apr 19, 2019
bc8b3c1
Split CRe margin settings in two (Horizontal & Vertical).
NiLuJe Apr 19, 2019
5e3aa33
Oops, don't have access to config here ;).
NiLuJe Apr 19, 2019
c516dcc
Possibly slightly less cryptic label
NiLuJe Apr 19, 2019
5258bcc
Oops, use the right string name ;p.
NiLuJe Apr 19, 2019
08f8df2
Crappier name, but leaves more space for clicky stuff!
NiLuJe Apr 19, 2019
ff2d2f9
Split vertical margin settings into top/bottom
NiLuJe Apr 19, 2019
bfe16db
Oops, forgot to make LuaCheck happy
NiLuJe Apr 19, 2019
267c789
Keep using the same weird ublanaced defaults, because I can't be arsed
NiLuJe Apr 19, 2019
8c63ea5
Forgot those
NiLuJe Apr 19, 2019
9ccfd6f
Update defaults tests (+19 keys)
NiLuJe Apr 19, 2019
8883e14
Gah.
NiLuJe Apr 19, 2019
f817a9a
Gnnnnn.
NiLuJe Apr 19, 2019
ded7585
I feel like if we could eval' the file instead, it'd be much easier to
NiLuJe Apr 19, 2019
9d66d17
Move margin settings to a new, dedicated tab
NiLuJe Apr 20, 2019
b0d9dfd
Add a buttonprogress variant with -/+ buttons on the sdie, for fine
NiLuJe Apr 20, 2019
b26f4b8
Can't make those default ;)
NiLuJe Apr 20, 2019
e9a4ea8
Use dedicated callbacks for tap/hold on -/+ buttons, to keep things
NiLuJe Apr 20, 2019
9066c0e
Show a toast when setting margins
NiLuJe Apr 20, 2019
87382d8
Longer timeout, and InfoMessage, because we need linefeeds.
NiLuJe Apr 20, 2019
0732f2b
Don't show the margins infomessage when opening the book ;).
NiLuJe Apr 20, 2019
2301a08
Kill debug
NiLuJe Apr 20, 2019
42af9bf
Make top margin fine tunable, too.
NiLuJe Apr 20, 2019
70a2743
Kill extra and ugly final linefeed
NiLuJe Apr 20, 2019
9c13b00
Kill all that, luacheck's right ;).
NiLuJe Apr 20, 2019
f4bbbf3
Migrate old global margin settings
NiLuJe Apr 29, 2019
7485058
Print a recap of the migration
NiLuJe Apr 29, 2019
44a7e01
Handle local settings migration, too.
NiLuJe Apr 29, 2019
0610bf1
Double the margin for the -/+ buttons
NiLuJe Apr 29, 2019
44f118b
Tuck away settings migration internals inside LuaSettings/DocSettings
NiLuJe Apr 29, 2019
d0fbf7b
DRYer
NiLuJe Apr 30, 2019
609edc9
Do a wee bit of introspection to make logging more accurate
NiLuJe Apr 30, 2019
c3e4c77
Update that comment ;)
NiLuJe Apr 30, 2019
caccaf8
Fool-proof that to prevent blowing up on bogus input
NiLuJe Apr 30, 2019
6620457
Wheee!
NiLuJe Apr 30, 2019
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -64,14 +64,33 @@ read_globals = {
"DKOPTREADER_CONFIG_DOC_DEFAULT_LANG_CODE",
"DCREREADER_CONFIG_FONT_SIZES",
"DCREREADER_CONFIG_DEFAULT_FONT_SIZE",
"DCREREADER_CONFIG_MARGIN_SIZES_SMALL",
"DCREREADER_CONFIG_MARGIN_SIZES_MEDIUM",
"DCREREADER_CONFIG_MARGIN_SIZES_LARGE",
"DCREREADER_CONFIG_MARGIN_SIZES_X_LARGE",
"DCREREADER_CONFIG_MARGIN_SIZES_XX_LARGE",
"DCREREADER_CONFIG_MARGIN_SIZES_XXX_LARGE",
"DCREREADER_CONFIG_MARGIN_SIZES_HUGE",
"DCREREADER_CONFIG_MARGIN_SIZES_X_HUGE",
"DCREREADER_CONFIG_H_MARGIN_SIZES_SMALL",
"DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM",
"DCREREADER_CONFIG_H_MARGIN_SIZES_LARGE",
"DCREREADER_CONFIG_H_MARGIN_SIZES_X_LARGE",
"DCREREADER_CONFIG_H_MARGIN_SIZES_XX_LARGE",
"DCREREADER_CONFIG_H_MARGIN_SIZES_XXX_LARGE",
"DCREREADER_CONFIG_H_MARGIN_SIZES_HUGE",
"DCREREADER_CONFIG_H_MARGIN_SIZES_X_HUGE",
"DCREREADER_CONFIG_H_MARGIN_SIZES_XX_HUGE",
"DCREREADER_CONFIG_T_MARGIN_SIZES_SMALL",
"DCREREADER_CONFIG_T_MARGIN_SIZES_MEDIUM",
"DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE",
"DCREREADER_CONFIG_T_MARGIN_SIZES_X_LARGE",
"DCREREADER_CONFIG_T_MARGIN_SIZES_XX_LARGE",
"DCREREADER_CONFIG_T_MARGIN_SIZES_XXX_LARGE",
"DCREREADER_CONFIG_T_MARGIN_SIZES_HUGE",
"DCREREADER_CONFIG_T_MARGIN_SIZES_X_HUGE",
"DCREREADER_CONFIG_T_MARGIN_SIZES_XX_HUGE",
"DCREREADER_CONFIG_B_MARGIN_SIZES_SMALL",
"DCREREADER_CONFIG_B_MARGIN_SIZES_MEDIUM",
"DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE",
"DCREREADER_CONFIG_B_MARGIN_SIZES_X_LARGE",
"DCREREADER_CONFIG_B_MARGIN_SIZES_XX_LARGE",
"DCREREADER_CONFIG_B_MARGIN_SIZES_XXX_LARGE",
"DCREREADER_CONFIG_B_MARGIN_SIZES_HUGE",
"DCREREADER_CONFIG_B_MARGIN_SIZES_X_HUGE",
"DCREREADER_CONFIG_B_MARGIN_SIZES_XX_HUGE",
"DCREREADER_CONFIG_LIGHTER_FONT_GAMMA",
"DCREREADER_CONFIG_DEFAULT_FONT_GAMMA",
"DCREREADER_CONFIG_DARKER_FONT_GAMMA",
@@ -114,15 +114,38 @@ DCREREADER_CONFIG_FONT_SIZES = {12, 16, 20, 22, 24, 26, 28, 30, 34, 38, 44} --
DCREREADER_CONFIG_DEFAULT_FONT_SIZE = 22 -- default font size

-- crereader margin sizes
-- margin {left, top, right, bottom} in pixels
DCREREADER_CONFIG_MARGIN_SIZES_SMALL = {5, 10, 5, 10}
DCREREADER_CONFIG_MARGIN_SIZES_MEDIUM = {10, 15, 10, 15}
DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {20, 20, 20, 20}
DCREREADER_CONFIG_MARGIN_SIZES_X_LARGE = {30, 30, 30, 30}
DCREREADER_CONFIG_MARGIN_SIZES_XX_LARGE = {50, 50, 50, 50}
DCREREADER_CONFIG_MARGIN_SIZES_XXX_LARGE = {70, 70, 70, 70}
DCREREADER_CONFIG_MARGIN_SIZES_HUGE = {100, 100, 100, 100}
DCREREADER_CONFIG_MARGIN_SIZES_X_HUGE = {140, 140, 140, 140}
-- horizontal margins {left, right} in (relative) pixels
DCREREADER_CONFIG_H_MARGIN_SIZES_SMALL = {5, 5}
DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM = {10, 10}
DCREREADER_CONFIG_H_MARGIN_SIZES_LARGE = {15, 15}
DCREREADER_CONFIG_H_MARGIN_SIZES_X_LARGE = {20, 20}
DCREREADER_CONFIG_H_MARGIN_SIZES_XX_LARGE = {30, 30}
DCREREADER_CONFIG_H_MARGIN_SIZES_XXX_LARGE = {50, 50}
DCREREADER_CONFIG_H_MARGIN_SIZES_HUGE = {70, 70}
DCREREADER_CONFIG_H_MARGIN_SIZES_X_HUGE = {100, 100}
DCREREADER_CONFIG_H_MARGIN_SIZES_XX_HUGE = {140, 140}

-- top margin in (relative) pixels
DCREREADER_CONFIG_T_MARGIN_SIZES_SMALL = 5
DCREREADER_CONFIG_T_MARGIN_SIZES_MEDIUM = 10
DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE = 15
DCREREADER_CONFIG_T_MARGIN_SIZES_X_LARGE = 20
DCREREADER_CONFIG_T_MARGIN_SIZES_XX_LARGE = 30
DCREREADER_CONFIG_T_MARGIN_SIZES_XXX_LARGE = 50
DCREREADER_CONFIG_T_MARGIN_SIZES_HUGE = 70
DCREREADER_CONFIG_T_MARGIN_SIZES_X_HUGE = 100
DCREREADER_CONFIG_T_MARGIN_SIZES_XX_HUGE = 140

-- bottom margin in (relative) pixels
DCREREADER_CONFIG_B_MARGIN_SIZES_SMALL = 5
DCREREADER_CONFIG_B_MARGIN_SIZES_MEDIUM = 10
DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE = 15
DCREREADER_CONFIG_B_MARGIN_SIZES_X_LARGE = 20
DCREREADER_CONFIG_B_MARGIN_SIZES_XX_LARGE = 30
DCREREADER_CONFIG_B_MARGIN_SIZES_XXX_LARGE = 50
DCREREADER_CONFIG_B_MARGIN_SIZES_HUGE = 70
DCREREADER_CONFIG_B_MARGIN_SIZES_X_HUGE = 100
DCREREADER_CONFIG_B_MARGIN_SIZES_XX_HUGE = 140

-- crereader font gamma (no longer used)
-- DCREREADER_CONFIG_LIGHTER_FONT_GAMMA = 10
@@ -43,10 +43,17 @@ end
function ReaderDogear:onReadSettings(config)
if not self.ui.document.info.has_pages then
-- Adjust to CreDocument margins (as done in ReaderTypeset)
self:onSetPageMargins(
config:readSetting("copt_page_margins") or

This comment has been minimized.

Copy link
@houqp

houqp Apr 21, 2019

Member

just curious, do we have any plan to migrate the old setting?

G_reader_settings:readSetting("copt_page_margins") or
DCREREADER_CONFIG_MARGIN_SIZES_MEDIUM)
local h_margins = config:readSetting("copt_h_page_margins") or
G_reader_settings:readSetting("copt_h_page_margins") or
DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM
local t_margin = config:readSetting("copt_t_page_margin") or
G_reader_settings:readSetting("copt_t_page_margin") or
DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE
local b_margin = config:readSetting("copt_b_page_margin") or
G_reader_settings:readSetting("copt_b_page_margin") or
DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE
local margins = { h_margins[1], t_margin, h_margins[2], b_margin }
self:onSetPageMargins(margins)
end
end

@@ -137,6 +137,7 @@ function ReaderFooter:init()
-- disable_progress_bar = true,
disabled = false,
all_at_once = false,
reclaim_height = false,
toc_markers = true,
battery = true,
time = true,
@@ -158,6 +159,7 @@ function ReaderFooter:init()

self.pageno = self.view.state.page
self.has_no_mode = true
self.reclaim_height = self.settings.reclaim_height or false
for _, m in ipairs(MODE_INDEX) do
if self.settings[m] then
self.has_no_mode = false
@@ -337,6 +339,7 @@ end

local option_titles = {
all_at_once = _("Show all at once"),
reclaim_height = _("Reclaim bar height from bottom margin"),
toc_markers = _("Show chapter markers"),
page_progress = _("Current page"),
time = _("Current time"),
@@ -387,6 +390,7 @@ function ReaderFooter:addToMainMenu(menu_items)
local should_update = false
local first_enabled_mode_num
local prev_has_no_mode = self.has_no_mode
local prev_reclaim_height = self.reclaim_height
self.has_no_mode = true
for mode_num, m in pairs(MODE_INDEX) do
if self.settings[m] then
@@ -395,14 +399,18 @@ function ReaderFooter:addToMainMenu(menu_items)
break
end
end
self.reclaim_height = self.settings.reclaim_height or false
-- refresh margins position
if self.has_no_mode then
self.ui:handleEvent(Event:new("SetPageMargins", self.view.document.configurable.page_margins))
self.ui:handleEvent(Event:new("SetPageBottomMargin", self.view.document.configurable.b_page_margin))
self.genFooterText = footerTextGeneratorMap.empty
self.mode = MODE.off
elseif prev_has_no_mode then
self.ui:handleEvent(Event:new("SetPageMargins", self.view.document.configurable.page_margins))
self.ui:handleEvent(Event:new("SetPageBottomMargin", self.view.document.configurable.b_page_margin))
G_reader_settings:saveSetting("reader_footer_mode", first_enabled_mode_num)
elseif self.reclaim_height ~= prev_reclaim_height then
self.ui:handleEvent(Event:new("SetPageBottomMargin", self.view.document.configurable.b_page_margin))
should_update = true
end
if callback then
should_update = callback(self)
@@ -429,6 +437,8 @@ function ReaderFooter:addToMainMenu(menu_items)

table.insert(sub_items,
getMinibarOption("all_at_once", self.updateFooterTextGenerator))
table.insert(sub_items,
getMinibarOption("reclaim_height"))
table.insert(sub_items, {
text = _("Progress bar"),
sub_item_table = {
@@ -1,5 +1,6 @@
local ConfirmBox = require("ui/widget/confirmbox")
local Event = require("ui/event")
local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer")
local UIManager = require("ui/uimanager")
local lfs = require("libs/libkoreader-lfs")
@@ -11,6 +12,7 @@ local ReaderTypeset = InputContainer:new{
css_menu_title = _("Style"),
css = nil,
internal_css = true,
unscaled_margins = nil,
}

function ReaderTypeset:init()
@@ -58,10 +60,17 @@ function ReaderTypeset:onReadSettings(config)
-- self.ui.document:setRenderScaleFontWithDPI(1)

-- set page margins
self:onSetPageMargins(
config:readSetting("copt_page_margins") or
G_reader_settings:readSetting("copt_page_margins") or
DCREREADER_CONFIG_MARGIN_SIZES_MEDIUM)
local h_margins = config:readSetting("copt_h_page_margins") or
G_reader_settings:readSetting("copt_h_page_margins") or
DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM
local t_margin = config:readSetting("copt_t_page_margin") or
G_reader_settings:readSetting("copt_t_page_margin") or
DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE
local b_margin = config:readSetting("copt_b_page_margin") or
G_reader_settings:readSetting("copt_b_page_margin") or
DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE
self.unscaled_margins = { h_margins[1], t_margin, h_margins[2], b_margin }
self:onSetPageMargins(self.unscaled_margins, true)

-- default to disable floating punctuation
-- the floating punctuation should not be boolean value for the following
@@ -336,18 +345,45 @@ function ReaderTypeset:makeDefaultStyleSheet(css, text, touchmenu_instance)
})
end

function ReaderTypeset:onSetPageMargins(margins)
function ReaderTypeset:onSetPageHorizMargins(h_margins)
self.unscaled_margins = { h_margins[1], self.unscaled_margins[2], h_margins[2], self.unscaled_margins[4] }
self:onSetPageMargins(self.unscaled_margins)
end

function ReaderTypeset:onSetPageTopMargin(t_margin)
self.unscaled_margins = { self.unscaled_margins[1], t_margin, self.unscaled_margins[3], self.unscaled_margins[4] }
self:onSetPageMargins(self.unscaled_margins)
end

function ReaderTypeset:onSetPageBottomMargin(b_margin)
self.unscaled_margins = { self.unscaled_margins[1], self.unscaled_margins[2], self.unscaled_margins[3], b_margin }
self:onSetPageMargins(self.unscaled_margins)
end

function ReaderTypeset:onSetPageMargins(margins, silent)
local left = Screen:scaleBySize(margins[1])
local top = Screen:scaleBySize(margins[2])
local right = Screen:scaleBySize(margins[3])
local bottom
if self.view.footer.has_no_mode then
if self.view.footer.has_no_mode or self.view.footer.reclaim_height then
bottom = Screen:scaleBySize(margins[4])
else
bottom = Screen:scaleBySize(margins[4] + DMINIBAR_HEIGHT)
end
self.ui.document:setPageMargins(left, top, right, bottom)
self.ui:handleEvent(Event:new("UpdatePos"))
if not silent then
-- Show a toast on set, with the unscaled & scaled values
UIManager:show(InfoMessage:new{
text = T(_([[
Margins set to:
horizontal: %1 (%2px)
top: %3 (%4px)
bottom: %5 (%6px)]]),
margins[1], left, margins[2], top, margins[4], bottom),
timeout = 4,
})
end
return true
end

@@ -49,6 +49,7 @@ local ReaderView = require("apps/reader/modules/readerview")
local ReaderWikipedia = require("apps/reader/modules/readerwikipedia")
local ReaderZooming = require("apps/reader/modules/readerzooming")
local Screenshoter = require("ui/widget/screenshoter")
local SettingsMigration = require("ui/data/settings_migration")
local UIManager = require("ui/uimanager")
local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
@@ -100,6 +101,8 @@ function ReaderUI:init()
end

self.doc_settings = DocSettings:open(self.document.file)
-- Handle local settings migration
SettingsMigration:migrateSettings(self.doc_settings)

if Device:hasKeys() then
self.key_events.Home = { {"Home"}, doc = "open file browser" }
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.