fix(pagination): recalculate with exact text_rect dims inside CentralPanel, validate current_page

This commit is contained in:
Developer
2026-05-15 20:05:34 +08:00
parent 1cb0c2aef2
commit 0d0700cf89

View File

@@ -58,14 +58,9 @@ pub fn reading_view(
};
let mut jump_to_bookmark: Option<usize> = None;
let colors = theme::reader_colors(theme);
let colors = theme::reader_colors(theme);
// 工具栏之前预估文本区尺寸完成分页(扣除边距 48px + 工具条 ~60px
let panel_size = ui.available_size();
let est_width = (panel_size.x - 48.0).max(100.0);
let est_height = (panel_size.y - 60.0).max(200.0);
recalculate_pages(book, style.font_size, style.line_height(), est_width, est_height);
let has_bookmark = bookmarks.iter().any(|b| b.section == *current_section && b.page == *current_page);
let has_bookmark = bookmarks.iter().any(|b| b.section == *current_section && b.page == *current_page);
// --- Sidebar (TOC + Bookmarks) ---
let sidebar_tab_id = ui.make_persistent_id("sidebar_tab");
@@ -229,6 +224,17 @@ egui::ComboBox::from_id_salt("bg_type_selector")
egui::vec2((rect.width() - inset * 2.0).max(100.0), rect.height()),
);
// 用实际文本区宽高重新分页(包含侧边栏、工具条等已占空间后的精确值)
recalculate_pages(book, style.font_size, style.line_height(), text_rect.width(), text_rect.height());
// 确保 current_page 在新分页后仍在有效范围内
if let Some(section) = book.sections.get(*current_section) {
let max_page = section.pages.len().saturating_sub(2);
if *current_page > max_page {
*current_page = max_page;
}
}
if let Some(section) = book.sections.get(*current_section) {
if *current_page < section.pages.len().saturating_sub(1) {
let start = section.pages[*current_page];