Commit Graph

3581 Commits

Author SHA1 Message Date
Antoine Beyeler 3411aba768
Modals: Add `UiKind::Modal`, and consume escape-key properly (#5414)
Small fixes/improvements to `Modal`

- Fixes #5413
2024-12-03 11:46:37 +01:00
Emil Ernerfeldt 8647b56b31 Update snapshot for `Code Example` 2024-12-03 10:33:10 +01:00
Emil Ernerfeldt a9c76ba7a6
Allow attaching custom user data to a screenshot command (#5416)
This lets users trigger a screenshot from anywhere, and then when they
get back the results they have some context about what part of their
code triggered the screenshot.
2024-12-03 10:08:55 +01:00
Emil Ernerfeldt 6a1131f1c9 Fix docstring backticks 2024-12-03 09:55:25 +01:00
Juan Campa 4f7f23ef5e
Fix cursor clipping in `TextEdit` inside a `ScrollArea` (#3660)
<!--
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.
* 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 cranky`.
* 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 #1531

### Before
Notice how the cursor hides after third enter and when the line is long.


https://github.com/user-attachments/assets/8e45736e-d6c7-4dc6-94d0-213188c199ff

### After
Cursor is always visible


https://github.com/user-attachments/assets/43200683-3524-471b-990a-eb7b49385fa9


- `ScrollArea` now checks if there's a `scroll_target` in `begin`, if
there is, it saves it because it's not from its children, then restore
it in `end`.
- `TextEdit` now allocates additional space if its galley grows during
the frame. This is needed so that any surrounding `ScrollArea` can bring
the cursor to view, otherwise the cursor lays outside the the
`ScrollArea`'s `content_ui`.
2024-12-02 09:29:06 +01:00
Jochen Görtler 6833cf56e1
Add new `Rect::intersects_ray_from_center` method (#5415)
<!--
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!
-->
Title.

* [x] I have followed the instructions in the PR template
2024-12-02 09:20:59 +01:00
Emil Ernerfeldt 328422dc62
Update MSRV to Rust 1.79 (#5421)
Mostly to fix `cargo-machete` CI
2024-12-01 18:58:35 +01:00
lucasmerlin 7e3275ca5c
Fix cargo machete (#5410)
* [x] I have followed the instructions in the PR template

cargo machete depends on cargo-platform which seems to bumped it's msrv.
Installing via --locked should fix this for now. I think it's fine to do
this manually instead of using the cargo action since it's so simple and
the action we used basically did the same (without --locked)
2024-12-01 18:57:41 +01:00
Valentin c86d0e5918
fix accidental change of FallbackEgl to PreferEgl (#5408)
I accidentally changed this in a previous commit when I meant to only
change the comment above it.

https://github.com/emilk/egui/pull/5392#discussion_r1859383653
2024-11-30 12:56:23 +01:00
lucasmerlin 10791cc43d
Add `Modal` and `Memory::set_modal_layer` (#5358)
* Closes #686 
* Closes #839 
* #5370 should be merged before this
* [x] I have followed the instructions in the PR template

This adds modals to egui. 
This PR
- adds a new `Modal` struct
- adds `Memory::set_modal_layer` to limit focus to a layer and above
(used by the modal struct, but could also be used by custom modal
implementations)
- adds `Memory::allows_interaction` to check if a layer is behind a
modal layer, deprecating `Layer::allows_interaction`



Current problems:
- ~When a button is focused before the modal opens, it stays focused and
you also can't hit tab to focus the next widget. Seems like focus is
"stuck" on that widget until you hit escape. This might be related to
https://github.com/emilk/egui/issues/5359~ fixed!

Possible future improvements: 
- The titlebar from `window` should be made into a separate widget and
added to the modal
- The state whether the modal is open should be stored in egui
(optionally), similar to popup and menu. Ideally before this we would
refactor popup state to unify popup and menu

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-11-28 16:52:05 +01:00
Samson 84cc1572b1
Update glow to 0.16 (#5395)
<!--
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

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2024-11-26 21:00:34 +01:00
Nicolas 88543270e0
Fix CI failures (#5407)
Fixes the RUSTSEC-2024-0399 issue with rustls and the errors in the
regression test
See:
https://rustsec.org/advisories/RUSTSEC-2024-0399.html
https://github.com/rustls/rustls/issues/2227

This also fixes the cargo deny runs which are currently failing

* [x] I have followed the instructions in the PR template
2024-11-26 20:09:59 +01:00
Valentin 7cee35c02a
document justification for FallbackEgl (#5392)
The previous link does not explain why we chose FallbackEgl. This is a
better link.
2024-11-26 15:23:43 +01:00
Valentin 6359ba7e66
forward x11 and wayland features to glutin (#5391)
eframe has features for selecting between x11 and wayland. eframe does
not forward the features to glutin. This makes glutin always compile
with both backends enabled. This change forwards the feature. This
allows users of egui to compile less dependencies when they only need
one of x11, wayland.

To understand this change, read the glutin Cargo.toml [1] and the glutin
build.rs [2]. You always have to enable glutin's glx feature with the
x11 feature. The other default features (egl, wgl) stay enabled. This is
intentional so that everything continues to work as before. We could
further minimize when egl and wgl are enabled, but that is not part of
this change. There is little reason to do so because those feature
already only add dependencies when you compile glutin for the right
platform (for example wgl on windows).

[1]
https://github.com/rust-windowing/glutin/blob/v0.32.1/glutin/Cargo.toml
[2]
https://github.com/rust-windowing/glutin/blob/v0.32.1/glutin/build.rs
2024-11-26 15:22:44 +01:00
Nicolas 12f9d6f42c
add painter.line() (#5291)
* Closes <https://github.com/emilk/egui/issues/5273>
* [x] I have followed the instructions in the PR template
2024-11-26 15:17:47 +01:00
lucasmerlin e28505077d
Update accesskit to 0.17 (#5372)
Updates accesskit and kittest. 

* [x] I have followed the instructions in the PR template
2024-11-26 15:16:08 +01:00
lucasmerlin 2f9b14def8
Add links to the wiki and move integrations there (#5373)
* [x] I have followed the instructions in the PR template
2024-11-26 15:00:38 +01:00
lucasmerlin 9ecc0b232c
Fix disabled widgets "eating" focus (#5370)
- fixes https://github.com/emilk/egui/issues/5359

For the test I added a `Harness::press_key` function. We should
eventually add these to kittest, probably via a trait one can implement
for the `Harness` but for now this should do.
2024-11-26 14:31:30 +01:00
Elie Michel 83a30064f4
Minor typo in README (#5381) 2024-11-18 17:28:22 +01:00
GiGaGon 1787952a83
Create gray -> grey doc aliases (#5362)
As someone who uses "grey" instead of "gray", it is annoying that my
autocomplete can never find any of the "gray" color related things, so
this adds doc aliases for that.

* [x] I have followed the instructions in the PR template
2024-11-11 13:21:58 +01:00
lucasmerlin 3c7ad0ee12
egui_kittest: Allow passing state to the app closure (#5313)
The allows us to pass any state to the ui closure. While it is possible
to just store state in the closure itself, accessing that state after
the harness was created to e.g. read or modify it would require interior
mutability. With this change there are new `Harness::new_state`,
`Harness::run_state`, ... methods that allow passing state on each run.

This builds on top of #5301, which should be merged first

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-11-06 14:43:41 +01:00
Emil Ernerfeldt fc743d63b4 Add link to helpful article in font alpha TODO 2024-11-06 13:33:43 +01:00
lucasmerlin 5d6a58b917
Fix some typos (#5339)
The spell check pipeline in #5313 suddenly failed, this fixes these
typos and some more found via my IDEs spell checker tool
2024-11-04 09:51:34 +01:00
lucasmerlin ad14bf2490
Add `Harness::new_ui`, `Harness::fit_contents` (#5301)
This adds a `Harness::new_ui`, which accepts a Ui closure and shows the
ui in a central panel. One big benefit is that this allows us to add a
fit_contents method that can run the ui closure with a sizing pass and
resize the "screen" based on the content size.

I also used this to add a snapshot test for the rendering_test at
different scales.
2024-11-01 18:30:40 +01:00
Cody Neiman 21826bec18
Use proper `image` crate URI and MIME support detection (#5324)
<!--
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

I removed the webp supported URI test given that the webp feature would
have to be enabled. I kept that webp is not supported in the other
tests.

There might need to be an additional warning in the changelog that image
support detection is now stricter.
2024-11-01 13:33:12 +01:00
StarStarJ 3f5cd74de7
Put font data into Arc to reduce memory consumption (#5276)
egui never accesses the `FontDefinitions`' member fields mutably, except
in `fonts_tweak_ui` where it cloned the `FontDefinitions` object anyway.

This patch reduces system memory consumption for shared font
definitions.
And also removes some overhead from copying (e.g. for the per
`pixel_per_points` font atlas)

Also it allows to keep a copy of the font definitions outside of egui.

In my App that uses international fonts:
Before:

![image](https://github.com/user-attachments/assets/f8dfb4f4-a21c-447c-8cf9-83025ad6e960)

New:

![image](https://github.com/user-attachments/assets/9f297fbd-e620-4b7e-a32a-65073ee805ed)


Note: If `Arc` is not wanted, then it could ofc be abstracted away.

I know this is quite a breaking change API wise, but would like to hear
your opinion.
2024-11-01 13:30:02 +01:00
lucasmerlin 793cb92557
Add egui_kittest label to workflow and changelog script (#5323)
* [X] I have followed the instructions in the PR template
2024-11-01 13:25:41 +01:00
YgorSouza 444c21a437
Prevent panic when copying text outside of a secure context (#5326)
* Closes <https://github.com/emilk/egui/issues/5293>
* [x] I have followed the instructions in the PR template
2024-11-01 13:21:59 +01:00
lucasmerlin bbbd936f50
Exclude icon.png from lfs (#5336)
* Closes #5331 
* [x] I have followed the instructions in the PR template
2024-11-01 13:21:05 +01:00
Emil Ernerfeldt 42652e223c
Update some crates (#5337) 2024-11-01 13:07:01 +01:00
TÖRÖK Attila 67c82ed5f2
wgpu: Bump to wgpu 23.0.0 and wasm-bindgen to 0.2.95 (#5330)
Co-authored-by: Andreas Reich <r_andreas2@web.de>
2024-10-30 18:53:22 +01:00
valadaptive 5bfff316c9
Fix documentation for file drag and drop (#5328)
<!--
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!
-->

The `RawInput::dropped_files` documentation referred to `NativeOptions`,
but the `drag_and_drop` option was moved to `ViewportBuilder` and is now
enabled by default.

Note that drag-and-drop is not *explicitly* enabled by default here, but
rather is enabled by default in winit. We only override winit's default
if the API consumer specifies it. It might be a good idea in general to
provide explicit defaults for everything in `ViewportBuilder` so we're
not relying on winit's behavior, but that's best left for another PR.

* Closes N/A
* [x] I have followed the instructions in the PR template
2024-10-30 15:24:45 +01:00
Cody Neiman 2cd3485dd4
Update MSRV from 1.76 to 1.77 (#5322)
<!--
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

I am preparing a separate PR that adds support for JXL with `jxl-oxide`,
which is unlikely to be added to the `image` crate anytime soon (more
context will be provided in that PR).

`jxl-oxide` makes use of the
[`array::each_mut`](https://doc.rust-lang.org/stable/std/primitive.array.html#method.each_mut)
API which was stabilized in 1.77, which is the motivation for this MSRV
bump.

Rust 1.77 was officially released to stable on 21 March, 2024.
2024-10-30 09:06:34 +01:00
lucasmerlin dafcfdad80
egui_kittest: Allow customizing the snapshot threshold and path (#5304)
This adds `egui_kittest::try_image_snapshot_options` and
`egui_kittest::image_snapshot_options`, as well as
`Harness::wgpu_snapshot_options` and
`Harness::try_wgpu_snapshot_options`

* [X] I have followed the instructions in the PR template
2024-10-29 19:52:21 +01:00
Arthur Brussee 759a0b2a21
Add option to initialize on existing wgpu setup (#5319)
When mixing and matching eframe with other wgpu applications
(https://github.com/tracel-ai/burn in my case), it can be helpful to use
an existing wgpu setup to initialize eframe with. This PR changes the
WpuConfiguration (in a non-backwards compat way :/), to either take some
options how to create a wgpu setup, or an existing wgpu setup
(consisting of an instance, adapter, device and queue).

* [x] I have followed the instructions in the PR template

---------

Co-authored-by: Andreas Reich <r_andreas2@web.de>
2024-10-29 17:12:28 +01:00
Bruce Mitchener fba2dc85a3
egui-winit: Remove implicit `accesskit_winit` feature (#5316)
This is controlled by the `accesskit` feature and nothing needs the
implicit `accesskit_winit` feature, so use `dep:` syntax to prevent it
from being created.

* [x] I have followed the instructions in the PR template
2024-10-29 13:09:31 +01:00
MStarha 44877d490e
Respect `Style::override_font_id` in `RichText` (#5310)
<!--
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!
-->

Currently `Style::override_font_id` does not affect widgets with their
`TextStyle` like `Button`s, `ComboBox`es, `CheckBox`es, etc. This PR
fixes this behavior such that all widgets using default configuration of
`RichText` are affected by this setting.
* [x] I have followed the instructions in the PR template
2024-10-29 12:51:17 +01:00
rustbasic 926799a167
Fix: Popup incorrectly calculates possible min width of popup causing panic (#5208)
Fix: Popup incorrectly calculates possible min width of popup causing
panic

* Closes #5206
2024-10-29 12:43:05 +01:00
zhatuokun c7d46ac9f9
Fix: `Sides` did not apply the layout position correctly. (#5303)
Same as last time, but use `available_rect_before_wrap` to avoid
containing infinity.
2024-10-29 12:42:02 +01:00
rustbasic 3f2bd14554
Fix: Window::default_pos does not work (#5315)
Fix: Window::default_pos does not work

Issues: Since `default_size` is not applied to `area`,
`style.spacing.default_area_size` is applied, causing problems.

* Closes #5314
2024-10-29 12:40:51 +01:00
Adrian Valcarcel-Schott 98916489f7
Add `ComboBox::close_behavior` (#5305)
Exposed the underlying PopupCloseBehavior of ComboBox in order to allow
more control of ComboBox behavior.

This allows ComboBox to be used rather than manually managing a popup
directly, while also gaining the convenience features of ComboBox such
as popup auto-sizing.

* [x] I have followed the instructions in the PR template
2024-10-29 12:39:44 +01:00
Zeenobit ce05b59689
Add `Window::scroll_bar_visibility` (#5231)
Trivial changelist to allow setting the scroll visibility on `Window`.
2024-10-29 12:35:48 +01:00
Dimitris Papaioannou ebb4646358
Impl from Box<str> for WidgetText, RichText (#5309)
`Box<str>` is an immutable heap-allocated string slice.
This PR makes it more convenient to use them in labels for example.

Before this PR
```rust
let text: Box<str> = "Hello".into();
ui.label(text.into_string());

let text_ref: &Box<str> = &"Hello".into();
ui.label(text_ref.clone().into_string());
// or
ui.label(text_ref.as_ref());
// or
ui.label(&**text_ref);
```
After this PR
```rust
let text: Box<str> = "Hello".into();
ui.label(text);

let text_ref: &Box<str> = &"Hello".into();
ui.label(text_ref);
```

* [x] I have followed the instructions in the PR template
2024-10-29 10:50:06 +01:00
rustbasic 288c74e332
Expand max font atlas size from 8k to 16k (#5257)
When using fonts with an average of 50,000 characters,
'epaint texture atlas overflowed!' may be printed and cause problems.
It is necessary to expand the max value related to texture.

* Closes #5256

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-10-29 10:42:28 +01:00
Emil Ernerfeldt 68352fc13e
CI: check that all png images are on git LFS (#5321)
To prevent egui repository from growing forever

* Sibling PR: https://github.com/emilk/egui/pull/5320
2024-10-29 10:30:25 +01:00
Emil Ernerfeldt 9e763fcc01 fix line-endings on clippy.toml 2024-10-29 10:10:59 +01:00
Emil Ernerfeldt 7b69ec3473
Move all existing .png images to git LGS (#5320)
* Sibling PR: https://github.com/emilk/egui/pull/5321
2024-10-29 10:04:07 +01:00
Wybe Westra 4622fff28c
Report egui::Window contents as children to accesskit (#5240)
Previously, all widgets would be listed in accesskit as children of the
toplevel window.
With this change, they will be reported as child of the `egui::Window`
they are in, Which should increase parseability of the ui for
screenreaders and integration tests.

Added an accesskit test to check that it is indeed working.

Co-authored-by: Wybe Westra <w.westra@kwantcontrols.nl>
2024-10-29 09:52:06 +01:00
lucasmerlin 4e101d25cd
Fix textedit intrinsic size metric (#5275)
Since textedit is doing the justify layout calculation itself, we need
to report the original desired_size as intrinsic size, instead of the
value passed to allocate_space.

I wonder though, is it still necessary that the TextEdit does the
justify calculation itself instead of relying on the ui layout to do it?
As far as I understand it, justify should be handled by the
ui.allocate_space call.
2024-10-28 13:58:34 +01:00
lucasmerlin 5b846b4554
Fix cargo test in check.sh (#5299)
The check.sh script was broken in #5166, this fixes it
* Related to #5297 
* [x] I have followed the instructions in the PR template

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-10-24 14:05:06 +02:00