feat: add settings toggle button to hide/show toolbar buttons

This commit is contained in:
Developer
2026-05-24 07:40:21 +08:00
parent f95d1c418f
commit b8bdd97d80

View File

@@ -280,6 +280,9 @@ pub fn reading_view(
let sidebar_tab_id = ui.make_persistent_id("sidebar_tab");
let mut sidebar_tab: usize = ui.data_mut(|d| *d.get_temp_mut_or_default::<usize>(sidebar_tab_id));
let settings_visible_id = ui.make_persistent_id("settings_visible");
let mut settings_visible: bool = ui.data_mut(|d| *d.get_temp_mut_or_default::<bool>(settings_visible_id));
if *sidebar_open {
egui::SidePanel::left("toc_sidebar")
.resizable(true)
@@ -325,58 +328,64 @@ pub fn reading_view(
ui.label(format!("{}", &book.title));
ui.label(format!("[{}]", book.layout.label()));
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let (theme_icon, theme_hint) = match theme {
Theme::Dark => ("🌞", "切换到浅色主题"),
Theme::Light => ("🌙", "切换到夜间主题"),
Theme::Sepia => ("📜", "切换到棕褐色主题"),
};
if ui.button(theme_icon).on_hover_text(theme_hint).clicked() {
action.toggle_theme = true;
let toggle_label = if settings_visible { "⚙ ▲" } else { "" };
if ui.button(toggle_label).on_hover_text("显示/隐藏设置").clicked() {
settings_visible = !settings_visible;
}
let bookmark_icon = if has_bookmark { "🔴" } else { "🔖" };
let bookmark_hint = if has_bookmark { "移除书签" } else { "添加书签" };
if ui.button(bookmark_icon).on_hover_text(bookmark_hint).clicked() {
action.toggle_bookmark = true;
}
if ui.button("A⁻").on_hover_text("缩小字体").clicked() {
style.font_size = (style.font_size - 2.0).max(10.0);
}
if ui.button("A⁺").on_hover_text("放大字体").clicked() {
style.font_size = (style.font_size + 2.0).min(48.0);
}
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());
if settings_visible {
let (theme_icon, theme_hint) = match theme {
Theme::Dark => ("🌞", "切换到浅色主题"),
Theme::Light => ("🌙", "切换到夜间主题"),
Theme::Sepia => ("📜", "切换到棕褐色主题"),
};
if ui.button(theme_icon).on_hover_text(theme_hint).clicked() {
action.toggle_theme = true;
}
let bookmark_icon = if has_bookmark { "🔴" } else { "🔖" };
let bookmark_hint = if has_bookmark { "移除书签" } else { "添加书签" };
if ui.button(bookmark_icon).on_hover_text(bookmark_hint).clicked() {
action.toggle_bookmark = true;
}
if ui.button("A⁻").on_hover_text("缩小字体").clicked() {
style.font_size = (style.font_size - 2.0).max(10.0);
}
if ui.button("A⁺").on_hover_text("放大字体").clicked() {
style.font_size = (style.font_size + 2.0).min(48.0);
}
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());
}
}
}
});
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));
});
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));
}
}
}
});
egui::ComboBox::from_id_salt("font_selector")
.width(100.0)
.selected_text(current_font)
.show_ui(ui, |ui| {
for name in crate::font::font_display_names() {
let selected = name == current_font;
if ui.selectable_label(selected, &name).clicked() {
action.switch_font = Some(name);
});
egui::ComboBox::from_id_salt("font_selector")
.width(100.0)
.selected_text(current_font)
.show_ui(ui, |ui| {
for name in crate::font::font_display_names() {
let selected = name == current_font;
if ui.selectable_label(selected, &name).clicked() {
action.switch_font = Some(name);
}
}
}
});
});
}
if ui.button("").on_hover_text("打开/关闭目录").clicked() {
*sidebar_open = !*sidebar_open;
}