Commit Graph

3581 Commits

Author SHA1 Message Date
YgorSouza f75a235c90
Use boxed slice for lookup table to avoid stack overflow (#5212)
* Closes <https://github.com/emilk/egui/issues/5210>
* [x] I have followed the instructions in the PR template
2024-10-23 14:42:47 +02:00
frederik-uni 04ab5e7574
`Context::add_font` (#5228)
make it easier to add fonts. 

For example if I want to add a custom FontFamily or if the user wants to
add a Chinese fallback
* [x] I have followed the instructions in the PR template

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-10-23 14:29:44 +02:00
lucasmerlin d9a35a7289
Increase the threshold for snapshot tests (#5298)
* Related to #5295 
* [x] I have followed the instructions in the PR template
2024-10-23 11:19:39 +02:00
Emil Ernerfeldt 68d312d043
Revert "Fix: `Sides` did not apply the layout position correctly." (#5300)
Reverts emilk/egui#5232

I should have tested it first. `cursor` can contain infinites. There is
a better fix to be found @zhatuokun
2024-10-23 11:18:36 +02:00
frederik-uni e02be45007
iOS: Support putting UI next to the dynamic island (#5211)
winit::Window::inner_size returns size of safe area on iOS. use
winit::Window::outer_size on iOS
The dimensions of outer_size include the title bar and borders, but as
far as I know there is no way to actually display the title bar or
borders on iOS so it should be fine.

<!--
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 #3547 
* [X] I have followed the instructions in the PR template

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-10-23 11:10:12 +02:00
lucasmerlin 13e65eb55b
Expose center position in `MultiTouchInfo` (#5247)
Expose the center / average position in MultiTouchInfo
2024-10-23 11:03:53 +02:00
YgorSouza e5c502f21e
Fix Ctrl+Shift+Z redo shortcut (#5258)
This shortcut was previously triggering the Undo action due to the
matches_logically method ignoring the state of the Shift key. This was
solved by simply inverting the order of the undo and redo arms, so the
undo is not matched if the shortcut corresponds to redo.

* Closes <https://github.com/emilk/egui/issues/5255>
* [x] I have followed the instructions in the PR template
2024-10-23 10:56:12 +02:00
zhatuokun 6add64e144
Fix: `Sides` did not apply the layout position correctly. (#5232)
<!--
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!
-->

Run this code

```rs
        CentralPanel::default().show(ctx, |ui| {
            Sides::new().show(
                ui,
                |ui| {
                    ui.label("1");
                },
                |ui| {
                    ui.label("2");
                },
            );
            Sides::new().show(
                ui,
                |ui| {
                    ui.label("11");
                },
                |ui| {
                    ui.label("22");
                },
            );
            Sides::new().show(
                ui,
                |ui| {
                    ui.label("111");
                },
                |ui| {
                    ui.label("222");
                },
            );
        });
```

Before


![before](https://github.com/user-attachments/assets/2678f937-859e-422a-9171-5f2a63166c8f)

After


![after](https://github.com/user-attachments/assets/879892f1-a69d-4540-8e56-8b2448e939ed)
2024-10-23 10:54:27 +02:00
zhatuokun 3a0859b817
Fix: `Ui::new_child` does not consider the sizing_pass field of `UiBuilder` (#5262)
During the sizing pass we want widgets to use up as little space as
possible, but it does not consider the sizing_pass field of `UiBuilder`.
2024-10-23 10:53:26 +02:00
Justin Whear 7c1f06941e
Use id_salt on Table ScrollArea (#5282)
The salt is based on the table's `state_id`.

* Closes https://github.com/emilk/egui/issues/5281
* [x] I have followed the instructions in the PR template
2024-10-23 10:48:09 +02:00
lucasmerlin 67a54ec5ce
Improve egui_kittest documentation and update CONTRIBUTING.md (#5296)
This should hopefully make it easier for egui contributors and
egui_kittest users to understand the snapshot tests


* [X] I have followed the instructions in the PR template
2024-10-23 08:54:43 +02:00
lucasmerlin 70a01138b7
Add egui testing library (#5166)
- closes #3491 
- closes #3926

This adds a testing library to egui based on
[kittest](https://github.com/rerun-io/kittest). Kittest is a new
[AccessKit](https://github.com/AccessKit/accesskit/)-based testing
library. The api is inspired by the js
[testing-library](https://testing-library.com/) where the idea is also
to query the dom based on accessibility attributes.
We made kittest with egui in mind but it should work with any rust gui
framework with AccessKit support.

It currently has support for:
- running the egui app, frame by frame
- building the AccessKit tree
- ergonomic queries via kittest
  - via e.g. get_by_name, get_by_role
- simulating events based on the accesskit node id
- creating arbitrary events based on Harness::input_mut
- rendering screenshots via wgpu
- snapshot tests with these screenshots

A simple test looks like this: 
```rust
fn main() {
    let mut checked = false;
    let app = |ctx: &Context| {
        CentralPanel::default().show(ctx, |ui| {
            ui.checkbox(&mut checked, "Check me!");
        });
    };

    let mut harness = Harness::builder().with_size(egui::Vec2::new(200.0, 100.0)).build(app);
    
    let checkbox = harness.get_by_name("Check me!");
    assert_eq!(checkbox.toggled(), Some(Toggled::False));
    checkbox.click();
    
    harness.run();

    let checkbox = harness.get_by_name("Check me!");
    assert_eq!(checkbox.toggled(), Some(Toggled::True));

    // You can even render the ui and do image snapshot tests
    #[cfg(all(feature = "wgpu", feature = "snapshot"))]
    egui_kittest::image_snapshot(&egui_kittest::wgpu::TestRenderer::new().render(&harness), "readme_example");
}
```

~Since getting wgpu to run in ci is a hassle, I'm taking another shot at
creating a software renderer for egui (ideally without a huge dependency
like skia)~ (this didn't work as well as I hoped and it turns out in CI
you can just run tests on a mac runner which comes with a real GPU)
 
Here is a example of a failed snapshot test in ci, it will say which
snapshot failed and upload an artifact with the before / after and diff
images:

https://github.com/emilk/egui/actions/runs/11183049487/job/31090724606?pr=5166
2024-10-22 12:39:00 +02:00
lucasmerlin 707cd03357
Set `Response::intrinsic_size` for TextEdit (#5266)
This allows me to correctly support multiline TextEdits in egui_flex
2024-10-15 09:13:34 +02:00
rustbasic 23728e145e
Fix bug causing wrong-fire of `ViewportCommand::Visible` (#5244)
Fix: variable name issue

I'm not sure, if there's any particular reason to do `self.active` .
I thought `self.visible` was the original intention.
2024-10-10 15:51:52 +02:00
Rusty-Cube 7bd6f83f18
Free textures after submitting queue instead of before with wgpu renderer (#5226)
* Closes #5224

I'm unfamiliar with wgpu, so I'd like someone to confirm, that calling
`wgpu::Texture` _after_ `wgpu::Queue::submit` is in fact the right thing
to do.

---------

Co-authored-by: Andreas Reich <r_andreas2@web.de>
2024-10-06 20:50:10 +02:00
Nicolas 0f2b427ff4
Allow easier setting of background color for TextEdit (#5203)
* Closes <https://github.com/emilk/egui/issues/5183>
* [x] I have followed the instructions in the PR template
2024-10-02 21:23:54 +02:00
lucasmerlin 1406e8717c
egui-wgpu: Fix docs.rs build (#5204)
This enables the rwh_06 feature in winit which is required to correctly
build egui-wgpu
- fixes #5202
2024-10-02 19:17:14 +02:00
valadaptive ac2466d14f
Update ScrollArea drag velocity when drag stopped (#5175)
Fixes #5174.

The drag velocity was not being updated unless the cursor counted as
"dragging", which only happens when it's in motion. This effectively
guarantees that the drag velocity will never be zero, even if the cursor
is not moving, and results in spurious scroll velocity being applied
when the cursor is released.

Instead, we update the velocity only when the drag is stopped, which is
when the kinetic scrolling actually needs to begin. Note that we
immediately *apply* the scroll velocity on the same frame that we first
set it, to avoid a 1-frame gap where the scroll area doesn't move.

I believe that *not* setting `scroll_stuck_to_end` and `offset_target`
when the drag is released is the correct thing to do, as they should
apply immediately once the user stops dragging. Should we maybe clear
the drag velocity instead if `scroll_stuck_to_end` is true or
`offset_target` exists?

* Closes #5174
* [x] I have followed the instructions in the PR template
2024-10-02 18:12:36 +02:00
Emil Ernerfeldt 24cd711f5b Fix typos 2024-10-01 10:41:59 +02:00
Emil Ernerfeldt 5f8f149444
Add `UiBuilder::layer_id`, and remove `layer_id` from `Ui::new` (#5195)
This adds `UiBuilder::layer_id` to replace `ui.with_layer_id`
2024-10-01 10:39:44 +02:00
Emil Ernerfeldt fe368bacc4 Release 0.29.1 - Bug fixes 2024-10-01 10:08:21 +02:00
Emil Ernerfeldt ce744e6f7a
Do not round panel rectangles to pixel grid (#5196)
* Closes https://github.com/emilk/egui/issues/5173
* Part of https://github.com/emilk/egui/issues/5163
* Related to https://github.com/emilk/egui/issues/5164
2024-09-30 15:48:41 +02:00
Emil Ernerfeldt 15d3d43aa3
Fix backspace/arrow keys in TextEdit on Linux (#5188)
* Closes https://github.com/emilk/egui/issues/5008
* Closes https://github.com/emilk/egui/pull/5182
* Bug introduced in https://github.com/emilk/egui/pull/4912

I suspect this will make IME no longer work on Linux, though I don't
know if it ever worked.
I rather have backspace/arrows working though.

Please help test this (I don't have Linux!)

# Tested on
* [x] Mac
* [ ] Linux Wayland
* [x] Linux X11
2024-09-30 13:23:02 +02:00
Emil Ernerfeldt 448e12d6b6
Fix id clash in `Ui::response` (#5192)
This adds a new `Ui::unique_id` used in `Ui::response`.

I'll make a follow-up PR where the old `id` is renamed `stable_id`, and
deprecate `fn id` to force users to think through which `id` they want.

* Closes https://github.com/emilk/egui/issues/5190
2024-09-30 13:20:34 +02:00
Emil Ernerfeldt 5390ecdf4a
Bug fix: click anywhere on a `Table` row to select it (#5193)
* Closes https://github.com/emilk/egui/issues/5184
2024-09-30 13:20:03 +02:00
Emil Ernerfeldt db3dcaf447
Remove debug-assert triggered by `with_layer_id/dnd_drag_source` (#5191)
* Closes https://github.com/emilk/egui/issues/5178
2024-09-30 13:19:53 +02:00
GiGaGon 679f6f57b1
Replace "an ui" with "a ui" (#5185)
Since ui's initial sound is a "y", it should be "a ui", not "an ui". 
Replaced case-sensitively using regex `([aA])n ([uU][iI])` replacement
`$1 $2`

* [x] I have followed the instructions in the PR template
2024-09-30 08:23:38 +02:00
Emil Ernerfeldt 59d71831fd Release 0.29.0 - Multipass, `UiBuilder`, & visual improvements 2024-09-26 15:32:02 +02:00
rustbasic dae1979dd3
Add back `Context::set_visuals()` (#5100)
My opinion is, it would be better to keep `Context::set_visuals()` so
that you don't get confused.

* Related #4744
2024-09-26 11:37:57 +02:00
Ethan Post 25abb74465
egui_extras: Add `TableBuilder::animate_scrolling` (#5159)
This will allow disabling the animation that occurs during
`scroll_to_row` calls. Follows the same coding style as the other scroll
options in `TableBuilder`.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-09-26 11:36:20 +02:00
Emil Ernerfeldt a72ebbeafc
Add a `cargo machete` CI step (#5171)
`cargo machete` looks for unused dependencies
2024-09-26 10:24:37 +02:00
Emil Ernerfeldt 92adfa57dc Improve comment in text layout code 2024-09-26 09:43:27 +02:00
YgorSouza a59e178131
Document the fact that the hex_color macro is not const (#5169)
It cannot be made const with the current version of Rust, and that is
counterintuitive since it does compile-time checks, so we make that
clear in the documentation. It might be possible to make it const once
MSRV is bumped to 1.82.

* See <https://github.com/emilk/egui/issues/5160>
* [x] I have followed the instructions in the PR template
2024-09-26 09:15:28 +02:00
Emil Ernerfeldt 3805584238
Fix bug causing tooltips with dynamic content to shrink (#5168)
Affects `.on_hover_text(…)` with dynamic content (i.e. content that
changes over time).

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

`.on_hover_ui` with dynamic content can still hit the shrinking problem.
The general solution depends on solving
https://github.com/emilk/egui/issues/5138 but a work-around is to add
this to your tooltips:

```diff
 response.on_hover_ui(|ui| {
+    ui.set_max_width(ui.spacing().tooltip_width);
     // …
 });
```
2024-09-25 18:50:14 +02:00
Emil Ernerfeldt 5d46f67f79
Add `DebugOptions::show_unaligned` (#5165)
This tool highlights coordinates that are non-integer.

* Closes https://github.com/emilk/egui/issues/4927
* Will be used for https://github.com/emilk/egui/issues/5163

This is disabled by default (even in debug builds), because so many
widgets cause un-alignment currently.
2024-09-25 16:05:30 +02:00
Emil Ernerfeldt f97f85089d
Prevent text shrinking in tooltips; round wrap-width to integer (#5161)
* Closes https://github.com/emilk/egui/pull/5106
* Closes https://github.com/emilk/egui/issues/5084


Protect against rounding errors in egui layout code.

Say the user asks to wrap at width 200.0.
The text layout wraps, and reports that the final width was 196.0
points.
This than trickles up the `Ui` chain and gets stored as the width for a
tooltip (say).
On the next frame, this is then set as the max width for the tooltip,
and we end up calling the text layout code again, this time with a wrap
width of 196.0.
Except, somewhere in the `Ui` chain with added margins etc, a rounding
error was introduced,
so that we actually set a wrap-width of 195.9997 instead.
Now the text that fit perfectly at 196.0 needs to wrap one word earlier,
and so the text re-wraps and reports a new width of 185.0 points.
And then the cycle continues.

So this PR limits the text wrap-width to be an integer.

Related issues:
* https://github.com/emilk/egui/issues/4927
* https://github.com/emilk/egui/issues/4928
* https://github.com/emilk/egui/issues/5163

--- 

Pleas test this @rustbasic
2024-09-25 11:31:41 +02:00
Emil Ernerfeldt 9ef4d02ab8
More compact `Debug` formatting of `Color32` (#5162)
Especially when using the verbose `{:#?}`, which before would result in

```
Color32([
    255,
    0,
    0,
    255
])
```

but now becomes `#ff_00_00_ff`
2024-09-25 11:14:44 +02:00
Andreas Reich 1603f05818
Wgpu render pass on paint callback has now static lifetime (#5149)
A very common usability issue on egui-wgpu callbacks is that `paint`
can't access any data that doesn't strictly outlive the callback
resources' data. E.g. if the callback resources have an `Arc` to some
resource manager, you can't easily pull out resources since you
statically needed to ensure that those resource references outlived the
renderpass, whose lifetime was only constrained to the callback
resources themselves.

Wgpu 22 no longer has this restriction! Its (render/compute-)passes take
care of the lifetime of any passed resource internally. The lifetime
constraint is _still_ opt-out since it protects from a common runtime
error of adding commands/passes on the parent encoder while a previously
created pass wasn't closed yet.
This is not a concern in egui-wgpu since the paint method where we have
to access the render pass doesn't even have access to the encoder!
2024-09-23 11:48:09 +02:00
Christofer Nolander 6f7b9b9b87
Add support for mipmap textures. (#5146)
<!--
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

Adds support for mipmaps in the `glow` backend.

Should be possible to implement for `wgpu` in the future as well, but
requires a custom compute kernel.
2024-09-22 19:16:16 +02:00
Swarkin 07ccf41bf9
Improve documentation grammar and wording (#5052)
This PR aims to make the documentation comments easier to read and
understand.
2024-09-22 19:15:11 +02:00
rustbasic 7c7190f98d
Clamp font size to between 0.1 and 2048 (#5139)
Fix: Font size limit to prevent panic
2024-09-22 19:14:03 +02:00
lucasmerlin c9df2f0783
Fix pan_zoom demo constraining windows (#5137)
fixes 

* Closes #5135
* [x] I have followed the instructions in the PR template
2024-09-22 19:13:01 +02:00
GiGaGon 02e795277f
Fix error in Response::dragged docs (#5143)
* [x] I have followed the instructions in the PR template
2024-09-21 12:48:29 +02:00
Emil Ernerfeldt 06f709481a
Keep track of why `request_discard` was called (#5134)
This will help debug spurious calls to it
2024-09-20 09:17:52 +02:00
lucasmerlin 0f290b4904
Add PR preview deployments (#5131)
This adds preview deployments that will deploy a version of
egui_demo_app for each pull request, making things easier to review /
test.

Some notes on security:
The preview deployment is split in two workflows, preview_build and
preview_deploy.
`preview_build` runs on pull_request, so it won't have any access to the
repositories secrets, so it is safe to
build / execute untrusted code.
`preview_deploy` has access to the repositories secrets (so it can push
to the pr preview repo) but won't run
any untrusted code (it will just extract the build artifact and push it
to the pages branch where it will
automatically be deployed).

To set this up, a DEPLOY_KEY secret needs to be added, which allows the
action to push the compiled artifacts into this repository:
https://github.com/egui-pr-preview/pr
The deploy key is the private key part of a key generated via
ssh-keygen. The public key is set as a deploy key in that repo.
I have created the repo on a separate github org, so it won't be
directly associated with emil or egui in case someone pushes something
naughty.

I have set this up in my fork of egui to show how this works:
- I created a PR: https://github.com/lucasmerlin/egui/pull/2
- The code will be compiled and pushed to the egui-pr-preview/pr repo
and deployed via github pages
- The bot leaves a comment on the pr with a link to the preview
- The preview is available at
https://egui-pr-preview.github.io/pr/2-pr-preview-demo/
(It's unfortunately only available a couple seconds after the bot writes
the comment, because the pages deployment action is run independently on
the other repository)
- Once the PR is merged / closed the preview will be cleaned up
(unfortunately the empty folder will remain, it seems like it's not
possible to remove that via the JamesIves/github-pages-deploy-action
action I use, but I don't think that it's a big issue)

I'll leave the PR in draft until the DEPLOY_KEY is set up
2024-09-20 09:08:58 +02:00
lucasmerlin 9ba97a9a2f
Fix empty grids repeatedly requesting a discard (#5133)
* Closes <https://github.com/emilk/egui/issues/5132>
* [x] I have followed the instructions in the PR template

This does cause a slight difference in the amount of space allocated by
a empty grid, is this a problem?
Before:

<img width="113" alt="image"
src="https://github.com/user-attachments/assets/88c9c1a8-2ab8-4b01-8d57-0eb0655fa0e4">

After:

<img width="101" alt="image"
src="https://github.com/user-attachments/assets/8e1c9d1b-54d6-43b9-9e37-2614dd90d6fe">
2024-09-20 09:08:44 +02:00
Emil Ernerfeldt 5cc35d2212 Improve docstring of `Ui::new_child` 2024-09-19 14:41:18 +02:00
Ilya Zlobintsev 00cb50ebad
Add `gtk-egui-area` integration to README (#5129)
<!--
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

Hi, I've made an integration that allows egui to be embedded as a widget
inside of a GTK application. I'm planning to use it to draw interactive
plots via `egui_plot`, as I haven't found comparable plotting widgets in
GTK. I hope others will find this integration useful as well.

The library doesn't do its own rendering, it instead relies on
`egui_glow` to render inside of a GTK-provided OpenGL drawing area.

It is published on [crates.io](https://crates.io/crates/gtk-egui-area).
2024-09-19 13:30:43 +02:00
Emil Ernerfeldt e0f0b7f47f
Remember to call `ui.register_rect` for better debug (#5130) 2024-09-19 12:23:53 +02:00
Emil Ernerfeldt b1784249d2 Fix merge race 2024-09-19 12:01:10 +02:00