Commit Graph

3641 Commits

Author SHA1 Message Date
Aely 1e0f3a5e2d
Animated WebP support (#5470)
Adds support for animated WebP images. Used the already existing GIF
implementation as a template for most of it.

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

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-12-29 11:46:08 +01:00
Emil Ernerfeldt 01a7e31b13 Update test snapshot 2024-12-29 11:27:01 +01:00
Tom Maffia 13676ea35f
Fix minor typo 2024-12-29 11:25:51 +01:00
Emil Ernerfeldt 2356ae8819 Remove colons from widget gallery 2024-12-28 23:26:26 +01:00
Emil Ernerfeldt fa95351675
Slight improvements to the demo (#5527) 2024-12-28 22:11:41 +01:00
Emil Ernerfeldt 820d42802a
Fix build of egui.rs (#5528) 2024-12-28 21:52:37 +01:00
Emil Ernerfeldt f37a8f91ca Better output when building demo 2024-12-28 21:44:56 +01:00
Ryan Bluth 8131b7b898
Make image extension lowercase before checking if it is supported (#5501)
<!--
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!
-->

* Images with capitalized extensions do not load because the list of
extensions they are checked against is lowercase. The image extension is
now converted to lowercase before comparing
* [x ] I have followed the instructions in the PR template
2024-12-28 16:01:30 +01:00
Emil Ernerfeldt c37125f835
Tweak window resize handles (#5524)
This makes it easier to hit the corners.
Previously the corner response-area was covered by the response-areas of
the edges.

* Related to https://github.com/emilk/egui/pull/5523
2024-12-27 15:50:34 +01:00
Emil Ernerfeldt 4d945f78ba
Fix widgets sometimes being incorrectly marked as hovered (#5523)
An interactive widget should only be marked hovered if a click/drag
would start an interaction with it.

egui 0.30 introduced a feature where a thin interactive widget could be
hit even if it was partially behind a larger interactive widget.
Unfortunately, this introduced a bug where the top widget would still be
marked as hovered, even though a click would go through to the thin
widget below.

This bug was most notacible when trying to reisize a window by dragging
its corner, which often would result in dragging one of its sides
instead.

This PR fixes this bug.
2024-12-27 14:47:18 +01:00
Emil Ernerfeldt d20f93e9bf
Make all lines and rectangles crisp (#5518)
* Merge this first: https://github.com/emilk/egui/pull/5517

This aligns all rectangles and (horizontal or vertical) line segments to
the physical pixel grid in the `epaint::Tessellator`, making these
shapes appear crisp everywhere.

* Closes https://github.com/emilk/egui/issues/5164
* Closes https://github.com/emilk/egui/issues/3667

This undoes a lot of the explicit, egui-side aligning added in:
* https://github.com/emilk/egui/pull/4943

The new approach has several benefits over the old one:

* It is done automatically by epaint, so it is applied to everything (no
longer opt-in)
* It is applied after any layer transforms (so it always works)
* It makes line segments crisper on high-DPI screens
* All filled rectangles now has sides that end on pixel boundaries
2024-12-26 21:02:27 +01:00
Emil Ernerfeldt dfcc679d5a
Round widget coordinates to even multiple of 1/32 (#5517)
* Closes https://github.com/emilk/egui/pull/5197
* Closes https://github.com/emilk/egui/issues/5163

This should help prevent rounding errors in layout code.

@lucasmerlin you may wanna test this with `egui_flex`
2024-12-26 20:54:24 +01:00
Emil Ernerfeldt f30f5e9578
Update to winit 0.30.7 (#5516)
Fixes wrong cursor on Mac, among other things:

https://github.com/rust-windowing/winit/releases/tag/v0.30.6
2024-12-26 12:06:24 +01:00
Jochen Görtler 7f711668b4
Provide better `debug_assert`s for ray intersections (#5504)
<!--
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. This would have helped me debug bugs quicker.

* [x] I have followed the instructions in the PR template
2024-12-19 13:39:14 +01:00
Onè 27a5803dd3
docs: remove "a" (#5499)
Was a duplicate article in the sentence. Already has "the"

<!--
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/THE_RELEVANT_ISSUE>
* [ ] I have followed the instructions in the PR template
2024-12-17 18:29:41 +01:00
lucasmerlin 8c4d8b2da8
Use correct minimum version of `profiling` crate (#5494)
We need profiling::function_scope which was introduced in 1.0.16, so
this is the minimum required version
* Closes <https://github.com/emilk/egui/issues/5491>
* [x] I have followed the instructions in the PR template
2024-12-17 09:37:15 +01:00
Emil Ernerfeldt cfc341fabd
Revert "Revert "forward x11 and wayland features to glutin" (#5391)" (#5490)
* https://github.com/emilk/egui/pull/5391
* https://github.com/emilk/egui/pull/5488
* https://github.com/emilk/egui/pull/5490
2024-12-17 09:36:03 +01:00
Emil Ernerfeldt adfc0bebfc
Revert "forward x11 and wayland features to glutin" (#5391) (#5488)
* Reverts https://github.com/emilk/egui/pull/5391

Because it causes head-ache:
https://github.com/emilk/eframe_template/actions/runs/12357896151/job/34487194281
2024-12-16 19:25:21 +01:00
Emil Ernerfeldt d864655018 Reorder crate publish steps 2024-12-16 18:10:01 +01:00
Emil Ernerfeldt 629f64551a Remove cyclic dependency of egui_demo_lib on itself 2024-12-16 18:10:01 +01:00
Emil Ernerfeldt 5b2b8cfb34 Remove cylic dependency of egui_kittest on itself 2024-12-16 18:10:01 +01:00
Emil Ernerfeldt eb403655ce Move egui tests to avoid cyclic dependency 2024-12-16 18:10:01 +01:00
lucasmerlin 69dbb00087
Simplify kittest readme example (#5486)
Updates the example using the new_ui function, and call fit_contents
- [x] I have followed the instructions in the PR template
2024-12-16 18:02:21 +01:00
Emil Ernerfeldt 320377e3ca
Release 0.30 - egui_kittest and modals (#5487) 2024-12-16 17:45:35 +01:00
Emil Ernerfeldt 0fb340fe89 Use released version of kittest 2024-12-16 17:10:39 +01:00
Emil Ernerfeldt 045ed41efc
Fix zero-width strokes still affecting the feathering color of boxes (#5485) 2024-12-16 16:54:18 +01:00
Emil Ernerfeldt e8029178b6
Reduce aliasing when painting thin box outlines (#5484)
* Part of https://github.com/emilk/egui/issues/5164
2024-12-16 16:28:15 +01:00
Emil Ernerfeldt 450c6242e4 Improve error message in ColorImage::region 2024-12-16 15:14:50 +01:00
Emil Ernerfeldt 0823a36952
Fix: ui.new_child should now respect 'disabled' (#5483)
* Closes https://github.com/emilk/egui/issues/5475
2024-12-16 15:07:14 +01:00
Andreas Reich b1d2551e7e
Make frame delay on screenshots consistently one frame on web as well (#5482)
Native is already delayed by a frame because it calls
`handle_viewport_output` -> `egui_winit::process_viewport_commands`
after drawing. On web however, we process input including viewport
commands separately from drawing.
This adds an arbitrary frame delay mechanism for web and then uses this
with 1 frame delay always
2024-12-16 15:03:01 +01:00
Emil Ernerfeldt 3995491212
Revert "Workaround for egui having wrong scale in firefox" (#5481)
* Reverts emilk/egui#5466

Restores pixel-perfect rendering on chromium, Mac
2024-12-16 14:41:02 +01:00
Emil Ernerfeldt f0ec2f05c4
Fix broken images on egui.rs (move from git lfs to normal git) (#5480)
The images in the widget gallery on egui.rs are broken:

![image](https://github.com/user-attachments/assets/305e1041-e3e3-472d-9a52-1b90e8da053d)

~Not sure why yet, and I fail to reproduce locally.~
It's because they are on git lfs.
2024-12-16 14:16:54 +01:00
lucasmerlin 3bdb19e864
Workaround for egui having wrong scale in firefox (#5466)
* [x] I have followed the instructions in the PR template
2024-12-16 11:38:08 +01:00
Emil Ernerfeldt f7efb2186d
Improve hit-test of thin widgets, and widgets across layers (#5468)
When there are multiple layers (e.g. with custom transforms) close to
each other, the hit test code used to only consider widgets in the layer
directly under the mouse. This can make it difficult to hit thin widgets
just on the outside of a transform layer.

This PR fixes that.

It also prioritizes thin widgets, so that if there is both a thin widget
and a thick widget under the mouse cursor, you will always hit the thin
widgets, even if the thin widgets is layered behind the thick one. This
makes it easier to hit thin resize-handles.

In theory this should allow us to make `resize_grab_radius_side` and
`resize_grab_radius_corner` smaller in a future PR, if we want to.
2024-12-16 09:33:25 +01:00
Ted de Munnik 3af907919b
Use `profiling` crate to support more profiler backends (#5150)
Hey! I am not sure if this is something that's been considered before
and decided against (I couldn't find any PR's or issues).

This change removes the internal profiling macros in library crates and
the `puffin` feature and replaces it with similar functions in the
[profiling](https://github.com/aclysma/profiling) crate. This crate
provides a layer of abstraction over various profiler instrumentation
crates and allows library users to pick their favorite (supported)
profiler.

An additional benefit for puffin users is that dependencies of egui are
included in the instrumentation output too (mainly wgpu which uses the
profiling crate), so more details might be available when profiling.

A breaking change is that instead of using the `puffin` feature on egui,
users that want to profile the crate with puffin instead have to enable
the `profile-with-puffin` feature on the profiling crate. Similarly they
could instead choose to use `profile-with-tracy` etc.

I tried to add a 'tracy' feature to egui_demo_app in order to showcase ,
however the /scripts/check.sh currently breaks on mutually exclusive
features (which this introduces), so I decided against including it for
the initial PR. I'm happy to iterate more on this if there is interest
in taking this PR though.

Screenshot showing the additional info for wgpu now available when using
puffin

![image](https://github.com/user-attachments/assets/49fc0e7e-8f88-40cb-a69e-74ca2e3f90f3)
2024-12-16 09:15:54 +01:00
Emil Ernerfeldt 9aae14cdf4 Shorter `Debug` formatting of `LayerId` 2024-12-13 08:15:13 +01:00
Antoine Beyeler ba060a2c87
Drag-and-drop: keep cursor set by user, if any (#5467)
We used to always set the cursor to `Grabbing` when a drag and drop
payload is set, but this shadows user code trying to set an alternative
cursor (e.g. `NoDrop`). This PR no only change the cursor to `Grabbing`
if is way previously set to `Default`.
2024-12-12 19:47:41 +01:00
Jay Oster ea89c2935e
Android support for eframe (#5318)
<!--
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!
-->

Android support is "almost there". This PR pushes it just a bit further
by allowing `eframe` to be used on Android. It works by smuggling the
`AndroidApp` required by `winit` through `NativeOptions`.

The example isn't great because it doesn't leave space on the display
for Android's top status bar or the lower navigation bar. I don't know
what to do about that, yet. This is as far as I've managed to get it
working.

Another problem is that the development environment setup is completely
awful for Android unless you happen to already be a full-time Android
developer with everything configured on your build host. As a Rustacean,
this makes me very sad.

I've had some luck moving all of that mess to a container, adapted from
https://github.com/SergioRibera/docker-rust-android. It takes care of
all of the build dependencies, Android SDK, and the `cargo-apk` patches
for bugs that I hit while getting the example to work on my device. (I
also had to install an adb driver on my host and downloaded the Android
platform-tools to get access to `adb`. An alternative is exposing the
USB device to Docker. On Windows hosts, that means [installing
`usbipd`](https://learn.microsoft.com/en-us/windows/wsl/connect-usb). A
second alternative is using an `mtp` client to upload the APK as a file
with USB file transfer enabled, then manually install it through the
device's file manager.)

I'm not including the docker stuff in this PR, but here are the files
and instructions for future reference (and it will probably simplify
manual testing and CI, FWIW!)

<details><summary><code>Dockerfile</code></summary>

```dockerfile
FROM rust:1.76.0-slim

# Variable arguments
ARG JAVA_VERSION=17
ARG NDK_VERSION=25.1.8937393
ARG BUILDTOOLS_VERSION=30.0.0
ARG PLATFORM_VERSION=android-30
ARG CLITOOLS_VERSION=8512546_latest

# Install Android requirements
RUN apt-get update -yqq && \
    apt-get install -y --no-install-recommends \
    libcurl4-openssl-dev libssl-dev pkg-config build-essential git python3 wget zip unzip openjdk-${JAVA_VERSION}-jdk && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Install android targets
RUN rustup target add armv7-linux-androideabi aarch64-linux-android

# Install cargo-apk
RUN git clone -b fix/bin-targets-workspace-members https://github.com/parasyte/cargo-apk.git /tmp/cargo-apk && \
    cargo install --path /tmp/cargo-apk/cargo-apk

# Generate Environment Variables
ENV JAVA_VERSION=${JAVA_VERSION}
ENV ANDROID_HOME=/opt/Android
ENV NDK_HOME=/opt/Android/ndk/${NDK_VERSION}
ENV ANDROID_NDK_ROOT=${NDK_HOME}
ENV PATH=$PATH:${ANDROID_HOME}:${ANDROID_NDK_ROOT}:${ANDROID_HOME}/build-tools/${BUILDTOOLS_VERSION}:${ANDROID_HOME}/cmdline-tools/bin

# Install command line tools
RUN mkdir -p ${ANDROID_HOME}/cmdline-tools && \
    wget -qc "https://dl.google.com/android/repository/commandlinetools-linux-${CLITOOLS_VERSION}.zip" -P /tmp && \
    unzip -d ${ANDROID_HOME} /tmp/commandlinetools-linux-${CLITOOLS_VERSION}.zip && \
    rm -fr /tmp/commandlinetools-linux-${CLITOOLS_VERSION}.zip
# Install sdk requirements
RUN echo y | sdkmanager --sdk_root=${ANDROID_HOME} --install \
    "build-tools;${BUILDTOOLS_VERSION}" "ndk;${NDK_VERSION}" "platforms;${PLATFORM_VERSION}"

# Create APK keystore for debug profile
# Adapted from caa806283d/ndk-build/src/ndk.rs (L393-L423)
RUN keytool -genkey -v -keystore ${HOME}/.android/debug.keystore -storepass android -alias androiddebugkey \
    -keypass android -dname 'CN=Android Debug,O=Android,C=US' -keyalg RSA -keysize 2048 -validity 10000

# Cleanup
RUN rm -rf /tmp/*

WORKDIR /src

ENTRYPOINT [ "cargo", "apk", "build" ]
```
</details>

<details><summary><code>.dockerignore</code></summary>

```ignore
# Ignore everything, only the Dockerfile is needed to build the container
*
```
</details>

```sh
docker build -t rust-android:latest .
docker run --rm -it -v "$PWD:/src" rust-android:latest -p hello_android
adb install target/debug/apk/hello_android.apk
```

* Part of #2066
* [x] I have followed the instructions in the PR template
2024-12-12 19:24:26 +01:00
lucasmerlin 6c1d695fc6
Add screenshot support for eframe web (#5438)
This implements web support for taking screenshots in an eframe app (and
adds a nice demo).
It also updates the native screenshot implementation to work with the
wgpu gl backend.

The wgpu implementation is quite different than the native one because
we can't block to wait for the screenshot result, so instead I use a
channel to pass the result to a future frame asynchronously.

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


https://github.com/user-attachments/assets/67cad40b-0384-431d-96a3-075cc3cb98fb
2024-12-12 19:17:42 +01:00
Emil Ernerfeldt de8ac88c0e
Add `Context::layer_transform_to_global` & `layer_transform_from_global` (#5465)
This makes it easy to get the current transform of a layer, and uses
consistent naming everywhere.

`Memory::layer_transforms` is now called `Memory::to_global`, because
the old name was ambiguous (transform into what direction?)
2024-12-12 18:29:13 +01:00
Emil Ernerfeldt 99c1034cfc Improve changelog generation script 2024-12-12 16:57:52 +01:00
Michael "Scott" McBee d3ea922cc6
Fix: don't interact with `Area` outside its `constrain_rect` (#5459)
<!--
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

This PR makes an area's interact rect intersect its constrain rect. This
fixes an issue where masked areas would still intercept input.


Before:

![before](https://github.com/user-attachments/assets/6b790a04-8a15-44fe-a7ae-4adda189ecba)

After:

![after](https://github.com/user-attachments/assets/98010d89-e680-44cb-8717-faf31b0912d3)
2024-12-12 11:42:32 +01:00
lucasmerlin 36a70e12c3
Fix pr preview vulnerability (#5461)
* Closes #5458
* [x] I have followed the instructions in the PR template
2024-12-11 16:55:57 +01:00
Tristan Guichaoua 4362a242b0
web_demo: make hash anchor case insensitive (#5446)
<!--
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
2024-12-11 13:44:37 +01:00
Emil Ernerfeldt f28080c675
Update some crates to fix CI (#5456)
> cargo update -p url

```
     Locking 28 packages to latest compatible versions
      Adding displaydoc v0.2.5
      Adding icu_collections v1.5.0
      Adding icu_locid v1.5.0
      Adding icu_locid_transform v1.5.0
      Adding icu_locid_transform_data v1.5.0
      Adding icu_normalizer v1.5.0
      Adding icu_normalizer_data v1.5.0
      Adding icu_properties v1.5.1
      Adding icu_properties_data v1.5.0
      Adding icu_provider v1.5.0
      Adding icu_provider_macros v1.5.0
    Updating idna v0.5.0 -> v1.0.3
      Adding idna_adapter v1.2.0
      Adding litemap v0.7.4
      Adding stable_deref_trait v1.2.0
      Adding synstructure v0.13.1
      Adding tinystr v0.7.6 (latest: v0.8.0)
    Removing tinyvec v1.8.0
    Removing tinyvec_macros v0.1.1
    Removing unicode-bidi v0.3.17
    Removing unicode-normalization v0.1.24
    Updating url v2.5.2 -> v2.5.4
      Adding utf16_iter v1.0.5
      Adding utf8_iter v1.0.4
      Adding write16 v1.0.0
      Adding writeable v0.5.5 (latest: v0.6.0)
      Adding yoke v0.7.5
      Adding yoke-derive v0.7.5
      Adding zerofrom v0.1.5
      Adding zerofrom-derive v0.1.5
      Adding zerovec v0.10.4 (latest: v0.11.0)
      Adding zerovec-derive v0.10.3 (latest: v0.11.0)
```

holy hell that's a lot of new crates 😭 


* Waiting for https://github.com/emilk/egui/pull/5457
2024-12-10 17:16:38 +01:00
Emil Ernerfeldt 53a926a428
Update MSRV to 1.80 (#5457)
Because some dependencies now require it, see:
* https://github.com/emilk/egui/pull/5456
2024-12-10 16:09:03 +01:00
Emil Ernerfeldt 9b1ae6b880 Add CHANGELOG.md for egui_kittest 2024-12-10 16:06:29 +01:00
Emil Ernerfeldt a7539b270a
Remove `Order::PanelResizeLine` (#5455)
This was a hack that is no longer in use
2024-12-10 15:32:43 +01:00
Antoine Beyeler 13352d6064
Fix drag-and-drop termination condition bug (#5452)
I introduced this in #5433.

TL;DR: there are two termination conditions for drag-and-drop
operations:
- ESC
- release mouse

The former _must_ happen at frame start (to properly capture the
keystroke). The latter _must_ happen at end-of-frame (to _not_ shadow
the mouse release event from user code).

This is now properly documented.
2024-12-09 12:12:14 +01:00
Emil Ernerfeldt 5384600fa2 cargo fmt 2024-12-09 12:11:27 +01:00