commit a24bd4cc4369fb2d806d3ffb8da2893f1d5c28c6
parent 35138cd951eafcbf284114433dcece4364185cac
Author: kernelkind <kernelkind@gmail.com>
Date: Mon, 9 Dec 2024 16:34:46 -0500
fix crash on AccountsView
It appears that Context::set_style doesn't keep the style changes from
the Damus constructor to the update method, but
`Context::all_styles_mut` does
Closes: https://github.com/damus-io/notedeck/issues/555
Closes: https://github.com/damus-io/notedeck/pull/560
Signed-off-by: kernelkind <kernelkind@gmail.com>
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
2 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/src/app_creation.rs b/src/app_creation.rs
@@ -1,6 +1,6 @@
use crate::{
app_size_handler::AppSizeHandler,
- app_style::{create_custom_style, dark_mode, desktop_font_size, light_mode, mobile_font_size},
+ app_style::{add_custom_style, dark_mode, light_mode},
fonts::setup_fonts,
storage::DataPath,
};
@@ -79,9 +79,5 @@ pub fn setup_cc(ctx: &egui::Context, is_mobile: bool, light: bool) {
ctx.set_visuals(dark_mode(is_mobile));
}
- ctx.set_style(if is_mobile {
- create_custom_style(ctx, mobile_font_size)
- } else {
- create_custom_style(ctx, desktop_font_size)
- });
+ ctx.all_styles_mut(|style| add_custom_style(is_mobile, style));
}
diff --git a/src/app_style.rs b/src/app_style.rs
@@ -6,7 +6,7 @@ use crate::{
use egui::{
epaint::Shadow,
style::{Interaction, Selection, WidgetVisuals, Widgets},
- Button, Context, FontFamily, FontId, Rounding, Stroke, Style, TextStyle, Ui, Visuals,
+ Button, FontFamily, FontId, Rounding, Stroke, Style, TextStyle, Ui, Visuals,
};
use strum::IntoEnumIterator;
use strum_macros::EnumIter;
@@ -52,9 +52,12 @@ pub fn user_requested_visuals_change(
}
/// Create custom text sizes for any FontSizes
-pub fn create_custom_style(ctx: &Context, font_size: fn(&NotedeckTextStyle) -> f32) -> Style {
- let mut style = (*ctx.style()).clone();
-
+pub fn add_custom_style(is_mobile: bool, style: &mut Style) {
+ let font_size = if is_mobile {
+ mobile_font_size
+ } else {
+ desktop_font_size
+ };
style.text_styles = NotedeckTextStyle::iter()
.map(|text_style| {
(
@@ -75,8 +78,6 @@ pub fn create_custom_style(ctx: &Context, font_size: fn(&NotedeckTextStyle) -> f
style.debug.show_interactive_widgets = true;
style.debug.debug_on_hover_with_all_modifiers = true;
}
-
- style
}
pub fn desktop_font_size(text_style: &NotedeckTextStyle) -> f32 {