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>
This commit is contained in:
kernelkind
2024-12-09 16:34:46 -05:00
committed by William Casarin
parent 35138cd951
commit a24bd4cc43
2 changed files with 9 additions and 12 deletions

View File

@@ -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));
}

View File

@@ -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 {