Files
booksprite/frontend/ui/elements/screen_rotation_menu_table.lua
Zhiqi Yao ce727e7736 Screen rotation: always show rotation mode options in file browser (#15505)
Previously rotation mode options were gated behind FileManager.instance,
which becomes nil when the Reader is opened (ReaderUI:doShowReader
explicitly closes the FileManager). This made manual rotation
inaccessible from the Reader view on all platforms, especially
noticeable on Android where hasGSensor is false and the menu otherwise
offers no way to change orientation.

Original reasoning from <https://github.com/koreader/koreader/pull/6309>:
> Before this PR we were always setting a screenmode and the checking what rotation to use, now we set rotations, and let koreader figure out what is the screenmode. (besides for the FM, which does not support landscape) now the only thing setting a screenmode is the FM.
> 
> This separates the rotation (physical) from the screenmode (portrait/landscape or H>W/W>H). I did not get into why the FM has to be portrait but if someone fixes that then the rotation and screenmode will be totally independent.
2026-06-06 21:18:10 +02:00

122 lines
5.3 KiB
Lua

local Device = require("device")
local Event = require("ui/event")
local UIManager = require("ui/uimanager")
local _ = require("gettext")
local Screen = Device.screen
local function genMenuItem(text, mode)
return {
text_func = function()
return G_reader_settings:readSetting("fm_rotation_mode") == mode and text .. " ★" or text
end,
checked_func = function()
return Screen:getRotationMode() == mode
end,
radio = true,
check_callback_closes_menu = true,
callback = function(touchmenu_instance)
UIManager:broadcastEvent(Event:new("SetRotationMode", mode))
touchmenu_instance:closeMenu()
end,
hold_callback = function(touchmenu_instance)
G_reader_settings:saveSetting("fm_rotation_mode", mode)
touchmenu_instance:updateItems()
end,
}
end
return {
text = _("Rotation"),
sub_item_table_func = function()
local rotation_table = {}
if Device:hasGSensor() then
table.insert(rotation_table, {
text = _("Ignore accelerometer rotation events"),
help_text = _("This will inhibit automatic rotations triggered by your device's gyro."),
checked_func = function()
return G_reader_settings:isTrue("input_ignore_gsensor")
end,
callback = function()
UIManager:broadcastEvent(Event:new("ToggleGSensor"))
end,
})
table.insert(rotation_table, {
text = _("Lock auto rotation to current orientation"),
help_text = _([[
When checked, the gyro will only be honored when switching between the two inverse variants of your current rotation,
i.e., Portrait <-> Inverted Portrait OR Landscape <-> Inverted Landscape.
Switching between (Inverted) Portrait and (Inverted) Landscape will be inhibited.
If you need to do so, you'll have to use the UI toggles.]]),
enabled_func = function()
return G_reader_settings:nilOrFalse("input_ignore_gsensor")
end,
checked_func = function()
return G_reader_settings:isTrue("input_lock_gsensor")
end,
callback = function()
UIManager:broadcastEvent(Event:new("LockGSensor"))
end,
})
end
table.insert(rotation_table, {
text = _("Keep current rotation across views"),
help_text = _([[
When checked, the current rotation will be kept when switching between the file browser and the reader, in both directions, and that no matter what the document's saved rotation or the default reader or file browser rotation may be.
This means that nothing will ever sneak a rotation behind your back, you choose your device's rotation, and it stays that way.
When unchecked, the default rotation of the file browser and the default/saved reader rotation will not affect each other (i.e., they will be honored), and may very well be different.]]),
checked_func = function()
return G_reader_settings:isTrue("lock_rotation")
end,
callback = function()
G_reader_settings:flipNilOrFalse("lock_rotation")
end,
separator = true,
})
local optionsutil = require("ui/data/optionsutil")
for i, mode in ipairs(optionsutil.rotation_modes) do
table.insert(rotation_table, genMenuItem(optionsutil.rotation_labels[i], mode))
end
rotation_table[#rotation_table].separator = true
table.insert(rotation_table, {
text = _("Image viewer rotation"),
sub_item_table = {
{
text = _("Invert default rotation in portrait mode"),
checked_func = function()
return G_reader_settings:isTrue("imageviewer_rotation_portrait_invert")
end,
callback = function()
G_reader_settings:flipNilOrFalse("imageviewer_rotation_portrait_invert")
end,
},
{
text = _("Invert default rotation in landscape mode"),
checked_func = function()
return G_reader_settings:isTrue("imageviewer_rotation_landscape_invert")
end,
callback = function()
G_reader_settings:flipNilOrFalse("imageviewer_rotation_landscape_invert")
end,
separator = true,
},
{
text = _("Auto-rotate for best fit"),
help_text = _("Auto-rotate the image to best match screen and image aspect ratios on image viewer launch (ie. if in portrait mode, a landscape image will be rotated).");
checked_func = function()
return G_reader_settings:isTrue("imageviewer_rotate_auto_for_best_fit")
end,
callback = function()
G_reader_settings:flipTrue("imageviewer_rotate_auto_for_best_fit")
end,
}
}
})
return rotation_table
end,
}