egui icon indicating copy to clipboard operation
egui copied to clipboard

Fix: `button_padding` when using image+text buttons

Open JasmineLowen opened this issue 3 years ago • 3 comments

Changes of the PR:

  • fix button_padding functionality for buttons with images

Only the last comment of this PR is important. All other comments aren't relevant after my self review anymore.


TODO:

  • [x] Unless this is a trivial change, add a line to the relevant CHANGELOG.md under "Unreleased".
  • [x] run cargo fmt
  • [x] run cargo clippy
  • [x] self-review
  • [x] run ./sh/check.sh

Closes https://github.com/emilk/egui/issues/2509.

JasmineLowen avatar Dec 26 '22 17:12 JasmineLowen

~~Question @reviewer: Should we maybe extend the margin feature to respect the text aswell, i.e. the right field of the Margin creates a margin on the right side of the text in the button instead?~~

JasmineLowen avatar Dec 26 '22 17:12 JasmineLowen

~~Question @Reviewer: Should we maybe extend the margin feature to respect the text aswell, i.e. the right field of the Margin creates a margin on the right side of the text in the button instead?~~

~~It seems like this would be the better solution as we already have the icon_spacing to configure the space between the image and the text. I implemented a PoC of the changes above and the example with image_margin(Margin::same(20.0)) and icon_spacing = 30.0; would look as follows:~~

image

JasmineLowen avatar Dec 26 '22 17:12 JasmineLowen

I just noticed that the style option button_padding does the trick. It just wasn't applied to the left of the button when there was an image. Setting the button_padding to Vec2::splat(20.0) in the example above looks like this

before

image

after

image

Note that this makes much more sense, since I also explicitly set icon_spacing = 0.0, which isn't the case in the "before" picture.

JasmineLowen avatar Dec 28 '22 12:12 JasmineLowen