Forked from IntrovertedMage/2-change-status-bar-color.lua
Last active
September 11, 2025 00:57
-
-
Save mallomar/d2bb1c89c1397d2d2c4481edf9d6f8e6 to your computer and use it in GitHub Desktop.
Modifies Status Bar patch by @IntrovertedMage to make it look like Alt-Status Bar: https://gist.github.com/IntrovertedMage/d759ff214f799cfb5e1f8c85daab6cae Introverted Mage's Patch has code from @sebdelsol https://gist.github.com/sebdelsol/eba2e492473ac1f9e0ecb003d403b7de
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local readerFooter = require("apps/reader/modules/readerfooter") | |
| local ProgressWidget = require("ui/widget/progresswidget") | |
| local BD = require("ui/bidi") | |
| local Blitbuffer = require("ffi/blitbuffer") | |
| local Geom = require("ui/geometry") | |
| local Math = require("optmath") | |
| local Screen = require("device").screen | |
| -- Threshold for initial position marker | |
| local INITIAL_MARKER_HEIGHT_THRESHOLD = Screen:scaleBySize(12) | |
| -- Progress bar colors | |
| local PROGRESS_FILL_COLOR = Blitbuffer.colorFromString("#00AA00") -- Darker, more saturated green | |
| local PROGRESS_BORDER_COLOR = Blitbuffer.COLOR_BLACK | |
| local PROGRESS_BG_COLOR = Blitbuffer.COLOR_WHITE | |
| -- Chapter icon colors | |
| local CHAPTER_ICON_COLOR = Blitbuffer.COLOR_BLACK | |
| local CHAPTER_TEXT_COLOR = Blitbuffer.COLOR_BLACK | |
| -- Initialize reader footer with custom progress bar settings | |
| local original_init = readerFooter.init | |
| function readerFooter:init() | |
| original_init(self) | |
| -- Override progress bar colors | |
| if self.progress_bar then | |
| self.progress_bar.fillcolor = PROGRESS_FILL_COLOR | |
| self.progress_bar.bordercolor = PROGRESS_BORDER_COLOR | |
| self.progress_bar.bgcolor = PROGRESS_BG_COLOR | |
| self.progress_bar.is_footer_progress = true | |
| if self.progress_bar.tick_color then | |
| self.progress_bar.tick_color = CHAPTER_ICON_COLOR | |
| end | |
| end | |
| -- Apply colors to chapter-related elements | |
| if self.chapter_icons then | |
| for _, icon in ipairs(self.chapter_icons) do | |
| if icon.color then | |
| icon.color = CHAPTER_ICON_COLOR | |
| end | |
| end | |
| end | |
| if self.chapter_text_color then | |
| self.chapter_text_color = CHAPTER_TEXT_COLOR | |
| end | |
| if self.settings and self.settings.progress_bar then | |
| self.settings.progress_bar.bordercolor = PROGRESS_BORDER_COLOR | |
| self.settings.progress_bar.fillcolor = PROGRESS_FILL_COLOR | |
| self.settings.progress_bar.bgcolor = PROGRESS_BG_COLOR | |
| end | |
| end | |
| -- Store the original paintTo method | |
| local orig_ProgressWidget_paintTo = ProgressWidget.paintTo | |
| -- Override paintTo to apply custom rendering for book view bottom status bar | |
| function ProgressWidget:paintTo(bb, x, y) | |
| local my_size = self:getSize() | |
| if not self.dimen then | |
| self.dimen = Geom:new{ | |
| x = x, y = y, | |
| w = my_size.w, | |
| h = my_size.h | |
| } | |
| else | |
| self.dimen.x = x | |
| self.dimen.y = y | |
| end | |
| if self.dimen.w == 0 or self.dimen.h == 0 then return end | |
| -- Force our colors | |
| self.fillcolor = PROGRESS_FILL_COLOR | |
| self.bordercolor = PROGRESS_BORDER_COLOR | |
| self.bgcolor = PROGRESS_BG_COLOR | |
| self.tick_color = CHAPTER_ICON_COLOR | |
| -- Detect book view bottom status bar | |
| local screen_height = Screen:getHeight() | |
| local screen_width = Screen:getWidth() | |
| local is_in_bottom_area = y > (screen_height * 0.9) -- Bottom 10% of screen | |
| local is_reasonably_wide = my_size.w > (screen_width * 0.3) -- At least 30% screen width | |
| local is_thin = my_size.h <= 35 -- Handles both windowed and maximized heights | |
| local is_near_left_edge = x < 50 -- Within 50 pixels of left edge | |
| local is_book_bottom_status = is_in_bottom_area and is_reasonably_wide and is_thin and is_near_left_edge | |
| local _mirroredUI = BD.mirroredUILayout() | |
| local fill_width = my_size.w - 2*(self.margin_h + self.bordersize) | |
| local fill_y = y + self.margin_v + self.bordersize | |
| local fill_height = my_size.h - 2*(self.margin_v + self.bordersize) | |
| if is_book_bottom_status then | |
| -- Custom rendering for book view bottom status bar - NO BORDER OR BACKGROUND | |
| -- Skip all border/background rendering | |
| else | |
| -- Standard rendering for all other progress bars | |
| if self.radius == 0 then | |
| bb:paintRect(x, y, my_size.w, my_size.h, self.bordercolor) | |
| bb:paintRect(x + self.margin_h + self.bordersize, | |
| fill_y, | |
| math.ceil(fill_width), | |
| math.ceil(fill_height), | |
| self.bgcolor) | |
| else | |
| bb:paintRoundedRect(x, y, my_size.w, my_size.h, self.bgcolor, self.radius) | |
| bb:paintBorder(math.floor(x), math.floor(y), | |
| my_size.w, my_size.h, | |
| self.bordersize, self.bordercolor, self.radius) | |
| end | |
| end | |
| -- Fill bar for alternate pages | |
| if self.alt and self.alt[1] ~= nil then | |
| for i=1, #self.alt do | |
| local tick_x = fill_width * ((self.alt[i][1] - 1) / self.last) | |
| local width = fill_width * (self.alt[i][2] / self.last) | |
| if _mirroredUI then | |
| tick_x = fill_width - tick_x - width | |
| end | |
| tick_x = math.floor(tick_x) | |
| width = math.ceil(width) | |
| bb:paintRectRGB32(x + self.margin_h + self.bordersize + tick_x, | |
| fill_y, | |
| width, | |
| math.ceil(fill_height), | |
| self.altcolor or CHAPTER_ICON_COLOR) | |
| end | |
| end | |
| -- Main fill bar | |
| if self.percentage >= 0 and self.percentage <= 1 then | |
| local fill_x = x + self.margin_h + self.bordersize | |
| local progress_width = math.ceil(fill_width * self.percentage) | |
| if self.fill_from_right or (_mirroredUI and not self.fill_from_right) then | |
| fill_x = fill_x + (fill_width * (1 - self.percentage)) | |
| fill_x = math.floor(fill_x) | |
| end | |
| if is_book_bottom_status then | |
| -- Custom progress rendering for book view bottom status bar | |
| local page_width = screen_width | |
| local page_fill_x = 0 | |
| local actual_progress_width = math.ceil(page_width * self.percentage) | |
| -- Draw 7-pixel high green progress bar | |
| local bar_height = 7 | |
| local bar_y = y + (my_size.h - bar_height) / 2 | |
| bb:paintRectRGB32(page_fill_x, | |
| math.floor(bar_y), | |
| actual_progress_width, | |
| bar_height, | |
| self.fillcolor) | |
| -- Draw 1-pixel horizontal line for unread portion | |
| if self.percentage < 1.0 then | |
| local unread_start_x = page_fill_x + actual_progress_width | |
| local unread_end_x = page_width | |
| local unread_width = unread_end_x - unread_start_x | |
| local thin_line_height = 1 | |
| local thin_line_y = y + (my_size.h - thin_line_height) / 2 | |
| if unread_width > 0 then | |
| bb:paintRect(unread_start_x, math.floor(thin_line_y), unread_width, thin_line_height, self.bordercolor) | |
| end | |
| end | |
| else | |
| -- Standard progress rendering | |
| bb:paintRectRGB32(fill_x, | |
| y + self.bordersize, | |
| progress_width, | |
| my_size.h - 2 * self.bordersize, | |
| self.fillcolor) | |
| end | |
| -- Initial position marker | |
| 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)) | |
| else | |
| self.initial_pos_icon:paintTo(bb, Math.round(fill_x + math.ceil(fill_width * self.initial_percentage) - self.height / 2), y) | |
| end | |
| end | |
| end | |
| -- Chapter ticks | |
| if self.ticks and self.last and self.last > 0 then | |
| -- Find the last read chapter | |
| local last_read_tick_index = nil | |
| for i, tick in ipairs(self.ticks) do | |
| local tick_position_percentage = tick / self.last | |
| if self.percentage >= tick_position_percentage then | |
| last_read_tick_index = i | |
| end | |
| end | |
| for i, tick in ipairs(self.ticks) do | |
| local tick_x = fill_width * (tick / self.last) | |
| if _mirroredUI then | |
| tick_x = fill_width - tick_x | |
| end | |
| tick_x = math.floor(tick_x) | |
| local thick_tick_width = math.max(2, math.floor(self.bordersize)) | |
| -- Determine tick color | |
| local tick_position_percentage = tick / self.last | |
| local is_read = self.percentage >= tick_position_percentage | |
| local is_last_read = (i == last_read_tick_index) | |
| local tick_color | |
| if is_read then | |
| if is_last_read then | |
| tick_color = CHAPTER_ICON_COLOR -- Black for last read | |
| else | |
| tick_color = Blitbuffer.COLOR_WHITE -- White for other read chapters | |
| end | |
| else | |
| tick_color = CHAPTER_ICON_COLOR -- Black for unread chapters | |
| end | |
| if is_book_bottom_status then | |
| -- Full page width tick rendering | |
| local page_width = screen_width | |
| local page_tick_x = page_width * (tick / self.last) | |
| if _mirroredUI then | |
| page_tick_x = page_width - page_tick_x | |
| end | |
| page_tick_x = math.floor(page_tick_x) | |
| if not is_read then | |
| -- Unread ticks: 7 pixels high, centered | |
| local unread_tick_height = 7 | |
| local unread_tick_y = y + (my_size.h - unread_tick_height) / 2 | |
| bb:paintRect(page_tick_x, | |
| math.floor(unread_tick_y), | |
| thick_tick_width, | |
| unread_tick_height, | |
| tick_color) | |
| else | |
| -- Read ticks: extend through green bar area | |
| local green_bar_height = 7 | |
| local green_bar_y = y + (my_size.h - green_bar_height) / 2 | |
| bb:paintRect(page_tick_x, | |
| math.floor(green_bar_y), | |
| thick_tick_width, | |
| green_bar_height, | |
| tick_color) | |
| end | |
| else | |
| -- Standard tick rendering | |
| bb:paintRect(x + self.margin_h + self.bordersize + tick_x, | |
| y, | |
| thick_tick_width, | |
| my_size.h, | |
| tick_color) | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment