Skip to content

Commit

Permalink
Fix: button_padding when using image+text buttons (emilk#2510)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
RobWalt authored and lictex committed Jan 23, 2023
1 parent 7016b48 commit b15ec18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG
* Trigger `PointerEvent::Released` for drags ([#2094](https://github.com/emilk/egui/pull/2094)).
* 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
Expand Down
5 changes: 4 additions & 1 deletion crates/egui/src/widgets/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b15ec18

Please sign in to comment.