fix: replace profile cycle button with ComboBox for instant style switching
This commit is contained in:
21
src/app.rs
21
src/app.rs
@@ -191,6 +191,7 @@ 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 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| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
let book = self.state.book.as_mut().unwrap();
|
let book = self.state.book.as_mut().unwrap();
|
||||||
@@ -205,6 +206,7 @@ impl eframe::App for App {
|
|||||||
&file_path,
|
&file_path,
|
||||||
self.kraft_texture.as_ref(),
|
self.kraft_texture.as_ref(),
|
||||||
use_kraft,
|
use_kraft,
|
||||||
|
&profile_names,
|
||||||
);
|
);
|
||||||
|
|
||||||
if action.go_back {
|
if action.go_back {
|
||||||
@@ -214,12 +216,19 @@ impl eframe::App for App {
|
|||||||
self.state.current_page = 0;
|
self.state.current_page = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if action.cycle_profile {
|
// Switch profile immediately: copy all settings from the selected profile
|
||||||
let idx = self.settings.profiles.iter()
|
if let Some(ref target) = action.switch_to_profile {
|
||||||
.position(|p| p.name == self.settings.active_profile)
|
if let Some(profile) = self.settings.profiles.iter()
|
||||||
.unwrap_or(0);
|
.find(|p| p.name == *target)
|
||||||
let next = (idx + 1) % self.settings.profiles.len();
|
{
|
||||||
self.settings.active_profile = self.settings.profiles[next].name.clone();
|
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 {
|
if action.toggle_kraft_bg {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ pub struct ReaderAction {
|
|||||||
pub toggle_theme: bool,
|
pub toggle_theme: bool,
|
||||||
pub toggle_bookmark: bool,
|
pub toggle_bookmark: bool,
|
||||||
pub toggle_kraft_bg: bool,
|
pub toggle_kraft_bg: bool,
|
||||||
pub cycle_profile: bool,
|
pub switch_to_profile: Option<String>,
|
||||||
pub page_next: bool,
|
pub page_next: bool,
|
||||||
pub page_prev: bool,
|
pub page_prev: bool,
|
||||||
}
|
}
|
||||||
@@ -42,13 +42,14 @@ pub fn reading_view(
|
|||||||
_file_path: &str,
|
_file_path: &str,
|
||||||
kraft_texture: Option<&egui::TextureHandle>,
|
kraft_texture: Option<&egui::TextureHandle>,
|
||||||
use_kraft_bg: bool,
|
use_kraft_bg: bool,
|
||||||
|
profile_names: &[String],
|
||||||
) -> ReaderAction {
|
) -> ReaderAction {
|
||||||
let mut action = ReaderAction {
|
let mut action = ReaderAction {
|
||||||
go_back: false,
|
go_back: false,
|
||||||
toggle_theme: false,
|
toggle_theme: false,
|
||||||
toggle_bookmark: false,
|
toggle_bookmark: false,
|
||||||
toggle_kraft_bg: false,
|
toggle_kraft_bg: false,
|
||||||
cycle_profile: false,
|
switch_to_profile: None,
|
||||||
page_next: false,
|
page_next: false,
|
||||||
page_prev: false,
|
page_prev: false,
|
||||||
};
|
};
|
||||||
@@ -98,12 +99,17 @@ pub fn reading_view(
|
|||||||
if ui.button("A⁺").on_hover_text("放大字体").clicked() {
|
if ui.button("A⁺").on_hover_text("放大字体").clicked() {
|
||||||
style.font_size = (style.font_size + 2.0).min(48.0);
|
style.font_size = (style.font_size + 2.0).min(48.0);
|
||||||
}
|
}
|
||||||
if ui.button(&style.name)
|
egui::ComboBox::from_id_salt("profile_selector")
|
||||||
.on_hover_text(format!("样式: {} (点击切换)", style.name))
|
.width(110.0)
|
||||||
.clicked()
|
.selected_text(&style.name)
|
||||||
{
|
.show_ui(ui, |ui| {
|
||||||
action.cycle_profile = true;
|
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 { "📋" };
|
let kraft_icon = if use_kraft_bg { "📄" } else { "📋" };
|
||||||
if ui.button(kraft_icon).on_hover_text("牛皮纸背景").clicked() {
|
if ui.button(kraft_icon).on_hover_text("牛皮纸背景").clicked() {
|
||||||
action.toggle_kraft_bg = true;
|
action.toggle_kraft_bg = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user