egui/crates
zk 27e648a335
Add `Rect::scale_from_center` (#4673)
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

I find myself wanting this API quite a lot, and I imagine it'll probably
be useful for others.

# What?

This PR adds `Rect::scale` and `Rect::scale2` functions, which work a
lot like `expand`, but instead multiply by a scale.

i.e.
```rs
rect.scale(2.0); // rect is 2x as big, still in same center
rect.scale2(vec2(1.5, 2.0)); // rect is 1.5x as big on x axis, 2.0x as big on y axis. still in same center
```

# Why?

Before this you either had to write this yourself or use a `expand` in a
cumbersome way:
```rs
rect.expand2(vec2(rect.width() * scale.x / 2.0, rect.height() * scale.y / 2.0));
```

I find myself wanting to scale things up by a factor frequently enough,
and it seems like a useful addition to have a multiply-based variant of
`expand`.

I realise this is pretty minor, but it seems useful enough to me!

---------

Co-authored-by: zkldi <20380519+zkldi@users.noreply.github.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-07-15 19:54:35 +02:00
..
ecolor Remove some debug asserts (#4826) 2024-07-15 11:20:22 +02:00
eframe Use canvas directly (#4780) 2024-07-15 18:59:15 +02:00
egui Remove some debug asserts (#4826) 2024-07-15 11:20:22 +02:00
egui-wgpu `egui-wgpu`: Ensure that `WgpuConfiguration` is `Send + Sync` (#4803) 2024-07-08 23:25:29 +02:00
egui-winit Release 0.28.1 - Tooltip tweaks 2024-07-05 12:09:21 +02:00
egui_demo_app Use canvas directly (#4780) 2024-07-15 18:59:15 +02:00
egui_demo_lib Move `egui_plot` to its own repo (#4828) 2024-07-15 18:45:19 +02:00
egui_extras Add `TableRow::set_hovered` (#4820) 2024-07-15 10:36:29 +02:00
egui_glow Introduce dithering to reduce banding (#4497) 2024-07-08 09:57:11 +02:00
egui_plot Move `egui_plot` to its own repo (#4828) 2024-07-15 18:45:19 +02:00
egui_web Fix typos (#2866) 2023-04-18 15:52:45 +02:00
emath Add `Rect::scale_from_center` (#4673) 2024-07-15 19:54:35 +02:00
epaint epaint: add some missing inline docs (#4815) 2024-07-11 11:52:27 +02:00