fix(styling): fullscreen kraft paper bg, persistence preset refresh, reader cleanup
This commit is contained in:
@@ -1,2 +1,6 @@
|
|||||||
[target.x86_64-pc-windows-gnu]
|
[target.x86_64-pc-windows-gnu]
|
||||||
rustflags = ["-C", "target-feature=+crt-static"]
|
rustflags = ["-C", "target-feature=+crt-static"]
|
||||||
|
linker = "x86_64-w64-mingw32-gcc"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER = "x86_64-w64-mingw32-gcc"
|
||||||
|
|||||||
24
src/app.rs
24
src/app.rs
@@ -178,6 +178,26 @@ impl App {
|
|||||||
|
|
||||||
impl eframe::App for App {
|
impl eframe::App for App {
|
||||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||||
|
let use_kraft = self.settings.use_kraft_bg;
|
||||||
|
|
||||||
|
// 牛皮纸模式:全窗口绘制纹理 + 面板透明
|
||||||
|
if use_kraft {
|
||||||
|
if let Some(texture) = &self.kraft_texture {
|
||||||
|
ctx.style_mut(|s| {
|
||||||
|
s.visuals.panel_fill = egui::Color32::TRANSPARENT;
|
||||||
|
s.visuals.window_fill = egui::Color32::TRANSPARENT;
|
||||||
|
s.visuals.faint_bg_color = egui::Color32::TRANSPARENT;
|
||||||
|
});
|
||||||
|
let viewport_rect =
|
||||||
|
ctx.input(|i| i.screen_rect());
|
||||||
|
crate::texture::draw_tiled_bg(
|
||||||
|
&ctx.layer_painter(egui::LayerId::background()),
|
||||||
|
viewport_rect,
|
||||||
|
texture,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if self.state.book.is_none() {
|
if self.state.book.is_none() {
|
||||||
self.welcome_view(ctx);
|
self.welcome_view(ctx);
|
||||||
return;
|
return;
|
||||||
@@ -190,7 +210,6 @@ impl eframe::App for App {
|
|||||||
|
|
||||||
let mut style = self.active_profile().clone();
|
let mut style = self.active_profile().clone();
|
||||||
let theme_copy = self.settings.theme;
|
let theme_copy = self.settings.theme;
|
||||||
let use_kraft = self.settings.use_kraft_bg;
|
|
||||||
let profile_names: Vec<String> = self.settings.profiles.iter().map(|p| p.name.clone()).collect();
|
let profile_names: Vec<String> = self.settings.profiles.iter().map(|p| p.name.clone()).collect();
|
||||||
|
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
@@ -203,9 +222,8 @@ impl eframe::App for App {
|
|||||||
&mut self.state.sidebar_open,
|
&mut self.state.sidebar_open,
|
||||||
&mut style,
|
&mut style,
|
||||||
&theme_copy,
|
&theme_copy,
|
||||||
&file_path,
|
|
||||||
self.kraft_texture.as_ref(),
|
|
||||||
use_kraft,
|
use_kraft,
|
||||||
|
&file_path,
|
||||||
&profile_names,
|
&profile_names,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,20 @@ pub fn load_settings(dir: &Path) -> Result<Settings, String> {
|
|||||||
let path = dir.join(SETTINGS_FILE);
|
let path = dir.join(SETTINGS_FILE);
|
||||||
let json = std::fs::read_to_string(&path)
|
let json = std::fs::read_to_string(&path)
|
||||||
.map_err(|e| format!("读取设置失败: {}", e))?;
|
.map_err(|e| format!("读取设置失败: {}", e))?;
|
||||||
serde_json::from_str(&json)
|
let mut settings: Settings = serde_json::from_str(&json)
|
||||||
.map_err(|e| format!("解析设置失败: {}", e))
|
.map_err(|e| format!("解析设置失败: {}", e))?;
|
||||||
|
// Always refresh profiles from code-defined presets so that updated
|
||||||
|
// preset values (font size, spacing, etc.) take effect even when
|
||||||
|
// an older settings.json is present on disk.
|
||||||
|
let preset_names: Vec<String> = crate::style::StyleProfile::presets()
|
||||||
|
.iter()
|
||||||
|
.map(|p| p.name.clone())
|
||||||
|
.collect();
|
||||||
|
settings.profiles = crate::style::StyleProfile::presets();
|
||||||
|
if !preset_names.contains(&settings.active_profile) {
|
||||||
|
settings.active_profile = "Kindle 默认".into();
|
||||||
|
}
|
||||||
|
Ok(settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -39,9 +39,8 @@ pub fn reading_view(
|
|||||||
sidebar_open: &mut bool,
|
sidebar_open: &mut bool,
|
||||||
style: &mut StyleProfile,
|
style: &mut StyleProfile,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
_file_path: &str,
|
|
||||||
kraft_texture: Option<&egui::TextureHandle>,
|
|
||||||
use_kraft_bg: bool,
|
use_kraft_bg: bool,
|
||||||
|
_file_path: &str,
|
||||||
profile_names: &[String],
|
profile_names: &[String],
|
||||||
) -> ReaderAction {
|
) -> ReaderAction {
|
||||||
let mut action = ReaderAction {
|
let mut action = ReaderAction {
|
||||||
@@ -185,13 +184,6 @@ pub fn reading_view(
|
|||||||
let available = ui.available_size();
|
let available = ui.available_size();
|
||||||
let (rect, response) = ui.allocate_at_least(available, egui::Sense::click());
|
let (rect, response) = ui.allocate_at_least(available, egui::Sense::click());
|
||||||
|
|
||||||
// Draw kraft paper background if enabled
|
|
||||||
if use_kraft_bg {
|
|
||||||
if let Some(tex) = kraft_texture {
|
|
||||||
crate::texture::draw_tiled_bg(ui.painter(), rect, tex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add reading margins (inset)
|
// Add reading margins (inset)
|
||||||
let inset = 24.0;
|
let inset = 24.0;
|
||||||
let text_rect = egui::Rect::from_min_size(
|
let text_rect = egui::Rect::from_min_size(
|
||||||
|
|||||||
Reference in New Issue
Block a user