Commit Graph

3393 Commits

Author SHA1 Message Date
Arthur Brussee 6f2f006885
Upgrade winit to 0.30.2 (#4849)
* Closes https://github.com/emilk/egui/issues/1918
* Closes https://github.com/emilk/egui/issues/4437
* Closes https://github.com/emilk/egui/issues/4709
* [x] I have followed the instructions in the PR template

Hiya,

I need new winit for a specific fix for a android_native_actvity. There
are already two PRs, but both don't seem to have a lot of movement, or
are entirely complete:

https://github.com/emilk/egui/pull/4466
Seems to have gone stale & is missing some bits.

https://github.com/emilk/egui/pull/4702
Also seems stale (if less so), and is missing a refactor to
run_on_demand. I also *think* the accesskit integration has a mistake
and can't be enabled. I've marked them as a co-author on this as I
started from this branch. (I think! Haven't done that on git before...).

Sorry for the wall of text but just dumping some details / thoughts
here:

- There's an issue with creating child windows in winit 0.30.1 and up on
macOS. The multiple_viewports, "create immediate viewport" example
crashes on anything later 0.30.1, with a stack overflow in unsafe code.
I've create [a winit
issue](https://github.com/rust-windowing/winit/issues/3800), it *might*
already be fixed in 0.31.0 but I can't test as 0.31 will likely require
another refactoring. For now I have just pinned things to 0.30.0 exatly.

- Winit has deprecated run_on_demand, instead requiring the
ApplicationHandler interface. In 0.31.0 run_on_demand is removed. I've
refactored both the integration and the WinitApp trait to follow this
pattern. I've left user_events a bit more opaque, as it seems 0.31.0 is
doing a rework of UserEvents too.

- I've used the new lazy init approach for access kit from this branch
https://github.com/mwcampbell/egui/tree/accesskit-new-lazy-init and
marked Matt as co-author, thanks Matt!

- There was very similair but not quite the same code for run_and_return
and run_and_exit. I've merged them, but looking at the github issues
graveyard it seems vey finnicky. I *hope* this is more robust than
before but it's a bit scary.

- when receiving new_events this also used to check the redraw timing
dictionary. That doesn't seem necesarry so left this out, but that is a
slight behaviour change?

- I have reeneabled serial_windows on macOS. I wondered whether it was
fixed after this PR and does seem to be! However, even before this PR it
seems to work, so maybe winit has sorted things out before that...
Windows also works fine now without the extra hack.

- I've done a very basic test of AccessKit on Windows and screen reader
seems ok but I'm really not knowleadgable enough to say whether it's all
good or not.

- I've tested cargo tests & all examples on Windows & macOS, and ran a
basic Android app. Still, testing native platforms is wel... hard so if
anyone can test linux / iOs / older mac versions / windows 10 would
probably be a good idea!

- For consistencys sake I've made all event like functions in WinitApp
return a `Result<EventResult>`. There's quite a bit of Ok-wrapping now,
maybe too annoying? Not sure.

Thank you for having a look!

# Tested on
* [x] macOS
* [x] Windows
* [x] Wayland (thanks [SiebenCorgie](https://github.com/SiebenCorgie))
* [x] X11 (thanks
[crumblingstatue](https://github.com/crumblingstatue)!,
[SiebenCorgie](https://github.com/SiebenCorgie))


# TODO
* [x] Fix "follow system theme" not working on initial startup (winit
issue, pinning to 0.30.2 for now).
* [x] Fix `request_repaint_after`

---------

Co-authored-by: mwcampbell <mattcampbell@pobox.com>
Co-authored-by: j-axa <josef.axa@gmail.com>
Co-authored-by: DataTriny <datatriny@gmail.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-07-31 09:43:16 +02:00
PrimmR 37b1e1504d
Fix: hint text follows the alignment set on the `TextEdit` (#4889)
Updated the `show_content` method of the `TextEdit` widget so that the
requested text alignment (if any) is also applied to the hint text.

Currently, hint text is always aligned to the top left of the widget,
which may be inconsistent with the actual location of text entered by
the user. I think it's more intuitive for the hint text to be positioned
as if the user had entered the same text themselves.

Here are some comparisons of the difference between how the hint text
and the entered text looks, before and after this change:

### Previous Behaviour

![Prev](https://github.com/user-attachments/assets/8cd7858f-833e-4946-84f1-ff1ede60c64d)


### Updated Behaviour

![Update](https://github.com/user-attachments/assets/2596dd44-d6f9-4376-9012-5b074fc2cdea)

* [x] I have followed the instructions in the PR template
2024-07-30 21:03:52 +02:00
Tyler Stevens 7736192722
Clarified `eframe::run_simple_native()` persistence (#4846)
* [x] I have followed the instructions in the PR template

Clarified that `eframe::run_simple_native()` does in fact save some
state (if persistence is enabled) but does not allow user to save state.
2024-07-30 21:01:10 +02:00
Onè 057033ef34
Fix typos in egui docstrings (#4869)
<!--
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 test and 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!
-->

* [x] I have followed the instructions in the PR template (less the
self-review using the script as it's only a single word change).
2024-07-30 21:00:47 +02:00
rustbasic 378df03910
Clamp margin values in `Margin::ui` (#4873)
limit margin value in `settings.ui()`.

Issues: If the `window margin` of `settings.ui()` becomes -10.0 or less,
a panic occurs.
2024-07-30 20:11:33 +02:00
Andreas Reich 64d5f948e4
Workaround for wgpu crash when surface is dropped last (#4876)
* Fixes https://github.com/emilk/egui/issues/4874
* Details see https://github.com/gfx-rs/wgpu/pull/6052
2024-07-26 10:10:23 +02:00
Salman Abuhaimed 34db001db1
Force canvas/text input focus on touch for iOS web browsers (#4848) 2024-07-23 18:16:51 +02:00
Simon Niedermayr 56df31ab48
upgrade to wgpu 22.0.0 (#4847)
wgpu changelog: https://github.com/gfx-rs/wgpu/releases/tag/v22.0.0

---------

Co-authored-by: Andreas Reich <r_andreas2@web.de>
2024-07-19 10:05:56 +02:00
frederik-uni b2d74eaef6
Return `ScrollAreaOutput` from `Table::body` (#4829)
<!--
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 test and 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!
-->

added return ScrollAreaOutput.

This can be used to monitor the scroll progress of a table(usage
example: custom scroll progress bar or lazy loading table)

* [X] I have followed the instructions in the PR template
2024-07-15 20:49:41 +02:00
Xavier Lau 1741f0a51c
Make sure SVGs are crisp (#4823)
<!--
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 test and 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!
-->

* Closes https://github.com/emilk/egui/issues/3453
* [x] I have followed the instructions in the PR template

I'm fairly new to egui.

I read the code, but I didn't follow the approach mentioned in
https://github.com/emilk/egui/issues/3453#issuecomment-2208255433.

I believe this is an easier way to achieve that, though I'm not certain
if it's the best method.

<img width="760" alt="image"
src="https://github.com/user-attachments/assets/4b3c561f-1c24-446b-9581-a2f4e9858480">

I get really nice svg with this patch.

@emilk Can you please take a look? I really need this!
2024-07-15 20:49:29 +02:00
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
Jan Procházka 0d89e31e3e
Use canvas directly (#4780) 2024-07-15 18:59:15 +02:00
Emil Ernerfeldt cb9f30482f
Move `egui_plot` to its own repo (#4828)
* Part of https://github.com/emilk/egui/issues/4705

`egui_plot` can now be found at https://github.com/emilk/egui_plot
2024-07-15 18:45:19 +02:00
Emil Ernerfeldt 1384410cb4
Revert "Don't specify a patch version of rust in rust-toolchain" (#4827)
Fix Android CI
2024-07-15 15:14:31 +02:00
Emil Ernerfeldt 8d2df5491e
Remove some debug asserts (#4826)
* Closes https://github.com/emilk/egui/issues/4825
2024-07-15 11:20:22 +02:00
v0x0g 1bee7bfefa
Add `Ui::columns_const()` (#4764)
# Changes

- Adds a new function `egui::Ui::columns_const()`, which is the same as
`egui::Ui::columns()` except that it uses a `const` parameter for the
column count.
- Backed by an array `[Ui; NUM_COL] instead of a `Vec<Ui>`, so fewer
allocations
- Inner closure takes in an array reference, instead of a slice
reference. This makes it possible to use pattern destructuring on the
columns, as shown in the example, and makes it more ergonomic to use

# Example

```rust
// ORIGINAL
ui.columns(2, |cols| {
    cols[0].label("one");
    cols[1].label("two");
});


// NEW
ui.columns_const(|[a,b]| {
    a.label("one");
    b.label("two");
});

```

# Checks

- [X] `cargo fmt`
- [X] `cargo clippy`
- [X] `./scripts/check.sh`
- [X] Docs
- [ ] Review
2024-07-15 11:19:34 +02:00
Wybe Westra 1adc3d8865
Add undo/redo demo. (#4811)
* Closes https://github.com/emilk/egui/issues/1713 

I almost went to implement my own undo/redo system, and then found the
egui undoer.
Went to make a small demo to test for myself how it worked, and then
found the linked issue.
So here is a tweaked version of that :)

Co-authored-by: Wybe Westra <w.westra@kwantcontrols.nl>
2024-07-15 10:54:34 +02:00
Addis Webb 2b9595ee3c
Add `TableRow::set_hovered` (#4820)
<!--
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 test and 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 added a util function `set_hovered` to change the hovered state of a
row from tables in `egui_extras` which matches the already present
`set_selected` function.

* [x] I have followed the instructions in the PR template
2024-07-15 10:36:29 +02:00
Xavier Lau a6ab126e47
Slider: round to decimals after applying `step_by` (#4822)
<!--
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 test and 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!
-->

* Closes https://github.com/emilk/egui/discussions/4670
* [x] I have followed the instructions in the PR template
2024-07-15 10:28:45 +02:00
Emil Ernerfeldt 67eb29001d Don't specify a patch version of rust in rust-toolchain 2024-07-15 08:45:18 +02:00
Emil Ernerfeldt b862f731d6 Add @Wumpf to CODEOWNERS for egui-wgpu 2024-07-15 08:43:01 +02:00
Antoine Beyeler 08c75d75c9
Change default `max_scroll_height` of `egui::Table` to `f32::INFINITY` (#4817)
`egui::Table` has a weirdly specific default `max_scroll_height` set to
800.0. This means that even with `vscroll(true)` and `auto_shrink([_,
false])`, the table will not expend to the full available height. This
PR changes this value to `f32::INFINITY`. This makes it consistent with
the corresponding default value of `ScrollArea::max_size.y`, which is
where that `max_scroll_height` ends up being used.
2024-07-12 10:03:59 +02:00
Wojciech Muła 7f899c1d07
epaint: add some missing inline docs (#4815)
Document a few `Mesh` methods.
2024-07-11 11:52:27 +02:00
rustbasic 20359a870f
eframe: Improve `glow` context switching (#4814)
Improved `change_gl_context()`

**Before:** 
Create a new `not_current_glcontext`. 

**After:**
If `not_current_glcontext` exists, apply it. Otherwise, create it. 

This will make the program smoother when dragging, etc.
2024-07-11 11:43:21 +02:00
Nicolas Bircks 3b8453e920
Add a menu button with text and image (#4748)
In order to make it possible that all buttons can have the same style
with a text and an image I created a `menu_text_image_button`.

It works the same way as all the other menu buttons.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-07-09 16:51:41 +02:00
Joe Sorensen aa96b25746
`egui-wgpu`: Ensure that `WgpuConfiguration` is `Send + Sync` (#4803)
As far as I can tell, there's no reason that this shouldn't be the case
2024-07-08 23:25:29 +02:00
Emil Ernerfeldt f9476e0a00 PR template: add a 'I have read…' checkbox 2024-07-08 14:52:29 +02:00
Jonas Wagner b283b8a560
Introduce dithering to reduce banding (#4497)
This PR introduces dithering in the egui_glow and egui_wgpu backends to
reduce banding artifacts.

It's based on the approach mentioned in #4493 with the small difference
that the amount of noise is scaled down slightly to avoid dithering
colors that can be represented exactly. This keeps flat surfaces clean.

Exaggerated dithering to show what is happening:
![Screenshot from 2024-05-14
19-09-48](https://github.com/emilk/egui/assets/293536/75782b83-9023-4cb2-99f7-a24e15fdefcc)

Subtle dithering as commited.
![Screenshot from 2024-05-14
19-13-40](https://github.com/emilk/egui/assets/293536/eb904698-a6ec-494a-952b-447e9a49bfda)

Closes #4493
2024-07-08 09:57:11 +02:00
rustbasic fcd02bd7d1
Handle the IME event first in `TextEdit` to fix some bugs (#4794)
Handle the `IME` event first 
There is a need to handle the Ime event first.

Fix Issues : When you press `BackSpace`, the entire text is erased, and
when you press another letter, it appears again.
Fix Issues : When you press `Left`, the character being entered will be
copied once more.
Fix Issues : When you press `Enter`, `Enter` with `repeat` set is
entered and `Enter` is entered twice.
Fix Issues : When you press a key in `IME` mode, `repeat` is often set.

Fix Issues : Since you may be selecting something in the IME, this also
disables the `Arrow` keys.
2024-07-07 22:03:13 +02:00
rustbasic cd1e4c573a
Remove dead code (`EpiIntegration::frame_start`) (#4790)
`frame_start` appears to be deprecated now.
( Am I wrong? )

It would be a good idea to add `#[allow(dead_code)]` or remove
`frame_start`.
2024-07-07 08:52:14 +02:00
YgorSouza 39f7368d2e
Fix typos (#4796) 2024-07-07 08:50:04 +02:00
Emil Ernerfeldt 0f6310c598 Add release title to changelog entry 2024-07-05 12:14:03 +02:00
Emil Ernerfeldt abab06867c Release 0.28.1 - Tooltip tweaks 2024-07-05 12:09:21 +02:00
Emil Ernerfeldt 13fddc6416
Hide tooltip on click (#4789)
Affects uses of `on_hover_ui_at_pointer` and `show_tooltip_at_pointer`
2024-07-05 11:53:49 +02:00
Emil Ernerfeldt f92fe5544b Document Vec2 constants 2024-07-05 11:39:47 +02:00
Emil Ernerfeldt 0a9e0c87a4
Fix occational flickering of pointer-tooltips (#4788)
Affects uses of `on_hover_ui_at_pointer` and `show_tooltip_at_pointer`
2024-07-05 11:36:26 +02:00
Emil Ernerfeldt 0be4450e3d
Smoother animations (#4787)
This makes animations slightly smoother, especially in reactive mode
2024-07-05 11:36:19 +02:00
Emil Ernerfeldt 1059e0e7f1 Fix tooltip delay, bug introduced in #4784 2024-07-05 10:27:11 +02:00
Emil Ernerfeldt 2e2366e88d
Make `serde` a default (opt-out) feature of `egui_extras` (#4786)
This is a workaround for https://github.com/emilk/egui/issues/4771 to
make it less likely to bite users
2024-07-05 10:05:40 +02:00
Emil Ernerfeldt 977d83a08f
Hide tooltips when scrolling (#4784)
* Closes #4781
2024-07-05 09:39:12 +02:00
Emil Ernerfeldt 143119943d
Show the innermost debug rectangle when pressing all modifier keys (#4782)
This is usually what the user is interested in.
2024-07-05 08:36:56 +02:00
rustbasic ad597a8491
Add `Image::uri()` (#4720)
`uri()` for image

The advantages of this are :

1. No need for `ctx()` and `source()`
2. Displays `name.gif#0` as `name.gif`
2024-07-05 08:20:20 +02:00
lucasmerlin 9a4c46289e
Check if the mouse / touch event is above the canvas via element_from_point (#4775)
* Closes #4752 

To test, start the web demo and follow the repro steps from #4752
2024-07-05 08:18:53 +02:00
Emil Ernerfeldt b31d02dd21
Fix default height of top/bottom panels (#4779)
The inner size is now `interactive_size.y`, like in 0.27.

* Closes https://github.com/emilk/egui/issues/4773
* Broke in https://github.com/emilk/egui/pull/4351

Thanks to @valadaptive for reporting and diagnosing the bug
2024-07-04 11:05:43 +02:00
Emil Ernerfeldt 042e1add41
Better documentation for `Event::Zoom` (#4778)
* Closes https://github.com/emilk/egui/issues/4777

Also add this to the 0.28 migration guide.
2024-07-04 10:31:27 +02:00
Emil Ernerfeldt 8bf498d2bf Fix sizing of `images` example 2024-07-03 15:49:05 +02:00
Emil Ernerfeldt 234274d46f Release 0.28.0 - Sizing pass, and better eframe web 2024-07-03 14:54:08 +02:00
Emil Ernerfeldt bca9a04acd
Use correct cursor icons when resizing panels too wide or narrow (#4769) 2024-07-03 14:33:11 +02:00
Emil Ernerfeldt 47accb0eeb Tooltip fix: Only treat enabled widgets as interactive 2024-07-03 13:11:48 +02:00
Emil Ernerfeldt 249b69d534
Make sure all tooltips close if you open a menu in the same layer (#4766) 2024-07-03 12:33:23 +02:00