diff --git a/crates/egui/src/widgets/button.rs b/crates/egui/src/widgets/button.rs index 7a6f03e8a..70505a999 100644 --- a/crates/egui/src/widgets/button.rs +++ b/crates/egui/src/widgets/button.rs @@ -284,23 +284,22 @@ impl<'a> Button<'a> { let text = layout.text().map(String::from); - // Get the widget style + // Get the widget style by reading the rect from the previous pass 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().button_style(state); + // let has_frame_margin = frame.unwrap_or_else(|| ui.visuals().button_frame); - // Apply the correct font on RichText and Text + // 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::RichText(mut text) => { - let text_mut = Arc::make_mut(&mut text); - *text_mut = mem::take(text_mut).font(style.text.font_id.clone()); - WidgetText::RichText(text) - } WidgetText::Text(text) => { - let rich_text = RichText::new(text.clone()).font(style.text.font_id.clone()); + let rich_text = RichText::new(text.clone()) + .font(style.text.font_id.clone()) + .color(style.text.color); WidgetText::RichText(Arc::new(rich_text)) } w => w, @@ -308,7 +307,7 @@ impl<'a> Button<'a> { // Retrocompatibility with button settings let mut prepared = - if has_frame_margin && (frame_when_inactive || state != WidgetState::Inactive) { + if has_frame_margin && (state != WidgetState::Inactive || frame_when_inactive) { layout.frame(style.frame).min_size(min_size).allocate(ui) } else { layout.min_size(min_size).allocate(ui) diff --git a/examples/hello_world_simple/src/main.rs b/examples/hello_world_simple/src/main.rs index 0514db692..9a0d98d16 100644 --- a/examples/hello_world_simple/src/main.rs +++ b/examples/hello_world_simple/src/main.rs @@ -28,12 +28,11 @@ fn main() -> eframe::Result { age += 1; } + // Button test ui.add(Button::new("no frame").frame(false)); ui.add(Button::new("small").small()); - ui.add_enabled( - false, - Button::new("no frame inactive").frame_when_inactive(false), - ); + ui.add_enabled(false, Button::new("disabled")); + ui.add(Button::new("no frame inactive").frame_when_inactive(false)); ui.label(format!("Hello '{name}', age {age}")); });