{"record":{"id":"783ca0181b183478","repo":"emilk/egui","slug":"failed-to-find-in-style-text-styles-available-styles","errorCode":null,"errorMessage":"Failed to find {:?} in Style::text_styles. Available styles:\n{:#?}","messagePattern":"Failed to find (.+?) in Style::text_styles\\. Available styles:\n(.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/egui/src/style.rs","lineNumber":114,"sourceCode":"\nimpl core::fmt::Display for TextStyle {\n    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {\n        match self {\n            Self::Small => \"Small\".fmt(f),\n            Self::Body => \"Body\".fmt(f),\n            Self::Monospace => \"Monospace\".fmt(f),\n            Self::Button => \"Button\".fmt(f),\n            Self::Heading => \"Heading\".fmt(f),\n            Self::Name(name) => (*name).fmt(f),\n        }\n    }\n}\n\nimpl TextStyle {\n    /// Look up this [`TextStyle`] in [`Style::text_styles`].\n    pub fn resolve(&self, style: &Style) -> FontId {\n        style.text_styles.get(self).cloned().unwrap_or_else(|| {\n            panic!(\n                \"Failed to find {:?} in Style::text_styles. Available styles:\\n{:#?}\",\n                self,\n                style.text_styles()\n            )\n        })\n    }\n}\n\n// ----------------------------------------------------------------------------\n\n/// A way to select [`FontId`], either by picking one directly or by using a [`TextStyle`].\n#[derive(Debug, Clone)]\npub enum FontSelection {\n    /// Default text style - will use [`TextStyle::Body`], unless\n    /// [`Style::override_font_id`] or [`Style::override_text_style`] is set.\n    Default,\n\n    /// Directly select size and font family","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/emilk/egui/blob/441971a776322a482e371775219380eca812cfa9/crates/egui/src/style.rs#L96-L132","documentation":"`TextStyle::resolve` maps a logical text style (e.g. `TextStyle::Heading`) to a concrete `FontId` by looking it up in `Style::text_styles`. If the map doesn't contain that key — because a custom style replaced the default `text_styles` and omitted entries — the lookup fails and it panics, listing the styles that ARE available.","triggerScenarios":"Setting a custom style via `ctx.style_mut` / `Context::set_style` / `Visuals` customization where `text_styles` is replaced with a BTreeMap missing one of the `TextStyle` variants, then rendering text whose widget requests that missing style (e.g. `RichText::new(x).heading()` or `text_style_height`).","commonSituations":"Hand-building `text_styles` for a themed app and forgetting variants like Monospace or Small; upgrading egui where new TextStyle variants/keys were added while custom code still constructs the old map; copying style code that only defines Body and Heading.","solutions":["Add the missing `TextStyle` variant to your `text_styles` map with a `FontId` (size/family) of your choice.","Start from `Style::default()` or clone the current style and modify only what you need, instead of constructing `text_styles` from scratch.","Read the panic's 'Available styles' list to see exactly which keys exist, then add the missing one.","Check the egui changelog when upgrading: new variants may need entries in custom text_styles maps."],"exampleFix":"// before\nstyle.text_styles = [(TextStyle::Body, FontId::proportional(14.0))].into(); // Heading/Monospace missing\n// after\nlet mut ts = style.text_styles.clone();\nts.insert(TextStyle::Heading, FontId::proportional(20.0));\nts.insert(TextStyle::Monospace, FontId::monospace(13.0));\nstyle.text_styles = ts;","handlingStrategy":"validation","validationCode":"// before rendering, ensure all TextStyle variants are present\nlet required = [TextStyle::Small, TextStyle::Body, TextStyle::Button, TextStyle::Heading, TextStyle::Monospace];\nfor ts in required {\n    assert!(ctx.style(|s| s.text_styles.contains_key(&ts)), \"text_styles missing {ts:?}\");\n}","typeGuard":"fn has_all_text_styles(style: &egui::Style) -> bool {\n    use egui::TextStyle::*;\n    [Small, Body, Button, Heading, Monospace]\n        .iter().all(|t| style.text_styles.contains_key(t))\n}","tryCatchPattern":null,"preventionTips":["Clone Style::default() and edit instead of building text_styles from an empty map.","Include every TextStyle variant in custom theme definitions.","After egui upgrades, diff TextStyle variants against your custom text_styles map.","Use the panic's 'Available styles' list in dev to quickly spot missing keys."],"tags":["style","fonts","lookup-failed","panic"],"backgroundTag":"record-not-found","analyzedSha":"441971a776322a482e371775219380eca812cfa9","analyzedAt":"2026-09-12T04:29:21.500Z","contentChangedAt":"2026-09-12T04:29:21.500Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}