diff --git a/crates/egui/src/lib.rs b/crates/egui/src/lib.rs index c0c68884a..df01e752a 100644 --- a/crates/egui/src/lib.rs +++ b/crates/egui/src/lib.rs @@ -434,7 +434,6 @@ mod plugin; pub mod response; mod sense; pub mod style; -pub mod style_trait; pub mod text_selection; mod ui; mod ui_builder; @@ -442,6 +441,7 @@ mod ui_stack; pub mod util; pub mod viewport; mod widget_rect; +pub mod widget_style; pub mod widget_text; pub mod widgets; diff --git a/crates/egui/src/style_trait.rs b/crates/egui/src/widget_style.rs similarity index 100% rename from crates/egui/src/style_trait.rs rename to crates/egui/src/widget_style.rs diff --git a/crates/egui/src/widgets/button.rs b/crates/egui/src/widgets/button.rs index 2c63b5fde..08acd12f9 100644 --- a/crates/egui/src/widgets/button.rs +++ b/crates/egui/src/widgets/button.rs @@ -1,12 +1,10 @@ -use std::{mem, sync::Arc}; - use epaint::Margin; use crate::{ Atom, AtomExt as _, AtomKind, AtomLayout, AtomLayoutResponse, Color32, CornerRadius, Frame, - Image, IntoAtoms, NumExt as _, Response, RichText, Sense, Stroke, TextStyle, TextWrapMode, Ui, - Vec2, Widget, WidgetInfo, WidgetText, WidgetType, - style_trait::{ButtonStyle, WidgetState}, + Image, IntoAtoms, NumExt as _, Response, Sense, Stroke, TextStyle, TextWrapMode, Ui, Vec2, + Widget, WidgetInfo, WidgetText, WidgetType, + widget_style::{ButtonStyle, WidgetState}, }; /// Clickable button with text. @@ -327,24 +325,10 @@ impl<'a> Button<'a> { frame = frame.inner_margin(button_padding); - // Apply the correct font and color if Text - // We assume that the other WidgetText have already a Fontid and color - layout.map_texts(|t| match t { - WidgetText::Text(text) => { - let rich_text = RichText::new(text.clone()) - .font(text_style.font_id.clone()) - .color(text_style.color); - WidgetText::RichText(Arc::new(rich_text)) - } - WidgetText::RichText(mut text) => { - let text_mut = Arc::make_mut(&mut text); - *text_mut = mem::take(text_mut) - .font(text_style.font_id.clone()) - .color(text_style.color); - WidgetText::RichText(text) - } - w => w, - }); + // Apply the style font and color as fallback + layout = layout + .fallback_font(text_style.font_id.clone()) + .fallback_text_color(text_style.color); // Retrocompatibility with button settings layout = if has_frame_margin && (state != WidgetState::Inactive || frame_when_inactive) { diff --git a/crates/egui/src/widgets/checkbox.rs b/crates/egui/src/widgets/checkbox.rs index f3a57af47..077673a9e 100644 --- a/crates/egui/src/widgets/checkbox.rs +++ b/crates/egui/src/widgets/checkbox.rs @@ -2,7 +2,7 @@ use emath::Rect; use crate::{ Atom, AtomLayout, Atoms, Id, IntoAtoms, NumExt as _, Response, Sense, Shape, Ui, Vec2, Widget, - WidgetInfo, WidgetType, epaint, pos2, style_trait::CheckboxStyle, + WidgetInfo, WidgetType, epaint, pos2, widget_style::CheckboxStyle, }; // TODO(emilk): allow checkbox without a text label diff --git a/crates/egui/src/widgets/separator.rs b/crates/egui/src/widgets/separator.rs index 5dfedf1d2..ab211773e 100644 --- a/crates/egui/src/widgets/separator.rs +++ b/crates/egui/src/widgets/separator.rs @@ -1,4 +1,4 @@ -use crate::{Response, Sense, Ui, Vec2, Widget, vec2}; +use crate::{Response, Sense, Ui, Vec2, Widget, vec2, widget_style::SeparatorStyle}; /// A visual separator. A horizontal or vertical line (depending on [`crate::Layout`]). /// @@ -97,10 +97,13 @@ impl Widget for Separator { let id = ui.next_auto_id(); let response: Option = ui.ctx().read_response(id); let state = response.map(|r| r.widget_state()).unwrap_or_default(); - let style = ui.style().separator_style(state); + let SeparatorStyle { + spacing: spacing_style, + stroke, + } = ui.style().separator_style(state); // override the spacing if not set - let spacing = spacing.unwrap_or(style.spacing); + let spacing = spacing.unwrap_or(spacing_style); let is_horizontal_line = is_horizontal_line .unwrap_or_else(|| ui.is_grid() || !ui.layout().main_dir().is_horizontal()); @@ -120,7 +123,6 @@ impl Widget for Separator { let (rect, response) = ui.allocate_at_least(size, Sense::hover()); if ui.is_rect_visible(response.rect) { - let stroke = style.stroke; let painter = ui.painter(); if is_horizontal_line { painter.hline(