1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 07:03:14 -04:00
Commit Graph

3612 Commits

Author SHA1 Message Date
Hubert Głuchowski
c094ee8a15 Merge branch 'emilk:master' into cache_galley_lines 2024-12-07 18:44:48 +01:00
Hubert Głuchowski
17a5f1f75e Fix incorrect behavior with LayoutJob::max_rows 2024-12-05 19:15:23 +01:00
Hubert Głuchowski
40f237d43c Add comment and check for newline before multiline layout 2024-12-05 18:45:36 +01:00
Hubert Głuchowski
25da82279f Fix text horizontal alignment 2024-12-05 18:27:38 +01:00
Emil Ernerfeldt
046034f902 Add Color32::mul (#5437)
Multiply two `Color32` together quickly, in gamma-space
2024-12-05 13:53:20 +01:00
lucasmerlin
291b83b7be Support loading images with weird urls and improve error message (#5431)
* Closes #5341
* [x] I have followed the instructions in the PR template
2024-12-05 07:33:02 +01:00
Hubert Głuchowski
c6592ec898 Fix nits 2024-12-04 19:30:13 +01:00
Antoine Beyeler
f687b27efc Consume escape keystroke when bailing out from a drag operation (#5433) 2024-12-04 17:35:24 +01:00
Emil Ernerfeldt
cf513d215c Update to wgpu 23.0.1 (#5432)
Updating wgpu v23.0.0 -> v23.0.1
    Updating wgpu-core v23.0.0 -> v23.0.1
    Updating wgpu-hal v23.0.0 -> v23.0.1
2024-12-04 16:59:42 +01:00
Emil Ernerfeldt
577ee8d228 Add Button::image_tint_follows_text_color (#5430)
For when you have a white icon/image that should respond to hover just
like the text does.
2024-12-04 15:24:29 +01:00
Emil Ernerfeldt
c5ac7d301a Fix on_hover_text_at_pointer for transformed layers (#5429) 2024-12-04 14:23:05 +01:00
Juan Campa
cd0f5859b2 Make text cursor always appear on click (#5420)
<!--
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

### Problem
When clicking on a TextEdit sometimes the cursor doesn't appear
immediately which makes it feel like the click was not registered for a
second. This is because the start time for the blinking animation is
only reset on keyboard input, but not on mouse interaction.

It's hard to tell on the video but the cursor doesn't show immediately
after clicking if the blink timer happens to be off.


https://github.com/user-attachments/assets/9f049bd0-0375-4291-b2ef-697777fb854d


### Solution
Reset the click timer every time a `TextEdit` is clicked. 

Additionally, the cursor is now correctly painted on the pixel boundary.
IMO we should default to 1px cursor (instead of 2px) but that's not
included in this PR. Happy to make that change too.


https://github.com/user-attachments/assets/6c489414-f2c4-4dc6-85dd-f8bc457edad0
2024-12-04 14:18:49 +01:00
Emil Ernerfeldt
eac7ba01fa Move egui::util::cache to egui::cache; add FramePublisher (#5426)
This moves `egui::util::cache` to `egui::cache` (the old path is
deprecated, but still works).

It also adds the `FramePublisher` helper, which can be used to publish a
value which will be retained for this frame and the next:

``` rs
pub type MyPublisher = egui::cache::FramePublisher<MyKey, MyValue>;

// Publish:
ctx.memory_mut(|mem| {
    mem.caches.cache::<MyPublisher>().set(key, value);
});

// Retrieve:
let value: Option<MyValue> = ctx.memory_mut(|mem| {
    mem.caches
        .cache::<MyPublisher>()
        .get(key)
        .clone()
})
```
2024-12-03 14:28:12 +01:00
Emil Ernerfeldt
c7224aab26 Improve error message when kittest fails (#5427)
* Closes https://github.com/emilk/egui/issues/5423

New output is actionable

```
failures:

---- demo::demo_app_windows::tests::demos_should_match_snapshot stdout ----
thread 'demo::demo_app_windows::tests::demos_should_match_snapshot' panicked at crates/egui_demo_lib/src/demo/demo_app_windows.rs:433:9:
Errors: [
    "'demos/Code Example' Image size did not match snapshot. Expected: (402, 574), Actual: (415, 574).
     Run `UPDATE_SNAPSHOTS=1 cargo test` to update the snapshots.",
]
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    demo::demo_app_windows::tests::demos_should_match_snapshot
```
2024-12-03 13:40:51 +01:00
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
Hubert Głuchowski
e15b34b984 Slightly simplify paint_text_selection code 2024-12-02 00:52:25 +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
Fishhh
139f28640d Replace a hack with a proper implementation 2024-11-30 19:29:40 +01:00
Fishhh
110a9c39e3 Move some PlacedRow methods back to Row 2024-11-30 18:27:13 +01:00
Fishhh
bbe566256e Fix Row::ends_with_newline docs, explain skipping of last galley row 2024-11-30 18:17:38 +01:00
Fishhh
fd8413c62a Simplify layout_multiline loop loop into a while loop 2024-11-30 18:12:24 +01:00
Fishhh
1be24ba470 Respect LayoutJob::round_output_size_to_nearest_ui_point 2024-11-30 17:51:07 +01:00
Fishhh
66c83c31ce Move ends_with_newline back into Row 2024-11-30 17:51:07 +01:00
Fishhh
6147ff3668 Round PlacedRow positions to pixels during multiline layout 2024-11-30 16:59:38 +01:00
Fishhh
6d6bc3befb Respect first_row_min_height during multiline Galley layout 2024-11-30 16:47:18 +01:00
Fishhh
abbc561ae1 Correctly handle empty lines 2024-11-30 15:59:50 +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
Hubert Głuchowski
bc86bec1cb Properly handle row repositioning 2024-11-29 15:57:47 +01:00
Hubert Głuchowski
f028154da8 Move cached-multiline-layout code into a helper function 2024-11-29 13:02:49 +01:00
Hubert Głuchowski
3de1723659 Don't add leading space to more than one split layout section 2024-11-29 11:55:15 +01:00
Hubert Głuchowski
4e3f162801 Fix lints 2024-11-29 11:50:24 +01:00
Hubert Głuchowski
db32a1ed44 Make Galleys share Rows and store their offsets 2024-11-28 18:54:54 +01:00
Hubert Głuchowski
150c0f662b Cache individual lines of text in GalleyCache 2024-11-28 18:53:45 +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
Hubert Głuchowski
622b848c00 Fix typo 2024-11-28 16:47: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