Text editor: rotate (#12658)

This commit is contained in:
hius07
2024-10-29 20:49:43 +02:00
committed by GitHub
parent b42b9a8799
commit 97a7ebefb9
9 changed files with 127 additions and 153 deletions

View File

@@ -2454,11 +2454,11 @@ function ReaderFooter:onSwapPageTurnButtons()
end
ReaderFooter.onToggleReadingOrder = ReaderFooter.onSwapPageTurnButtons
function ReaderFooter:onSetRotationMode()
function ReaderFooter:onSetDimensions()
self:updateFooterContainer()
self:resetLayout(true)
end
ReaderFooter.onScreenResize = ReaderFooter.onSetRotationMode
ReaderFooter.onScreenResize = ReaderFooter.onSetDimensions
function ReaderFooter:onSetPageHorizMargins(h_margins)
if self.settings.progress_margin then

View File

@@ -1,47 +0,0 @@
local InputContainer = require("ui/widget/container/inputcontainer")
local Device = require("device")
local Event = require("ui/event")
local _ = require("gettext")
local ReaderRotation = InputContainer:extend{
current_rotation = 0,
}
function ReaderRotation:init()
self:registerKeyEvents()
-- NOP our own gesture handling
self.ges_events = nil
end
function ReaderRotation:onGesture() end
function ReaderRotation:registerKeyEvents()
if Device:hasKeyboard() then
self.key_events = {
-- these will all generate the same event, just with different arguments
RotateLeft = {
{ "J" },
event = "Rotate",
args = -90
},
RotateRight = {
{ "K" },
event = "Rotate",
args = 90
},
}
end
end
ReaderRotation.onPhysicalKeyboardConnected = ReaderRotation.registerKeyEvents
--- @todo Reset rotation on new document, maybe on new page?
--- @fixme: More importantly, this breaks rendering, c.f., `Document:renderPage`
-- A modern implementation of this feature is available in Dispatcher via the `IterateRotation` Event.
function ReaderRotation:onRotate(rotate_by)
self.current_rotation = (self.current_rotation + rotate_by) % 360
self.ui:handleEvent(Event:new("RotationUpdate", self.current_rotation))
return true
end
return ReaderRotation

View File

@@ -836,13 +836,15 @@ function ReaderView:restoreViewContext(ctx)
return false
end
function ReaderView:onSetRotationMode(rotation)
if rotation ~= nil then
local old_rotation = Screen:getRotationMode()
if rotation == old_rotation then
return
end
function ReaderView:onSetRotationMode(mode)
local old_mode = Screen:getRotationMode()
if mode ~= nil and mode ~= old_mode then
Screen:setRotationMode(mode)
self:rotate(mode, old_mode)
end
end
function ReaderView:rotate(mode, old_mode)
-- NOTE: We cannot rely on getScreenMode, as it actually checks the screen dimensions, instead of the rotation mode.
-- (i.e., it returns how the screen *looks* like, not how it's oriented relative to its native layout).
-- This would horribly break if you started in Portrait (both rotation and visually),
@@ -850,26 +852,18 @@ function ReaderView:onSetRotationMode(rotation)
-- If you then attempted to switch to a Landscape *rotation*, it would mistakenly think the layout hadn't changed!
-- So, instead, as we're concerned with *rotation* layouts, just compare the two.
-- We use LinuxFB-style constants, so, Portraits are even, Landscapes are odds, making this trivial.
local matching_orientation = bit.band(rotation, 1) == bit.band(old_rotation, 1)
if rotation ~= old_rotation and matching_orientation then
-- No layout change, just rotate & repaint with a flash
Screen:setRotationMode(rotation)
UIManager:setDirty(self.dialog, "full")
Notification:notify(T(_("Rotation mode set to: %1"), optionsutil:getOptionText("SetRotationMode", rotation)))
return
end
Screen:setRotationMode(rotation)
local matching_orientation = bit.band(mode, 1) == bit.band(old_mode, 1)
if matching_orientation then
-- No layout change, just rotate & repaint with a flash
UIManager:setDirty(self.dialog, "full")
else
UIManager:setDirty(nil, "full") -- SetDimensions will only request a partial, we want a flash
local new_screen_size = Screen:getSize()
self.ui:handleEvent(Event:new("SetDimensions", new_screen_size))
self.ui:onScreenResize(new_screen_size)
self.ui:handleEvent(Event:new("InitScrollPageStates"))
end
UIManager:setDirty(nil, "full") -- SetDimensions will only request a partial, we want a flash
local new_screen_size = Screen:getSize()
self.ui:handleEvent(Event:new("SetDimensions", new_screen_size))
self.ui:onScreenResize(new_screen_size)
self.ui:handleEvent(Event:new("InitScrollPageStates"))
Notification:notify(T(_("Rotation mode set to: %1"), optionsutil:getOptionText("SetRotationMode", rotation)))
return
Notification:notify(T(_("Rotation mode set to: %1"), optionsutil:getOptionText("SetRotationMode", mode)))
end
function ReaderView:onSetDimensions(dimensions)
@@ -975,7 +969,7 @@ function ReaderView:onBBoxUpdate(bbox)
self.use_bbox = bbox and true or false
end
--- @note: From ReaderRotation, which is broken and disabled.
--- @note: From ReaderRotation, which was broken, and has been removed in #12658
function ReaderView:onRotationUpdate(rotation)
self.state.rotation = rotation
self:recalculate()

View File

@@ -322,7 +322,7 @@ function ReaderZooming:onRestoreDimensions(dimensions)
self:setZoom()
end
--- @note: From ReaderRotation, which is broken and disabled.
--- @note: From ReaderRotation, which was broken, and has been removed in #12658
function ReaderZooming:onRotationUpdate(rotation)
self.rotation = rotation
self:setZoom()