Commit Graph

3214 Commits

Author SHA1 Message Date
Emil Ernerfeldt a8b50e6aa1
Move test crates to own folder (#4554) 2024-05-27 21:28:33 +02:00
YgorSouza 7a17a6d6ad
Plot now respects the `interact_radius` set in the UI's style (#4520)
* Closes #4519
2024-05-27 19:23:15 +02:00
lucasmerlin 8553e738e0
eframe: Add `NativeOptions::persistence_path` (#4423)
This allows customizing the persistence path in NativeOptions.
Previously, persistence wouldn't work with android because
directories-next doesn't support android so eframe would just fail to
find a place where it could store its config.

* Closes #4098 (android users can now specify a path that works with
android, by e.g. using app_dirs2, which supports android)
2024-05-27 18:57:39 +02:00
Antoine Beyeler 192a111272
Hide all other series when alt-clicking in the legend (#4549)
https://github.com/emilk/egui/assets/49431240/75d32f53-4c1c-4713-b25e-e1787e465a48

* Closes #4548
2024-05-27 18:56:16 +02:00
zaaarf ff7a3832b6
TextEdit hint text styling (#4517)
Simply adds a `hint_text_font` (any suggestions for a better name?
hint_text_style seemed misleading as it doesn't only accept `TextStyle`)
method to the TextEdit builder that allows to set the styling
(specifically, a `FontSelection`) for the hint text.

My personal use-case for this was having body-sized hint text in a
heading-sized TextEdit, but I'm sure there's more out there.

The PR shouldn't break compatibility, as it's stored as an `Option` that
defaults to the `font_id` (which was the only behaviour prior to this)
when empty.

It looked too trivial to add something to the actual demo, but I have it
locally, so let me know if I should commit that.

Ran the check script locally, had no complaints.
2024-05-27 17:28:03 +02:00
Doonv 1ae2d2803a
Make `TextEdit::return_key` optional (#4543)
I wanted to disable the return key functionality on my `TextEdit`, so
that the `TextEdit` doesn't get unfocused whenever the user submits a
command onto my developer console (which is also bound to <kbd>↵
Enter</kbd>).
2024-05-27 16:43:48 +02:00
Oscar Gustafsson cd45d18615
Do no use the ahash reimport (#4504)
<!--
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!
-->

Related to #3482 

Not sure what the "best practice" is, to me it seems like one should
import from "the original location" if possible, but now it should at
least be possible to not re-export ahash without any breakage in the
egui code base (but possibly in projects using egui, so one should
probably deprecate it if one would like to go that path). It also seems
like epaint re-exports ahash.
2024-05-27 16:24:50 +02:00
Ryan Bluth f0cbb18943
Don't panic when replacement glyph is not found (#4542)
I wanted to implement a font picker that loads all system fonts but ran
into panics due to missing glyphs. Falling back to an empty glyph when
none of the fallback glyphs are available avoids the panic.
2024-05-27 11:53:06 +02:00
Emil Ernerfeldt 34672bc1bb
Add improved pixel alignment test with alternating white/black lines (#4537)
This is a good test, because you will have obvious darkening/lightening
when this fails, and/or Moiré patterns.

<img width="490" alt="image"
src="https://github.com/emilk/egui/assets/1148717/bee74b9f-2529-4544-9102-2ee273eade2d">
2024-05-24 15:55:36 +02:00
Emil Ernerfeldt a98c42e317
Add `Options::line_scroll_speed` and `scroll_zoom_speed` (#4532)
This lets integrations and user change how sensitive egui is to scroll
events
2024-05-23 10:07:08 +02:00
Emil Ernerfeldt 8433b43231
Smooth out zooming with discreet scroll wheel (#4530)
* closes https://github.com/emilk/egui/issues/4525

You can zoom in using ctrl/cmd + scrolling. When using a discreet scroll
wheel, the zoom factor now gets smoothed.
2024-05-23 09:56:36 +02:00
Emil Ernerfeldt 8db8f6df82
Remove scroll latency for smooth trackpads (#4526)
* Closes https://github.com/emilk/egui/issues/4401

It was small, but annoying. Now we get that butter smooth scrolling on
mac trackpads again, with no latency
2024-05-23 08:50:48 +02:00
Emil Ernerfeldt 48045e57da
Remove `Event::Scroll` and handle it in egui (#4524)
For integrations: just emit `egui::Event::MouseWheel` (like before).
egui will interpret that as zoom or pan.

On the way towards https://github.com/emilk/egui/issues/4401
2024-05-22 21:35:15 +02:00
Emil Ernerfeldt c8578c9a6b
Fix: still track mouse when dragging outside web canvas (#4522)
* Closes https://github.com/emilk/egui/issues/3157

If the mouse leaves the canvas when dragging a slider, the slider will
still move.

---

To support this, I had to revert https://github.com/emilk/egui/pull/4419
Despite that, I fail to reproduce the two issues it claimed to solve:

* https://github.com/emilk/egui/issues/4406 may have been solved in
another way by this PR
* https://github.com/emilk/egui/issues/4418 I cannot reproduce on Mac.
If it is still a problem, I think it should be solved by triggering a
`PointerEvent::Released` when focus is lost (i.e. on alt-tab), and not
on `PointerGone`
2024-05-22 11:48:34 +02:00
YgorSouza 7035aa4e53
`include_image!` now accepts expressions (#4521)
Closes https://github.com/emilk/egui/issues/4510
2024-05-21 22:44:27 +02:00
hut 262a8bcf98
Ignore synthetic key presses (#4514)
This PR discards "synthetic" winit keypresses, as discussed in the issue
#4513.

* Closes https://github.com/emilk/egui/issues/4513
2024-05-21 18:29:45 +02:00
hellodword 8321f64f6e
Update ahash 0.8.6 -> 0.8.11 (#4507)
See:
https://github.com/tkaitchuck/aHash/pull/183#issuecomment-1789806373

* Closes https://github.com/emilk/egui/issues/4476
2024-05-20 17:31:17 +02:00
Emil Ernerfeldt 738ea75453 Add clippy::use_self lint 2024-05-16 17:28:37 +02:00
Emil Ernerfeldt 6b607ffa2a Remove unmaintained `amethyst_egui` from README.md 2024-05-16 13:33:07 +02:00
Fabian Lippold ce59e43869
Introduce lifetime to `egui_plot::Plot` to replace `'static` fields (#4435)
* Closes https://github.com/emilk/egui/issues/4434

Shouldn't break anything, because when all arguments have a 'static
lifetime (required without this PR), the Plot is also 'static and can be
used like before.
2024-05-15 09:58:31 +02:00
Oscar Gustafsson c1eb3f884d
Move dependencies to workspace (#4495)
<!--
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!
-->

Inspired by:

44d65f41ac/Cargo.toml (L65)

I took the liberty of removing that comment since I *think* that I got
all "relevant" ones (showing up more than once, sort of).
2024-05-14 11:02:49 +02:00
Emil Ernerfeldt 44d65f41ac
Update `image` crate to 0.25 (#4160)
To not produce duplicating deps in Rerun
(https://github.com/rerun-io/rerun/pull/5280) I suggest we wait with
merging this until these crates have updated to `image` 0.25:
* [x] [`arboard`](https://crates.io/crates/arboard)
* [x] [`gltf`](https://crates.io/crates/gltf)
2024-05-13 13:35:15 +02:00
crumblingstatue acfe9f6f3b
Make `epaint::mutex::RwLock` allow `?Sized` types (#4485)
`parking_lot`'s `RwLock` allows this, so probably `epaint`'s `RwLock`
should too.
Although I'm not sure how much it's intended for users, rather than just
internal use by `egui`.
2024-05-13 12:49:31 +02:00
Emil Ernerfeldt c3f386aa30
Remove work-around for `unsafe` in puffin macro (#4484)
…since it is no longer in the puffin macro
2024-05-11 20:17:19 +02:00
Emil Ernerfeldt 059218d954
eframe: Remove dependency on `thiserror` (#4483)
Less dependencies => faster compile times

* Part of https://github.com/emilk/egui/issues/4481
2024-05-11 20:17:06 +02:00
Emil Ernerfeldt 4f2f057508
Update arboard (#4482)
Updating arboard v3.3.1 -> v3.4.0
    Updating clipboard-win v5.1.0 -> v5.3.1
2024-05-11 20:01:40 +02:00
rustbasic 3b3ce22adc
Make sure plot size is positive (#4429)
* Closes #4425 

Fix: in Plot, Minimum values for screen protection.
2024-05-11 16:49:27 +02:00
Avery Radmacher e06b225dab
Fix: Window position creeps between executions on scaled monitors (#4443)
<!--
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!
-->

* Closes <https://github.com/emilk/egui/issues/4442>
* Refactors active monitor detection so it can be called from multiple
locations.

Compare this gif to the one on the issue report.

![egui_window_position_no_creep](https://github.com/emilk/egui/assets/45777186/8e05d4fb-266e-48b9-9223-b65f16500a99)

### Investigation notes

- [`WindowSettings.inner_position_pixels` and
`WindowSettings.outer_position_pixels`](https://github.com/emilk/egui/blob/master/crates/egui-winit/src/window_settings.rs#L8-L12)
are stored in physical/pixel coordinates.
- `ViewportBuilder::with_position` expects to be passed a position in
_logical_ coordinates.
- Prior to this PR, the position was being passed from `WindowSettings`
to `with_position` [without any
scaling](https://github.com/emilk/egui/blob/master/crates/egui-winit/src/window_settings.rs#L61-L68).
This was the root cause of the issue.
- The fix is to first convert the position to logical coordinates,
respecting the scaling factor of the active monitor. This requires us to
first determine the active monitor, so I factored out some of the logic
in
[`clamp_pos_to_monitor`](https://github.com/emilk/egui/blob/master/crates/egui-winit/src/window_settings.rs#L130)
to find the active monitor.
2024-05-11 16:48:12 +02:00
rustbasic 66d2b3ffe4
Treat `Event::PointerGone` as `PointerEvent::Released` (#4419)
* Closes #4406
* Closes #4418 

If `Event::PointerGone` occurs, it is treated as
`PointerEvent::Released`.
2024-05-11 13:17:58 +02:00
Varphone Wong 11fa9cc7ee
Disable interaction for `ScrollArea` and `Plot` when UI is disabled (#4457)
## Summary

This PR modifies `ScrollArea` and `Plot` to disable their interactions
when the UI is disabled.

## Changes

- Interaction with `ScrollArea` in `egui` is disabled when the UI is
disabled.
- Interaction with `Plot` in `egui_plot` is disabled when the UI is
disabled.
- These changes ensure that `ScrollArea` and `Plot` behave consistently
with the rest of the UI, preventing them from responding to user input
when the UI is in a disabled state.

## Impact

This PR enhances the consistency of `egui`'s UI behavior by ensuring
that all elements, including `ScrollArea` and `Plot`, respect the UI's
disabled state. This prevents unexpected interactions when the UI is
disabled.

Closes #4341
2024-05-11 00:42:03 +02:00
rustbasic 27a22f991d
Fix : In Windows, the 'egui_demo_app' screen does not appear. (#4410)
* Related #4337 
* Closes #4409 

Fix : In Windows, the 'egui_demo_app' screen does not appear After the
#4337 update.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-05-11 00:41:02 +02:00
rustbasic a9efbcff36
IME for chinese (#4436)
* Completed.

* Closes #4430

IME for chinese
2024-05-11 00:09:14 +02:00
TicClick 2b2e70cb91
egui-winit: emit physical key presses when a non-Latin layout is active (#4461)
resolves https://github.com/emilk/egui/issues/4081 (see discussion
starting from
https://github.com/emilk/egui/issues/3653#issuecomment-1962740175 for
extra context)

this partly restores event-emitting behaviour to the state before #3649,
when shortcuts such as `Ctrl` + `C` used to work regardless of the
active layout. the difference is that physical keys are only used in
case of the logical ones' absence now among the named keys.

while originally I have only limited this to clipboard shortcuts
(Ctrl+C/V/X), honestly it felt like a half-assed solution. as a result,
I decided to expand this behaviour to all key events to stick to the
original logic, in case there are other workflows and hotkeys people
rely on or expect to work out of the box. let me know if this is an
issue.
2024-05-11 00:07:42 +02:00
Emil Ernerfeldt f19f99180e
Remove `extra_asserts` and `extra_debug_asserts` feature flags (#4478)
Removes `egui_assert` etc and replaces it with normal `debug_assert`
calls.

Previously you could opt-in to more runtime checks using feature flags.
Now these extra runtime checks are always enabled for debug builds.

You are most likely to encounter them if you use negative sizes or NaNs
or other similar bugs.
These usually indicate bugs in user space.
2024-05-10 19:39:08 +02:00
Emil Ernerfeldt 155e138998 Fix debug-assert hit in panel sizing code 2024-05-10 19:21:35 +02:00
Emil Ernerfeldt dce5696b67 Show Cargo.lock in GitHub PR diffs 2024-05-10 11:38:54 +02:00
Emil Ernerfeldt ded8dbd45b
Fix some clippy warning from Rust 1.78.0 (#4444) 2024-05-02 17:04:25 +02:00
Simon Niedermayr c9b24d5a5c
Update to wgpu 0.20 (#4433)
updates the wgpu version to 0.20 and changes the API calls accordingly. 
I had to update wasm-bindgen to "0.2.92". Otherwise, I got this error
for the demo app:
```
error: failed to select a version for `wasm-bindgen`.
    ... required by package `js-sys v0.3.69`
    ... which satisfies dependency `js-sys = "^0.3.69"` of package `eframe v0.27.2 (/home/user/Projects/egui/crates/eframe)`
    ... which satisfies path dependency `eframe` (locked to 0.27.2) of package `confirm_exit v0.1.0 (/home/user/Projects/egui/examples/confirm_exit)`
versions that meet the requirements `^0.2.92` are: 0.2.92

all possible versions conflict with previously selected packages.

  previously selected package `wasm-bindgen v0.2.90`
    ... which satisfies dependency `wasm-bindgen = "=0.2.90"` of package `egui_demo_app v0.27.2 (/home/user/Projects/egui/crates/egui_demo_app)`

failed to select a version for `wasm-bindgen` which could resolve this conflict
```

Why is it locked to this version right now?

I ran the tests, checked the web demo and my own projects, and
everything seems to work fine with wgpu 0.20.

---------

Co-authored-by: Andreas Reich <r_andreas2@web.de>
2024-04-30 11:47:12 +02:00
Trevor Gross 2fabde1396
Add a `Display` impl for `Vec2`, `Pos2`, and `Rect` (#4428)
These three types currently have a `Debug` implementation that only ever
prints one decimal point. Sometimes it is useful to see more of the
number, or otherwise have specific formatting.

Add `Display` implementations that pass the format specification to the
member `f32`s for an easier way to control what is shown when debugging.

This allows doing e.g. `ui.label(format!("{:.4}", rect * scale))` which
currently prints zeroes if scale is small.
2024-04-29 14:22:34 +02:00
Patrick José Pereira af39bd22ab
crates: egui_demo_lib: Fix table height (#4422)
* Closes #4404

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2024-04-29 11:16:55 +02:00
hardlydearly 3bb33980a9
chore: remove repetitive words (#4400)
<!--
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 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!
-->

remove repetitive words

Signed-off-by: hardlydearly <799511800@qq.com>
2024-04-29 10:33:29 +02:00
Simon Frankau c1fc9213c3
Enable egui_glow's winit feature on wasm (#4420) (#4421)
Reverts change in #1303, enabling the egui_glow::winit module when using
wasm.

* Closes <https://github.com/emilk/egui/issues/4420>
2024-04-29 10:33:23 +02:00
YgorSouza 0bc59f578b
Fix some typos from the cranky-clippy transition (#4417) 2024-04-26 07:46:25 +02:00
Emil Ernerfeldt 2f508d6a61
Replace cargo-cranky with workspace lints (#4413)
Replace `cargo-cranky` (which has served us well) with workspace lints
2024-04-25 17:24:50 +02:00
Emil Ernerfeldt cee790681d
Update to Rust 1.76 (#4411)
Motivation: I want to replace `cargo-cranky` with workspace lints, first
available in Rust 1.74.
However, `cargo doc` would hange on `wgpu` and `wgpu-core` on 1.74 and
1.75… so now we're on 1.76.
I think this is fine - when 1.78 is released next week we're still two
versions behind the bleeding edge.

…and the branch name is just wrong 🤦
2024-04-25 15:51:01 +02:00
Dennis Schön bfe1858e0b
eframe: update ViewportBuilder.with_icon() documentation (#4408)
`None` is no longer correct. To disable the egui icon one has to pass
`IconData::default()` now.
2024-04-25 15:43:24 +02:00
Mads Marquart 14194f5d3a
eframe: Use `objc2` and its framework crates (#4395)
These are a replacement to the `objc` and `cocoa` crates.

This PR prevents:
- An extra copy when creating `NSData`
- A memory leak when creating `NSImage`
- A memory leak when creating `NSString`

And is generally a readability improvement.

Note that we define `NSApp` manually for now, the implementation in
`objc2-app-kit` is currently suboptimal and wouldn't allow you to check
whether the NSApplication has been created or not.

Related: https://github.com/emilk/egui/issues/4219, this should nicely
coincide with the Winit `0.30` release.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-04-23 17:35:12 +02:00
TÖRÖK Attila 2c590636b5
`egui-winit`: Update `webbrowser` to `v1.0.0` (#4394)
No significant changes, mostly marks API stability:
https://github.com/amodm/webbrowser-rs/releases/tag/v1.0.0
2024-04-23 08:03:36 +02:00
Joe Sorensen 2ce82cce21
Added ability to define colors at UV coordinates along a path (#4353)
<!--
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 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!
-->

I had to make a couple types not Copy because closures, but it should'nt
be a massive deal.

I tried my best to make the API change as non breaking as possible.
Anywhere a PathStroke is used, you can just use a normal Stroke instead.
As mentioned above, the bezier paths couldn't be copy anymore, but IMO
that's a minor caveat.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-04-22 18:35:09 +02:00
lopo ff8cfc2aa0
Allow users to create viewports larger than monitor on Windows & macOS (#4337)
Added clamp_size_to_monitor_size field on ViewportBuilder, which means
whether clamp the window's size to monitor's size. (default to `true`)

* Closes https://github.com/emilk/egui/issues/3389

### simple example

```rust
pub struct MyApp {}

impl MyApp {
    pub fn new() -> MyApp {
        MyApp {}
    }
}

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &Context, frame: &mut eframe::Frame) {
        egui::CentralPanel::default()
            .frame(Frame::none().fill(Color32::DARK_GRAY))
            .show(ctx, |ui| {
                if ctx.input(|i| i.key_pressed(Key::Escape)) {
                    ctx.send_viewport_cmd(ViewportCommand::Close);
                }
            });
    }
}

pub fn main() {
    let option = eframe::NativeOptions {
        viewport: ViewportBuilder::default()
            .with_position([10.0, 10.0])
            .with_inner_size([3000.0, 2000.0])
            .with_clamp_size_to_monitor_size(false),
        ..Default::default()
    };

    eframe::run_native(
        "a large window app",
        option,
        Box::new(|ctx| Box::new(MyApp::new())),
    ).unwrap();
}
```

It works on my windows (with 3 monitors), but I don't have a test
environment for macos

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-04-22 12:44:21 +02:00