diff --git a/crates/egui/src/memory/mod.rs b/crates/egui/src/memory/mod.rs index 72bc94ae5..436798a2e 100644 --- a/crates/egui/src/memory/mod.rs +++ b/crates/egui/src/memory/mod.rs @@ -617,10 +617,7 @@ impl Focus { } } - // AccessKit names the widget by the node id it read from the last tree we sent, so the - // widget has been here before and is in the cache. Handing the focus out here, instead of - // waiting for the widget to ask for it, means everything that reads the focus before the - // widget runs — styling it, for one — already sees the new focus. + // Handle accesskit focus requests let newly_focused = focus_requested_by_accesskit.and_then(|node_id| { self.focus_widgets_cache .keys() diff --git a/crates/egui/src/theme/default_style.rs b/crates/egui/src/theme/default_style.rs index c36a963b3..814de169c 100644 --- a/crates/egui/src/theme/default_style.rs +++ b/crates/egui/src/theme/default_style.rs @@ -5,7 +5,7 @@ use crate::{ Frame, TextStyle, theme::StyleProvider, widget_style::{ - BaseStyle, ButtonStyle, CheckboxStyle, HasClasses as _, LabelStyle, LayoutStyle, + BaseStyle, ButtonStyle, CheckboxStyle, HasClasses as _, LabelStyle, AtomLayoutStyle, READ_ONLY_CLASS, SELECTED_CLASS, SeparatorStyle, StyleArgs, TextEditStyle, TextVisuals, WidgetState, }, @@ -88,7 +88,7 @@ impl StyleProvider for DefaultStyle { .into(), ..Default::default() }, - layout: LayoutStyle { + layout: AtomLayoutStyle { min_size: Vec2::new(0.0, spacing.interact_size.y), gap: spacing.icon_spacing, }, @@ -146,7 +146,7 @@ impl StyleProvider for DefaultStyle { outer_margin: Margin::same(-(widget_visuals.expansion as i8)), ..Default::default() }, - layout: LayoutStyle { + layout: AtomLayoutStyle { // A text edit sizes itself from the rows it holds; egui's own theme adds no floor // of its own. min_size: Vec2::ZERO, diff --git a/crates/egui/src/widget_style/mod.rs b/crates/egui/src/widget_style/mod.rs index 17dcfbe79..71b903d99 100644 --- a/crates/egui/src/widget_style/mod.rs +++ b/crates/egui/src/widget_style/mod.rs @@ -36,17 +36,14 @@ pub struct TextVisuals { } impl TextVisuals { - /// The undecorated body text of a [`Style`], as a starting point for a widget's own text. - /// - /// The color is the style's ordinary text color; a widget that paints its text in a color of - /// its own overrides it. - pub fn from_style(style: &Style) -> Self { + /// Resolves the provided [`TextStyle`], unless `style.override_font_id` is set. + pub fn from_style(style: &Style, text_style: TextStyle) -> Self { Self { color: style.visuals.text_color(), font_id: style .override_font_id .clone() - .unwrap_or_else(|| TextStyle::Body.resolve(style)), + .unwrap_or_else(|| text_style.resolve(style)), underline: Stroke::NONE, strikethrough: Stroke::NONE, } @@ -71,7 +68,7 @@ impl WidgetStyle for BaseStyle {} /// button are one look, not two — so they travel as one struct, shared by every widget style that /// lays its contents out with an [`crate::AtomLayout`]. #[derive(Debug, Clone)] -pub struct LayoutStyle { +pub struct AtomLayoutStyle { /// How small the widget may get, before its contents are taken into account. /// /// A floor, not a size: a widget is never smaller than what it holds. @@ -88,10 +85,10 @@ pub struct ButtonStyle { /// How the button's contents are laid out. /// - /// [`LayoutStyle::min_size`] is ignored by a [`crate::Button::small`] button, which sizes + /// [`AtomLayoutStyle::min_size`] is ignored by a [`crate::Button::small`] button, which sizes /// itself purely from its contents and its own [`crate::Button::min_size`]; - /// [`LayoutStyle::gap`] is overridden by [`crate::Button::gap`]. - pub layout: LayoutStyle, + /// [`AtomLayoutStyle::gap`] is overridden by [`crate::Button::gap`]. + pub layout: AtomLayoutStyle, pub text_style: TextVisuals, } @@ -106,10 +103,10 @@ pub struct TextEditStyle { /// How the field's contents are laid out. /// - /// [`LayoutStyle::min_size`] is raised by [`crate::TextEdit::min_size`] and by the rows of - /// text the field holds, so it only ever sets a floor; [`LayoutStyle::gap`] separates the + /// [`AtomLayoutStyle::min_size`] is raised by [`crate::TextEdit::min_size`] and by the rows of + /// text the field holds, so it only ever sets a floor; [`AtomLayoutStyle::gap`] separates the /// text from a [`crate::TextEdit::prefix`] or [`crate::TextEdit::suffix`]. - pub layout: LayoutStyle, + pub layout: AtomLayoutStyle, /// The text being edited. pub text: TextVisuals, diff --git a/crates/egui/src/widgets/button.rs b/crates/egui/src/widgets/button.rs index c4358faa5..f4edc075b 100644 --- a/crates/egui/src/widgets/button.rs +++ b/crates/egui/src/widgets/button.rs @@ -4,7 +4,7 @@ use crate::{ Atom, AtomExt as _, AtomKind, AtomLayout, AtomLayoutResponse, Atoms, Color32, CornerRadius, Frame, Image, IntoAtoms, Response, Sense, Stroke, TextStyle, TextWrapMode, Ui, Vec2, Widget, WidgetInfo, WidgetText, WidgetType, - widget_style::{ButtonStyle, Classes, HasClasses, LayoutStyle, SELECTED_CLASS, WidgetState}, + widget_style::{ButtonStyle, Classes, HasClasses, AtomLayoutStyle, SELECTED_CLASS, WidgetState}, }; /// Clickable button with text. @@ -331,7 +331,7 @@ impl<'a> Button<'a> { let ButtonStyle { frame, layout: - LayoutStyle { + AtomLayoutStyle { min_size: style_min_size, gap, }, diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index e224f1282..db5b75652 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -17,7 +17,7 @@ use crate::{ self, CCursorRange, text_cursor_state::cursor_rect, visuals::paint_text_selection, }, vec2, - widget_style::{Classes, HasClasses, LayoutStyle, READ_ONLY_CLASS, TextEditStyle}, + widget_style::{Classes, HasClasses, AtomLayoutStyle, READ_ONLY_CLASS, TextEditStyle}, }; use super::{TextEditOutput, TextEditState}; @@ -490,7 +490,7 @@ impl TextEdit<'_> { let TextEditStyle { frame: styled_frame, layout: - LayoutStyle { + AtomLayoutStyle { min_size: style_min_size, gap, }, diff --git a/examples/styling_engine/src/main.rs b/examples/styling_engine/src/main.rs index 425578f38..9c142f50c 100644 --- a/examples/styling_engine/src/main.rs +++ b/examples/styling_engine/src/main.rs @@ -6,7 +6,7 @@ use eframe::egui::{ self, CentralPanel, Color32, Frame, Panel, theme::StyleProvider, - widget_style::{BaseStyle, ButtonStyle, HasClasses as _, LayoutStyle, StyleArgs, WidgetState}, + widget_style::{BaseStyle, ButtonStyle, HasClasses as _, AtomLayoutStyle, StyleArgs, WidgetState}, }; /// Buttons with this class are styled as a destructive action. @@ -67,7 +67,7 @@ impl StyleProvider for MyTheme { .fill(fill) .corner_radius(self.corner_radius) .inner_margin(8), - layout: LayoutStyle { + layout: AtomLayoutStyle { min_size: args.style.spacing.interact_size, gap: args.style.spacing.icon_spacing, },