Invert progress bar direction, independently of UI layout (LTR/RTL) (#13382)

This commit is contained in:
David authored and GitHub committed 2025-08-29 08:13:01 +02:00
1 parent 1ad234d754
commit 6c25d045eb
7 files changed
+164 -17

No files matched your search

@@ -522,6 +522,7 @@ ReaderFooter.default_settings = {
progress_pct_format = "0",
pages_left_includes_current_page = false,
initial_marker = false,
invert_progress_direction = false,
}
function ReaderFooter:init()
@@ -2403,6 +2404,13 @@ function ReaderFooter:onToggleChapterProgressBar()
self:refreshFooter(true)
end
function ReaderFooter:invertProgressBar(invert_direction)
if self.progress_bar then
self.progress_bar.invert_direction = invert_direction
self:maybeUpdateFooter()
end
end
function ReaderFooter:getBookProgress()
if self.ui.document:hasHiddenFlows() then
local flow = self.ui.document:getPageFlow(self.pageno)
@@ -213,6 +213,7 @@ function ReaderMenu:setUpdateItemTable()
{
text = _("Save document settings as default"),
keep_menu_open = true,
separator = true,
callback = function()
UIManager:show(ConfirmBox:new{
text = _("Save current document settings as default values?"),
@@ -230,6 +231,51 @@ function ReaderMenu:setUpdateItemTable()
},
}
if not Device:isTouchDevice() then
-- This menu entry is a duplicate of the one found in page_turns for touch devices
-- but we need to add it here for non-touch devices.
table.insert(self.menu_items.document_settings.sub_item_table, {
text_func = function()
local text = _("Invert document-related dialogs")
if G_reader_settings:isTrue("invert_ui_layout") then
text = text .. " ★"
end
return text
end,
checked_func = function()
return self.view:shouldInvertBiDiLayoutMirroring()
end,
callback = function()
UIManager:broadcastEvent(Event:new("ToggleUILayoutMiroring"))
end,
hold_callback = function(touchmenu_instance)
local invert_ui_layout = G_reader_settings:isTrue("invert_ui_layout")
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
UIManager:show(MultiConfirmBox:new{
text = invert_ui_layout and _("The default (★) for newly opened books is to Invert document-related dialogs.\n\nWould you like to change it?")
or _("The default (★) for newly opened books is not to Invert document-related dialogs.\n\nWould you like to change it?"),
choice1_text_func = function()
return invert_ui_layout and _("Don't invert") or _("Don't invert") .." (★)"
end,
choice1_callback = function()
G_reader_settings:makeFalse("invert_ui_layout")
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
choice2_text_func = function()
return invert_ui_layout and _("Invert") .." (★)" or _("Invert")
end,
choice2_callback = function()
G_reader_settings:makeTrue("invert_ui_layout")
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
end,
help_text = _([[
When enabled the UI direction for the Table of Contents, Book Map, and Page Browser dialogs will mirror the default UI direction.
Useful when used alongside 'Invert page turns'.]]),
})
end
self.menu_items.page_overlap = dofile("frontend/ui/elements/page_overlap.lua")
-- settings tab
+19 -2
View File
@@ -993,6 +993,12 @@ function ReaderView:onReadSettings(config)
else
self.inverse_reading_order = G_reader_settings:isTrue("inverse_reading_order")
end
if config:has("invert_ui_layout") then
self.invert_ui_layout = config:isTrue("invert_ui_layout")
else
self.invert_ui_layout = G_reader_settings:isTrue("invert_ui_layout")
end
self.footer:invertProgressBar(self.invert_ui_layout)
self.page_overlap_enable = config:isTrue("show_overlap_enable") or G_reader_settings:isTrue("page_overlap_enable") or G_defaults:readSetting("DSHOWOVERLAP")
self.page_overlap_style = config:readSetting("page_overlap_style") or G_reader_settings:readSetting("page_overlap_style") or "dim"
self.page_gap.height = Screen:scaleBySize(config:readSetting("kopt_page_gap_height")
@@ -1001,8 +1007,18 @@ function ReaderView:onReadSettings(config)
end
function ReaderView:shouldInvertBiDiLayoutMirroring()
-- A few widgets may temporarily invert UI layout mirroring when both these settings are true
return self.inverse_reading_order and G_reader_settings:isTrue("invert_ui_layout_mirroring")
return self.invert_ui_layout
end
function ReaderView:onToggleUILayoutMiroring(toggle)
if toggle == nil then
toggle = not self.invert_ui_layout
end
if self.invert_ui_layout ~= toggle then
self.invert_ui_layout = toggle
self.footer:invertProgressBar(self.invert_ui_layout)
end
return true
end
function ReaderView:onPageUpdate(new_page_no)
@@ -1208,6 +1224,7 @@ function ReaderView:onSaveSettings()
self.document.configurable.rotation_mode = Screen:getRotationMode() -- will be saved by ReaderConfig
end
self.ui.doc_settings:saveSetting("inverse_reading_order", self.inverse_reading_order)
self.ui.doc_settings:saveSetting("invert_ui_layout", self.invert_ui_layout)
self.ui.doc_settings:saveSetting("show_overlap_enable", self.page_overlap_enable)
self.ui.doc_settings:saveSetting("page_overlap_style", self.page_overlap_style)
end
+34 -7
View File
@@ -1,4 +1,5 @@
local Device = require("device")
local Event = require("ui/event")
local ReaderUI = require("apps/reader/readerui")
local UIManager = require("ui/uimanager")
local _ = require("gettext")
@@ -151,18 +152,44 @@ local PageTurns = {
end,
},
{
text = _("Also invert document-related dialogs"),
checked_func = function()
return G_reader_settings:isTrue("invert_ui_layout_mirroring")
text_func = function()
local text = _("Invert document-related dialogs")
if G_reader_settings:isTrue("invert_ui_layout") then
text = text .. " ★"
end
return text
end,
enabled_func = function()
return ReaderUI.instance.view.inverse_reading_order
checked_func = function()
return ReaderUI.instance.view:shouldInvertBiDiLayoutMirroring()
end,
callback = function()
G_reader_settings:flipNilOrFalse("invert_ui_layout_mirroring")
UIManager:broadcastEvent(Event:new("ToggleUILayoutMiroring"))
end,
hold_callback = function(touchmenu_instance)
local invert_ui_layout = G_reader_settings:isTrue("invert_ui_layout")
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
UIManager:show(MultiConfirmBox:new{
text = invert_ui_layout and _("The default (★) for newly opened books is to Invert document-related dialogs.\n\nWould you like to change it?")
or _("The default (★) for newly opened books is not to Invert document-related dialogs.\n\nWould you like to change it?"),
choice1_text_func = function()
return invert_ui_layout and _("Don't invert") or _("Don't invert") .. " (★)"
end,
choice1_callback = function()
G_reader_settings:makeFalse("invert_ui_layout")
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
choice2_text_func = function()
return invert_ui_layout and _("Invert") .. " (★)" or _("Invert")
end,
choice2_callback = function()
G_reader_settings:makeTrue("invert_ui_layout")
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
end,
help_text = _([[
When enabled the UI direction for the Table of Contents, Book Map, and Page Browser dialogs will follow the page turn direction instead of the default UI direction.]]),
When enabled the UI direction for the Table of Contents, Book Map, and Page Browser dialogs will mirror the default UI direction.
Useful when used alongside 'Invert page turns'.]]),
separator = true,
},
Device:canDoSwipeAnimation() and {
+25 -4
View File
@@ -61,6 +61,7 @@ local ProgressWidget = Widget:extend{
_orig_bordersize = nil,
initial_pos_marker = false, -- overlay a marker at the initial percentage position
initial_percentage = nil,
invert_direction = false, -- manually invert the direction regardless of UI mirroring
}
function ProgressWidget:init()
@@ -125,6 +126,11 @@ function ProgressWidget:paintTo(bb, x, y)
if self.dimen.w == 0 or self.dimen.h == 0 then return end
local _mirroredUI = BD.mirroredUILayout()
-- Apply inversion if requested (XOR operation with mirrored UI)
if self.invert_direction then
_mirroredUI = not _mirroredUI
end
-- We'll draw every bar element in order, bottom to top.
local fill_width = my_size.w - 2*(self.margin_h + self.bordersize)
local fill_y = y + self.margin_v + self.bordersize
@@ -185,11 +191,20 @@ function ProgressWidget:paintTo(bb, x, y)
-- Overlay the initial position marker on top of that
if self.initial_pos_marker and self.initial_percentage >= 0 then
if self.height <= INITIAL_MARKER_HEIGHT_THRESHOLD then
self.initial_pos_icon:paintTo(bb, Math.round(fill_x + math.ceil(fill_width * self.initial_percentage) - self.height / 4), y - Math.round(self.height / 6))
local marker_x, icon_x, icon_y
if _mirroredUI then
marker_x = x + self.margin_h + self.bordersize + math.ceil(fill_width - (fill_width * self.initial_percentage))
else
self.initial_pos_icon:paintTo(bb, Math.round(fill_x + math.ceil(fill_width * self.initial_percentage) - self.height / 2), y)
marker_x = x + self.margin_h + self.bordersize + math.ceil(fill_width * self.initial_percentage)
end
if self.height <= INITIAL_MARKER_HEIGHT_THRESHOLD then
icon_x = Math.round(marker_x - self.height * (1/4))
icon_y = y - Math.round(self.height * (1/6))
else
icon_x = Math.round(marker_x - self.height * (1/2))
icon_y = y
end
self.initial_pos_icon:paintTo(bb, icon_x, icon_y)
end
end
@@ -229,7 +244,13 @@ function ProgressWidget:getPercentageFromPosition(pos)
if x < 0 or x > width then
return nil
end
if BD.mirroredUILayout() then
local mirrored = BD.mirroredUILayout()
-- Invert if requested
if self.invert_direction then
mirrored = not mirrored
end
if mirrored then
x = width - x
end
return x / width
+31 -4
View File
@@ -17,6 +17,7 @@ local UIManager = require("ui/uimanager")
local VerticalGroup = require("ui/widget/verticalgroup")
local VerticalSpan = require("ui/widget/verticalspan")
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local util = require("util")
local _ = require("gettext")
local Screen = Device.screen
@@ -80,6 +81,9 @@ function SkimToWidget:init()
self.curr_page = self.ui:getCurrentPage()
self.page_count = self.ui.document:getPageCount()
-- Determine if we need to invert the button functionality and labels
local invert_buttons = self.ui.view:shouldInvertBiDiLayoutMirroring()
self.progress_bar = ProgressWidget:new{
width = inner_width,
height = progress_bar_height,
@@ -89,6 +93,7 @@ function SkimToWidget:init()
last = self.page_count,
alt = self.ui.document.flows,
initial_pos_marker = true,
invert_direction = invert_buttons,
}
-- Bottom row buttons
@@ -176,13 +181,19 @@ function SkimToWidget:init()
}
-- Top row buttons
local chapter_next_text = " ▷▏"
local chapter_prev_text = "▕◁ "
local bookmark_next_text = "\u{F097}\u{202F}▷"
local bookmark_prev_text = "◁\u{202F}\u{F097}"
local chapter_prev_text = "\u{2595}\u{25C1}\u{2002}" -- ▕◁ (right one eighth block, white left-pointing triangle, en space)
local chapter_next_text = "\u{2002}\u{25B7}\u{258F}" -- ▷▏ (en space, white right-pointing triangle, left one eighth block)
local bookmark_prev_text = "\u{F097}\u{25C1}" -- ◁ (private use area character, white left-pointing triangle)
local bookmark_next_text = "\u{25B7}\u{F097}" -- ▷ (white right-pointing triangle, private use area character)
local bookmark_enabled_text = "\u{F02E}"
local bookmark_disabled_text = "\u{F097}"
if BD.mirroredUILayout() then
chapter_prev_text = BD.ltr(chapter_next_text)
-- (We need this trick to keep BiDi from reordering chapter_next_text's leading space in RTL)
chapter_next_text = "\u{2002}" .. BD.ltr("\u{2595}\u{25C1}")
bookmark_next_text, bookmark_prev_text = BD.ltr(bookmark_prev_text), BD.ltr(bookmark_next_text)
end
if invert_buttons then
chapter_next_text, chapter_prev_text = chapter_prev_text, chapter_next_text
bookmark_next_text, bookmark_prev_text = bookmark_prev_text, bookmark_next_text
end
@@ -302,6 +313,10 @@ function SkimToWidget:init()
button_plus_ten,
}
radius = Size.radius.window
if invert_buttons then
util.arrayReverse(top_buttons_row)
util.arrayReverse(bottom_buttons_row)
end
else
top_row_span = VerticalSpan:new{ width = Size.padding.default }
top_buttons_row = HorizontalGroup:new{
@@ -328,6 +343,9 @@ function SkimToWidget:init()
small_button_span,
button_plus,
}
if invert_buttons then
util.arrayReverse(top_buttons_row)
end
if skim_dialog_position == "top" then
bottom_row_span, bottom_buttons_row = top_row_span, top_buttons_row
top_buttons_row = VerticalSpan:new{ width = 0 }
@@ -375,6 +393,15 @@ function SkimToWidget:init()
self.current_page_text, button_orig_page, button_minus_ten, button_plus_ten, button_minus, button_plus },
}
end
-- Invert D-Pad navigation layout to match visual button order
if invert_buttons then
if full_mode then
util.arrayReverse(self.layout[1])
util.arrayReverse(self.layout[2])
else
util.arrayReverse(self.layout[1])
end
end
self:moveFocusTo(1, 1)
end
if Device:hasKeyboard() then
@@ -18,6 +18,7 @@ return {--do NOT change this line
--[[
["/mnt/us/documents/hebrew"] = {
["inverse_reading_order"] = true
["invert_ui_layout"] = true
},
["/mnt/onboard/smalltext"] = {
["copt_font_size"] = 34,