feat(bg): multi-background support with kraft, manuscript, composition, and custom image

This commit is contained in:
Developer
2026-05-14 23:19:14 +08:00
parent a82fa6b7b6
commit 88f15d307a
6 changed files with 757 additions and 109 deletions

View File

@@ -1,7 +1,7 @@
use eframe::egui;
use crate::book::Book;
use crate::style::{StyleProfile, TextAlignment};
use crate::theme::{self, Theme};
use crate::theme::{self, BgType, Theme};
pub fn recalculate_pages(book: &mut Book, font_size: f32, line_height: f32, panel_width: f32, panel_height: f32) {
let char_width = font_size * 0.6;
@@ -25,7 +25,7 @@ pub struct ReaderAction {
pub go_back: bool,
pub toggle_theme: bool,
pub toggle_bookmark: bool,
pub toggle_kraft_bg: bool,
pub switch_bg: Option<BgType>,
pub switch_to_profile: Option<String>,
pub page_next: bool,
pub page_prev: bool,
@@ -39,7 +39,7 @@ pub fn reading_view(
sidebar_open: &mut bool,
style: &mut StyleProfile,
theme: &Theme,
use_kraft_bg: bool,
bg_type: BgType,
_file_path: &str,
profile_names: &[String],
) -> ReaderAction {
@@ -47,7 +47,7 @@ pub fn reading_view(
go_back: false,
toggle_theme: false,
toggle_bookmark: false,
toggle_kraft_bg: false,
switch_bg: None,
switch_to_profile: None,
page_next: false,
page_prev: false,
@@ -108,10 +108,17 @@ pub fn reading_view(
}
}
});
let kraft_icon = if use_kraft_bg { "📄" } else { "📋" };
if ui.button(kraft_icon).on_hover_text("牛皮纸背景").clicked() {
action.toggle_kraft_bg = true;
}
egui::ComboBox::from_id_salt("bg_type_selector")
.width(100.0)
.selected_text(bg_type.label())
.show_ui(ui, |ui| {
for &label in BgType::ALL.iter() {
let selected = bg_type.label() == label;
if ui.selectable_label(selected, label).clicked() {
action.switch_bg = Some(theme::BgType::from_label(label));
}
}
});
if ui.button("").on_hover_text("打开/关闭目录").clicked() {
*sidebar_open = !*sidebar_open;
}