fix: replace profile cycle button with ComboBox for instant style switching

This commit is contained in:
Developer
2026-05-14 21:08:31 +08:00
parent 7d056e2670
commit 515ec0e07d
2 changed files with 29 additions and 14 deletions

View File

@@ -191,6 +191,7 @@ impl eframe::App for App {
let mut style = self.active_profile().clone();
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();
egui::CentralPanel::default().show(ctx, |ui| {
let book = self.state.book.as_mut().unwrap();
@@ -205,6 +206,7 @@ impl eframe::App for App {
&file_path,
self.kraft_texture.as_ref(),
use_kraft,
&profile_names,
);
if action.go_back {
@@ -214,12 +216,19 @@ impl eframe::App for App {
self.state.current_page = 0;
}
if action.cycle_profile {
let idx = self.settings.profiles.iter()
.position(|p| p.name == self.settings.active_profile)
.unwrap_or(0);
let next = (idx + 1) % self.settings.profiles.len();
self.settings.active_profile = self.settings.profiles[next].name.clone();
// Switch profile immediately: copy all settings from the selected profile
if let Some(ref target) = action.switch_to_profile {
if let Some(profile) = self.settings.profiles.iter()
.find(|p| p.name == *target)
{
style.alignment = profile.alignment;
style.line_spacing = profile.line_spacing;
style.paragraph_spacing = profile.paragraph_spacing;
style.first_line_indent = profile.first_line_indent;
style.font_size = profile.font_size;
style.name = profile.name.clone();
self.settings.active_profile = profile.name.clone();
}
}
if action.toggle_kraft_bg {

View File

@@ -26,7 +26,7 @@ pub struct ReaderAction {
pub toggle_theme: bool,
pub toggle_bookmark: bool,
pub toggle_kraft_bg: bool,
pub cycle_profile: bool,
pub switch_to_profile: Option<String>,
pub page_next: bool,
pub page_prev: bool,
}
@@ -42,13 +42,14 @@ pub fn reading_view(
_file_path: &str,
kraft_texture: Option<&egui::TextureHandle>,
use_kraft_bg: bool,
profile_names: &[String],
) -> ReaderAction {
let mut action = ReaderAction {
go_back: false,
toggle_theme: false,
toggle_bookmark: false,
toggle_kraft_bg: false,
cycle_profile: false,
switch_to_profile: None,
page_next: false,
page_prev: false,
};
@@ -98,12 +99,17 @@ pub fn reading_view(
if ui.button("A⁺").on_hover_text("放大字体").clicked() {
style.font_size = (style.font_size + 2.0).min(48.0);
}
if ui.button(&style.name)
.on_hover_text(format!("样式: {} (点击切换)", style.name))
.clicked()
{
action.cycle_profile = true;
}
egui::ComboBox::from_id_salt("profile_selector")
.width(110.0)
.selected_text(&style.name)
.show_ui(ui, |ui| {
for name in profile_names {
let selected = *name == style.name;
if ui.selectable_label(selected, name).clicked() {
action.switch_to_profile = Some(name.clone());
}
}
});
let kraft_icon = if use_kraft_bg { "📄" } else { "📋" };
if ui.button(kraft_icon).on_hover_text("牛皮纸背景").clicked() {
action.toggle_kraft_bg = true;