From 0ad8aea8116836016d07efb9b5cbab68ce1a00ee Mon Sep 17 00:00:00 2001 From: Robert Walter <26892280+RobWalt@users.noreply.github.com> Date: Mon, 23 Jan 2023 09:23:57 +0100 Subject: [PATCH] Fix: `button_padding` when using image+text buttons (#2510) * feat(image-button-margin): implement image button margin - add `image_margin` field on `Button` widget - implement setter method called `image_margin` for `Button` widget - use margin from `image_margin` field of `Button` widget in `Widget` trait functions * feat(image-button-margin): update changelog * feat(image-button-margin): implement `map_or` clippy fix * feat(image-button-margin): remove margin field & fix button-padding instead * feat(image-button-margin): fix CI errors * feat(image-button-margin): update changelog to include fix * feat(image-button-margin): re-add changes after creating screenshots for PR --- CHANGELOG.md | 1 + crates/egui/src/widgets/button.rs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3adff09a..e6ad6728 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG ### Fixed 🐛 * Expose `TextEdit`'s multiline flag to AccessKit ([#2448](https://github.com/emilk/egui/pull/2448)). * Don't render `\r` (Carriage Return) ([#2452](https://github.com/emilk/egui/pull/2452)). +* The `button_padding` style option works closer as expected with image+text buttons now ([#2510](https://github.com/emilk/egui/pull/2510)). ## 0.20.1 - 2022-12-11 - Fix key-repeat diff --git a/crates/egui/src/widgets/button.rs b/crates/egui/src/widgets/button.rs index 19385470..7f050a06 100644 --- a/crates/egui/src/widgets/button.rs +++ b/crates/egui/src/widgets/button.rs @@ -221,7 +221,10 @@ impl Widget for Button { if let Some(image) = image { let image_rect = Rect::from_min_size( - pos2(rect.min.x, rect.center().y - 0.5 - (image.size().y / 2.0)), + pos2( + rect.min.x + button_padding.x, + rect.center().y - 0.5 - (image.size().y / 2.0), + ), image.size(), ); image.paint_at(ui, image_rect);