1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

fix some logic

This commit is contained in:
Adrien Zianne
2025-10-15 15:35:03 +02:00
parent a99adc6c93
commit ad4b0de2b3
2 changed files with 11 additions and 13 deletions

View File

@@ -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<Response> = 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)

View File

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