mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
CRe margins: hide bottom menu on change (#5000)
So we can immediately see how's the bottom margin.
This commit is contained in:
@@ -71,7 +71,7 @@ function ReaderTypeset:onReadSettings(config)
|
||||
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)
|
||||
self:onSetPageMargins(self.unscaled_margins)
|
||||
self.sync_t_b_page_margins = config:readSetting("copt_sync_t_b_page_margins") or
|
||||
G_reader_settings:readSetting("copt_sync_t_b_page_margins") or 0
|
||||
self.sync_t_b_page_margins = self.sync_t_b_page_margins == 1 and true or false
|
||||
@@ -349,32 +349,32 @@ function ReaderTypeset:makeDefaultStyleSheet(css, text, touchmenu_instance)
|
||||
})
|
||||
end
|
||||
|
||||
function ReaderTypeset:onSetPageHorizMargins(h_margins)
|
||||
function ReaderTypeset:onSetPageHorizMargins(h_margins, refresh_callback)
|
||||
self.unscaled_margins = { h_margins[1], self.unscaled_margins[2], h_margins[2], self.unscaled_margins[4] }
|
||||
self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins))
|
||||
self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, refresh_callback))
|
||||
end
|
||||
|
||||
function ReaderTypeset:onSetPageTopMargin(t_margin)
|
||||
function ReaderTypeset:onSetPageTopMargin(t_margin, refresh_callback)
|
||||
self.unscaled_margins = { self.unscaled_margins[1], t_margin, self.unscaled_margins[3], self.unscaled_margins[4] }
|
||||
if self.sync_t_b_page_margins then
|
||||
self.unscaled_margins[4] = t_margin
|
||||
-- Let ConfigDialog know so it can update it on screen and have it saved on quit
|
||||
self.ui.document.configurable.b_page_margin = t_margin
|
||||
end
|
||||
self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins))
|
||||
self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, refresh_callback))
|
||||
end
|
||||
|
||||
function ReaderTypeset:onSetPageBottomMargin(b_margin)
|
||||
function ReaderTypeset:onSetPageBottomMargin(b_margin, refresh_callback)
|
||||
self.unscaled_margins = { self.unscaled_margins[1], self.unscaled_margins[2], self.unscaled_margins[3], b_margin }
|
||||
if self.sync_t_b_page_margins then
|
||||
self.unscaled_margins[2] = b_margin
|
||||
-- Let ConfigDialog know so it can update it on screen and have it saved on quit
|
||||
self.ui.document.configurable.t_page_margin = b_margin
|
||||
end
|
||||
self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins))
|
||||
self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, refresh_callback))
|
||||
end
|
||||
|
||||
function ReaderTypeset:onSyncPageTopBottomMargins(toggle)
|
||||
function ReaderTypeset:onSyncPageTopBottomMargins(toggle, refresh_callback)
|
||||
self.sync_t_b_page_margins = not self.sync_t_b_page_margins
|
||||
if self.sync_t_b_page_margins then
|
||||
-- Adjust current top and bottom margins if needed
|
||||
@@ -389,12 +389,16 @@ function ReaderTypeset:onSyncPageTopBottomMargins(toggle)
|
||||
self.ui.document.configurable.t_page_margin = mean_margin
|
||||
self.ui.document.configurable.b_page_margin = mean_margin
|
||||
self.unscaled_margins = { self.unscaled_margins[1], mean_margin, self.unscaled_margins[3], mean_margin }
|
||||
self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins))
|
||||
self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, refresh_callback))
|
||||
refresh_callback = nil
|
||||
end
|
||||
end
|
||||
if refresh_callback then
|
||||
refresh_callback()
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderTypeset:onSetPageMargins(margins, silent)
|
||||
function ReaderTypeset:onSetPageMargins(margins, refresh_callback)
|
||||
local left = Screen:scaleBySize(margins[1])
|
||||
local top = Screen:scaleBySize(margins[2])
|
||||
local right = Screen:scaleBySize(margins[3])
|
||||
@@ -406,16 +410,19 @@ function ReaderTypeset:onSetPageMargins(margins, silent)
|
||||
end
|
||||
self.ui.document:setPageMargins(left, top, right, bottom)
|
||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||
if not silent then
|
||||
if refresh_callback 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)]]),
|
||||
bottom: %5 (%6px)
|
||||
|
||||
Tap to dismiss.]]),
|
||||
margins[1], left, margins[2], top, margins[4], bottom),
|
||||
timeout = 4,
|
||||
dismiss_callback = refresh_callback,
|
||||
})
|
||||
end
|
||||
return true
|
||||
|
||||
@@ -89,6 +89,7 @@ Note that this may not be ensured under some conditions: in scroll mode, when a
|
||||
DCREREADER_CONFIG_H_MARGIN_SIZES_X_HUGE,
|
||||
DCREREADER_CONFIG_H_MARGIN_SIZES_XX_HUGE,
|
||||
},
|
||||
delay_repaint = true,
|
||||
name_text_hold_callback = optionsutil.showValuesHMargins,
|
||||
},
|
||||
{
|
||||
@@ -97,9 +98,10 @@ Note that this may not be ensured under some conditions: in scroll mode, when a
|
||||
toggle = {S.OFF, S.ON},
|
||||
values = {0, 1},
|
||||
default_value = 0,
|
||||
event = "SyncPageTopBottomMargins",
|
||||
args = {false, true},
|
||||
default_arg = false,
|
||||
event = "SyncPageTopBottomMargins",
|
||||
delay_repaint = true,
|
||||
name_text_hold_callback = optionsutil.showValues,
|
||||
help_text = _([[Keep top and bottom margins synchronized.
|
||||
- 'off' allows different top and bottom margins.
|
||||
@@ -137,6 +139,7 @@ In the top menu → Settings → Status bar, you can choose whether the bottom m
|
||||
DCREREADER_CONFIG_T_MARGIN_SIZES_X_HUGE,
|
||||
DCREREADER_CONFIG_T_MARGIN_SIZES_XX_HUGE,
|
||||
},
|
||||
delay_repaint = true,
|
||||
name_text_hold_callback = optionsutil.showValues,
|
||||
},
|
||||
{
|
||||
@@ -169,6 +172,7 @@ In the top menu → Settings → Status bar, you can choose whether the bottom m
|
||||
DCREREADER_CONFIG_B_MARGIN_SIZES_X_HUGE,
|
||||
DCREREADER_CONFIG_B_MARGIN_SIZES_XX_HUGE,
|
||||
},
|
||||
delay_repaint = true,
|
||||
name_text_hold_callback = optionsutil.showValues,
|
||||
help_text = _([[In the top menu → Settings → Status bar, you can choose whether the bottom margin applies from the bottom of the screen, or from above the status bar.]]),
|
||||
},
|
||||
|
||||
@@ -514,6 +514,7 @@ function ConfigOption:init()
|
||||
args = self.options[c].args,
|
||||
event = self.options[c].event,
|
||||
events = self.options[c].events,
|
||||
delay_repaint = self.options[c].delay_repaint,
|
||||
config = self.config,
|
||||
enabled = enabled,
|
||||
row_count = row_count,
|
||||
@@ -541,10 +542,10 @@ function ConfigOption:init()
|
||||
callback = function(arg)
|
||||
if arg == "-" or arg == "+" then
|
||||
self.config:onConfigFineTuneChoose(self.options[c].values, self.options[c].name,
|
||||
self.options[c].event, self.options[c].args, self.options[c].events, arg)
|
||||
self.options[c].event, self.options[c].args, self.options[c].events, arg, self.options[c].delay_repaint)
|
||||
else
|
||||
self.config:onConfigChoose(self.options[c].values, self.options[c].name,
|
||||
self.options[c].event, self.options[c].args, self.options[c].events, arg)
|
||||
self.options[c].event, self.options[c].args, self.options[c].events, arg, self.options[c].delay_repaint)
|
||||
end
|
||||
UIManager:setDirty(self.config, function()
|
||||
return "fast", switch.dimen
|
||||
@@ -855,8 +856,8 @@ function ConfigDialog:onConfigChoice(option_name, option_value)
|
||||
return true
|
||||
end
|
||||
|
||||
function ConfigDialog:onConfigEvent(option_event, option_arg)
|
||||
self.ui:handleEvent(Event:new(option_event, option_arg))
|
||||
function ConfigDialog:onConfigEvent(option_event, option_arg, refresh_callback)
|
||||
self.ui:handleEvent(Event:new(option_event, option_arg, refresh_callback))
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -868,14 +869,41 @@ function ConfigDialog:onConfigEvents(option_events, arg_index)
|
||||
return true
|
||||
end
|
||||
|
||||
function ConfigDialog:onConfigChoose(values, name, event, args, events, position)
|
||||
function ConfigDialog:onConfigChoose(values, name, event, args, events, position, delay_repaint)
|
||||
UIManager:tickAfterNext(function()
|
||||
-- Repainting may be delayed depending on options
|
||||
local refresh_dialog_func = function()
|
||||
self.skip_paint = nil
|
||||
if self.config_options.needs_redraw_on_change then
|
||||
-- Some Kopt document event handlers just save their setting,
|
||||
-- and need a full repaint for kopt to load these settings,
|
||||
-- notice the change, and redraw the document
|
||||
UIManager:setDirty("all", "partial")
|
||||
else
|
||||
-- CreDocument event handlers do their own refresh:
|
||||
-- we can just redraw our frame
|
||||
UIManager:setDirty(self, function()
|
||||
return "ui", self.dialog_frame.dimen
|
||||
end)
|
||||
end
|
||||
end
|
||||
local refresh_callback = nil
|
||||
if type(delay_repaint) == "number" then -- timeout
|
||||
UIManager:scheduleIn(delay_repaint, refresh_dialog_func)
|
||||
self.skip_paint = true
|
||||
elseif delay_repaint then -- anything but nil or false: provide a callback
|
||||
-- This needs the config option to have an "event" key
|
||||
-- The event handler is responsible for calling this callback when
|
||||
-- it considers it appropriate
|
||||
refresh_callback = refresh_dialog_func
|
||||
self.skip_paint = true
|
||||
end
|
||||
if values then
|
||||
self:onConfigChoice(name, values[position])
|
||||
end
|
||||
if event then
|
||||
args = args or {}
|
||||
self:onConfigEvent(event, args[position])
|
||||
self:onConfigEvent(event, args[position], refresh_callback)
|
||||
end
|
||||
if events then
|
||||
self:onConfigEvents(events, position)
|
||||
@@ -885,24 +913,42 @@ function ConfigDialog:onConfigChoose(values, name, event, args, events, position
|
||||
-- toggles may have their state (enabled/disabled) modified
|
||||
-- after this toggle update.
|
||||
self:update()
|
||||
if self.config_options.needs_redraw_on_change then
|
||||
-- Some Kopt document event handlers just save their setting,
|
||||
-- and need a full repaint for kopt to load these settings,
|
||||
-- notice the change, and redraw the document
|
||||
UIManager:setDirty("all", "partial")
|
||||
else
|
||||
-- CreDocument event handlers do their own refresh:
|
||||
-- we can just redraw our frame
|
||||
UIManager:setDirty(self, function()
|
||||
return "ui", self.dialog_frame.dimen
|
||||
end)
|
||||
if not delay_repaint then -- immediate refresh
|
||||
refresh_dialog_func()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Tweaked variant used with the fine_tune variant of buttonprogress (direction can only be "-" or "+")
|
||||
function ConfigDialog:onConfigFineTuneChoose(values, name, event, args, events, direction)
|
||||
function ConfigDialog:onConfigFineTuneChoose(values, name, event, args, events, direction, delay_repaint)
|
||||
UIManager:tickAfterNext(function()
|
||||
-- Repainting may be delayed depending on options
|
||||
local refresh_dialog_func = function()
|
||||
self.skip_paint = nil
|
||||
if self.config_options.needs_redraw_on_change then
|
||||
-- Some Kopt document event handlers just save their setting,
|
||||
-- and need a full repaint for kopt to load these settings,
|
||||
-- notice the change, and redraw the document
|
||||
UIManager:setDirty("all", "partial")
|
||||
else
|
||||
-- CreDocument event handlers do their own refresh:
|
||||
-- we can just redraw our frame
|
||||
UIManager:setDirty(self, function()
|
||||
return "ui", self.dialog_frame.dimen
|
||||
end)
|
||||
end
|
||||
end
|
||||
local refresh_callback = nil
|
||||
if type(delay_repaint) == "number" then -- timeout
|
||||
UIManager:scheduleIn(delay_repaint, refresh_dialog_func)
|
||||
self.skip_paint = true
|
||||
elseif delay_repaint then -- anything but nil or false: provide a callback
|
||||
-- This needs the config option to have an "event" key
|
||||
-- The event handler is responsible for calling this callback when
|
||||
-- it considers it appropriate
|
||||
refresh_callback = refresh_dialog_func
|
||||
self.skip_paint = true
|
||||
end
|
||||
if values then
|
||||
local value
|
||||
if direction == "-" then
|
||||
@@ -934,7 +980,7 @@ function ConfigDialog:onConfigFineTuneChoose(values, name, event, args, events,
|
||||
arg = arg + 1
|
||||
end
|
||||
end
|
||||
self:onConfigEvent(event, arg)
|
||||
self:onConfigEvent(event, arg, refresh_callback)
|
||||
end
|
||||
if events then
|
||||
self:onConfigEvents(events, direction)
|
||||
@@ -944,17 +990,8 @@ function ConfigDialog:onConfigFineTuneChoose(values, name, event, args, events,
|
||||
-- toggles may have their state (enabled/disabled) modified
|
||||
-- after this toggle update.
|
||||
self:update()
|
||||
if self.config_options.needs_redraw_on_change then
|
||||
-- Some Kopt document event handlers just save their setting,
|
||||
-- and need a full repaint for kopt to load these settings,
|
||||
-- notice the change, and redraw the document
|
||||
UIManager:setDirty("all", "partial")
|
||||
else
|
||||
-- CreDocument event handlers do their own refresh:
|
||||
-- we can just redraw our frame
|
||||
UIManager:setDirty(self, function()
|
||||
return "ui", self.dialog_frame.dimen
|
||||
end)
|
||||
if not delay_repaint then -- immediate refresh
|
||||
refresh_dialog_func()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -68,6 +68,9 @@ function InputContainer:paintTo(bb, x, y)
|
||||
if self[1] == nil then
|
||||
return
|
||||
end
|
||||
if self.skip_paint then
|
||||
return
|
||||
end
|
||||
|
||||
if not self.dimen then
|
||||
local content_size = self[1]:getSize()
|
||||
|
||||
@@ -202,7 +202,7 @@ function ToggleSwitch:onTapSelect(arg, gev)
|
||||
end
|
||||
--]]
|
||||
self.config:onConfigChoose(self.values, self.name,
|
||||
self.event, self.args, self.events, self.position)
|
||||
self.event, self.args, self.events, self.position, self.delay_repaint)
|
||||
UIManager:setDirty(self.config, function()
|
||||
return "ui", self.dimen
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user