Compare commits
2 Commits
579aace306
...
a663de3ca0
| Author | SHA1 | Date | |
|---|---|---|---|
| a663de3ca0 | |||
| 61575fbf65 |
40
src/app.rs
40
src/app.rs
@ -15,7 +15,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use egui::{
|
use egui::{
|
||||||
Align, Button, Context, FontData, FontDefinitions, FontId, Image, Key, Modifiers,
|
Align, Button, Context, FontData, FontDefinitions, FontId, Image, Key, Modifiers,
|
||||||
PointerButton, RichText, ScrollArea, Widget, include_image,
|
PointerButton, RichText, ScrollArea, Theme, Widget, include_image,
|
||||||
};
|
};
|
||||||
use eyre::eyre;
|
use eyre::eyre;
|
||||||
|
|
||||||
@ -202,24 +202,26 @@ impl App {
|
|||||||
cc.egui_ctx.set_fonts(fonts);
|
cc.egui_ctx.set_fonts(fonts);
|
||||||
|
|
||||||
// markdown font styles
|
// markdown font styles
|
||||||
cc.egui_ctx.style_mut(|style| {
|
for theme in [Theme::Dark, Theme::Light] {
|
||||||
for (name, size) in [
|
cc.egui_ctx.style_mut_of(theme, |style| {
|
||||||
("H1", 28.0),
|
for (name, size) in [
|
||||||
("H2", 26.0),
|
("H1", 28.0),
|
||||||
("H3", 24.0),
|
("H2", 26.0),
|
||||||
("H4", 22.0),
|
("H3", 24.0),
|
||||||
("H5", 20.0),
|
("H4", 22.0),
|
||||||
("H6", 18.0),
|
("H5", 20.0),
|
||||||
] {
|
("H6", 18.0),
|
||||||
style.text_styles.insert(
|
] {
|
||||||
egui::TextStyle::Name(name.into()),
|
style.text_styles.insert(
|
||||||
FontId {
|
egui::TextStyle::Name(name.into()),
|
||||||
size,
|
FontId {
|
||||||
family: egui::FontFamily::Proportional,
|
size,
|
||||||
},
|
family: egui::FontFamily::Proportional,
|
||||||
);
|
},
|
||||||
}
|
);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// enable features on egui_extras to add more image types
|
// enable features on egui_extras to add more image types
|
||||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use egui::{Color32, Context, RichText, Theme, Ui, Visuals};
|
use egui::{Color32, Context, RichText, Theme, Ui, Visuals, style::ScrollAnimation};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
@ -14,7 +14,7 @@ pub struct Preferences {
|
|||||||
pub hide_handwriting_cursor: bool,
|
pub hide_handwriting_cursor: bool,
|
||||||
|
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
has_applied_theme: bool,
|
has_applied_prefs: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Preferences {
|
impl Default for Preferences {
|
||||||
@ -22,7 +22,7 @@ impl Default for Preferences {
|
|||||||
Self {
|
Self {
|
||||||
animations: true,
|
animations: true,
|
||||||
high_contrast: false,
|
high_contrast: false,
|
||||||
has_applied_theme: false,
|
has_applied_prefs: false,
|
||||||
hide_handwriting_cursor: false,
|
hide_handwriting_cursor: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,8 +31,20 @@ impl Default for Preferences {
|
|||||||
impl Preferences {
|
impl Preferences {
|
||||||
/// Apply preferences, if they haven't already been applied.
|
/// Apply preferences, if they haven't already been applied.
|
||||||
pub fn apply(&mut self, ctx: &Context) {
|
pub fn apply(&mut self, ctx: &Context) {
|
||||||
if !self.has_applied_theme {
|
if !self.has_applied_prefs {
|
||||||
self.has_applied_theme = true;
|
self.has_applied_prefs = true;
|
||||||
|
|
||||||
|
let scroll_animation = if self.animations {
|
||||||
|
ScrollAnimation::default()
|
||||||
|
} else {
|
||||||
|
ScrollAnimation::none()
|
||||||
|
};
|
||||||
|
|
||||||
|
for theme in [Theme::Dark, Theme::Light] {
|
||||||
|
ctx.style_mut_of(theme, |style| {
|
||||||
|
style.scroll_animation = scroll_animation;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let mut dark_visuals = Visuals::dark();
|
let mut dark_visuals = Visuals::dark();
|
||||||
let mut light_visuals = Visuals::light();
|
let mut light_visuals = Visuals::light();
|
||||||
@ -71,11 +83,15 @@ impl Preferences {
|
|||||||
pub fn show(&mut self, ui: &mut Ui) {
|
pub fn show(&mut self, ui: &mut Ui) {
|
||||||
ui.label(RichText::new("Prefs").weak());
|
ui.label(RichText::new("Prefs").weak());
|
||||||
|
|
||||||
ui.toggle_value(&mut self.animations, "Animations");
|
let animations_toggle = ui.toggle_value(&mut self.animations, "Animations");
|
||||||
|
if animations_toggle.clicked() {
|
||||||
|
self.has_applied_prefs = false;
|
||||||
|
self.apply(ui.ctx());
|
||||||
|
}
|
||||||
|
|
||||||
let high_contrast_toggle = ui.toggle_value(&mut self.high_contrast, "High Contrast");
|
let high_contrast_toggle = ui.toggle_value(&mut self.high_contrast, "High Contrast");
|
||||||
if high_contrast_toggle.clicked() {
|
if high_contrast_toggle.clicked() {
|
||||||
self.has_applied_theme = false;
|
self.has_applied_prefs = false;
|
||||||
self.apply(ui.ctx());
|
self.apply(ui.ctx());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user