Commit Graph

3892 Commits

Author SHA1 Message Date
Alexander Nadeau 995058bbd1
Update web-sys min version to 0.3.73 (#5862)
This should prevent compilation errors (which I ran into) where eframe
tries to use HtmlElement::set_autofocus(), which doesn't exist until
0.3.73.

```
error[E0599]: no method named `set_autofocus` found for struct `HtmlElement` in the current scope
  --> C:\Users\wareya\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\eframe-0.31.1\src\web\text_agent.rs:24:15
   |
24 |         input.set_autofocus(true)?;
   |               ^^^^^^^^^^^^^
   |
help: there is a method `set_onfocus` with a similar name
   |
24 |         input.set_onfocus(true)?;
   |               ~~~~~~~~~~~
```

<!--
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
2025-03-30 14:04:07 +02:00
Hank Jordan 943e3618fc
Improve drag-to-select text (add margins) (#5797)
Might want to draw from `interaction.interact_radius` style instead of
hard-coding the margin, but I didn't want to create a breaking change.
If desired, I can follow up with a separate PR to address that concern.

* Closes <https://github.com/emilk/egui/issues/5796>
* [x] I have followed the instructions in the PR template
2025-03-30 14:03:19 +02:00
Timo von Hartz ab0f0b7b64
Rename `should_propagate_event` & add `should_prevent_default` (#5779)
* [x] I have followed the instructions in the PR template

Currently eframe [calls
`prevent_default()`](962c7c7516/crates/eframe/src/web/events.rs (L307-L369))
for all copy / paste events on the
[*document*](962c7c7516/crates/eframe/src/web/events.rs (L88)),
making embedding an egui application in a page (e.g. an react
application) hard (as all copy & paste functionality for other elements
on the page is broken by this).

I'm not sure what the motivation for this is, if any.

This commit / PR adds a callback (`should_prevent_default`), similar to
`should_propgate_event`, that an egui application can use to overwrite
this behavior. It defaults to returning `true` for all events, to keep
the existing behavior.

I call `should_prevent_default` in every place that
`should_propagate_event` is called (which is not all places that
`prevent_default` is called!). I'm not sure for the motivation of not
calling `should_propagate_event` everywhere that `stop_propagation` is
called, but I kept that behavior for the `should_prevent_default`
callback too.

Please let me know if I'm missing some existing functionality that would
allow me to do this, or if there's a reason that we don't want
applications to be able to customize this (i.e. if there's a reason to
always `prevent_default` for all copy / paste events on the whole
document)
2025-03-30 14:00:46 +02:00
Emil Ernerfeldt 83254718a3 Clean up strikethrough/underline code in epaint 2025-03-30 13:15:41 +02:00
Emil Ernerfeldt 7ea3f762b8
Make text underline and strikethrough pixel perfect crisp (#5857)
Small visual fix: pixel-align any text underline or strikethrough.
Before they could be often be blurry.
2025-03-28 20:37:38 +01:00
Lucas Meurer 884be3491d
Fix color picker button (#5847)
* related to #5832 
(I want to keep that open and actually update the button to use the new
popup, but this should be enough to fix it for now)
* [X] I have followed the instructions in the PR template
2025-03-25 14:38:51 +01:00
TPhoenix 5d6aaa239b
Fix typo in style.rs (#5845)
lien -> line

<!--
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>
* [ x ] I have followed the instructions in the PR template
2025-03-25 14:19:23 +01:00
Nicolas 8b62fd9286
Fix Lint for debug-assert (#5846)
Fixes the current ci workflow error
2025-03-25 14:18:45 +01:00
Grayden ddf9d267fc
Fix in `Scene`: make `scene_rect` full size on reset (#5801)
<!--
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

# Overview

This is a small change that supports draggable elements inside a
`Scene`.

When a Scene is initialized with a `Rect::Zero`, following the [example
in the
demo](https://github.com/emilk/egui/blob/master/crates/egui_demo_lib/src/demo/scene.rs#L15),
it will [automatically be reset to the `inner_rect` of the
UI](https://github.com/emilk/egui/blob/master/crates/egui/src/containers/scene.rs#L120-L123).

This centers the scene on the inner-rect contents, however the resulting
`scene_rect` doesn't fill the entire `outer_rect`. This probably isn't
an issue for most users of `Scene`.

However, I want to support draggable elements on a `Scene`, and to do
that I need to map the pointer-position in the window to the scene_rect
position.

As is, the example of draggable elements on Scene works after the user
has modified the scene rect in some way (zoom or pan), when `scene_rect`
is set to `to_global.inverse() * outer_rect`
([here](https://github.com/emilk/egui/blob/master/crates/egui/src/containers/scene.rs#L114-L118)).
Before a user modifies the scene rect, the pointer-position cannot be
reliably mapped to the scene_rect, since the scene_rect doesn't span the
entire window.

This PR just forces that translation to always run after the scene_rect
is reset to `inner_rect`. The practical result is that the scene_rect
will now always span the full outer_rect.

# Example

Here's a small app that demonstrates the functionality I'm trying to
support. I'm new to Egui so there may be better patterns for what I'm
trying to do, but if you run this against `main` and this branch you'll
notice the difference.

```rs
use eframe::egui::*;

/// Map coordinates from the src rect to the target rect
fn map_to_rect(position: Pos2, src_rect: Rect, dest_rect: Rect) -> Pos2 {
    let x = (position.x - src_rect.min.x) / (src_rect.max.x - src_rect.min.x)
        * (dest_rect.max.x - dest_rect.min.x)
        + dest_rect.min.x;
    let y = (position.y - src_rect.min.y) / (src_rect.max.y - src_rect.min.y)
        * (dest_rect.max.y - dest_rect.min.y)
        + dest_rect.min.y;
    Pos2::new(x, y)
}

pub fn draggable_scene_element(
    ui: &mut Ui,
    id: Id,
    position: &mut Rect,
    scene_rect: Rect,
    container_rect: Rect,
) -> Response {
    let is_being_dragged = ui.ctx().is_being_dragged(id);
    if is_being_dragged {
        let r = ui.put(*position, |ui: &mut Ui| ui.label("Draggable"));

        if let Some(pointer_pos) = ui.ctx().pointer_interact_pos() {
            let pointer_pos = map_to_rect(pointer_pos, container_rect, scene_rect);
            let delta = pointer_pos.to_vec2() - position.center().to_vec2();
            *position = position.translate(delta);
        };
        r
    } else {
        let r = ui.put(*position, |ui: &mut Ui| ui.label("Draggable"));
        ui
            .interact(position.clone(), id, Sense::drag())
            .on_hover_cursor(CursorIcon::Grab);
        r
    }
}

struct MyApp {
    scene_rect: Rect,
    position: Rect,
}
impl MyApp {
    fn new() -> Self {
        Self {
            scene_rect: Rect::ZERO,
            position: Rect::from_min_size(Pos2::new(-50., -50.), Vec2::new(100., 100.)),
        }
    }
}

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &Context, _frame: &mut eframe::Frame) {
        CentralPanel::default().show(ctx, |ui| {
            let scene_rect = self.scene_rect.clone();
            let container_rect = ui.min_rect();
            Scene::default().show(ui, &mut self.scene_rect, |ui| {
                ui.put(
                    Rect::from_min_size(Pos2::new(100., 200.), Vec2::new(100., 100.)),
                    |ui: &mut Ui| ui.label("static element"),
                );
                ui.put(self.position, |ui: &mut Ui| {
                    draggable_scene_element(
                        ui,
                        Id::from("demo"),
                        &mut self.position,
                        scene_rect,
                        container_rect,
                    )
                });
            });
        });
    }
}
```

# Summary

I need a way to map pointer coordinates to scene coordinates, in order
to support draggable elements in a scene. This patch makes that easier
by ensuring the scene_rect will always be the full size of the
outer_rect.

If you have a better way to accomplish what I'm after, I'm happy to
close this. Thanks!
2025-03-25 10:26:07 +01:00
Nicolas 2024295f78
Make ImageLoader use background thread (#5394)
This is the same change as in #4069 but as this is stale I wanted to
reopen a non stale PR

Modifies ImageLoader's load function to use background threads for the
image decoding work. This avoids blocking the main thread that is
especially noticeable when loading many images at once.

This was modelled after the other loader implementations that also use
threads.

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

---------

Co-authored-by: lucasmerlin <lucasmeurer96@gmail.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2025-03-25 10:17:31 +01:00
Nicolas 58b2ac88c0
Add assert messages and print bad argument values in asserts (#5216)
Enabled the `missing_assert_message` lint

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

---------

Co-authored-by: Lucas Meurer <lucasmeurer96@gmail.com>
2025-03-25 09:20:29 +01:00
Lucas Meurer 903bd81313
Add script to update local snapshots from CI (#5816)
It seems like the thresholds are too low for all tests to pass when
snapshots are generated from windows / linux. We need a better solution
to this problem, but in the meantime this script should allow
contributors to update their snapshots by downloading them from the last
CI run.
2025-03-25 09:19:21 +01:00
StratusFearMe21 390e0bfc1e
Fix text input on Android (#5759)
<!--
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 fixes an issue on android where keyboard input is not registered in
text boxes because `winit` does not fill in the `text` field of the
`KeyEvent`

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2025-03-21 14:35:46 +01:00
rustbasic 91f02f9e87
Enhance stability on Windows (#5723)
Dear emilk,

Programs built with egui on Windows are terminating every hour on
average.
When this commit is applied, it works fine for about 3 to 6 hours on
average.

I've been testing it for over 6 months and have submitted multiple PRs
since 6 months ago,
but they haven't applied it yet.

Thank you.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2025-03-21 14:32:37 +01:00
valadaptive bc090bd299
Use `RUSTUP_TOOLCHAIN=stable` for rust-analyzer (#5761)
* Resolves #5760

Overrides the toolchain used in rust-analyzer to `stable`, as [suggested
by
rustup](https://rust-analyzer.github.io/book/installation.html#rust-standard-library).
2025-03-21 13:58:02 +01:00
GiGaGon 668abc2838
Add `expand_bg` to customize size of text background (#5365)
This removes the `expand(1.0)` on text background colors, since it makes
translucent background colors have bad looking bleeding.

There is probably a smarter solution than disabling the highlighting
entirely, but I don't see a way to do that while keeping the area
consumed consistent between translucent/solid colors, or adding a decent
step up in complexity.

Since this makes it impossible to tell if selected text is highlighted,
this also adds a blanket `0.5` gamma multiply to the text selection
background color. If that is undesirable because it's a bad arbitrary
number choice, or if it's too much of an unexpected change and just the
default values should be changed, please let me know.

These changes cause the tests that use screenshots with highlighted text
to fail, though I am not sure how to update those tests to match the
changes.

<details>
<summary>Comparison Images</summary>

Current:


![image](https://github.com/user-attachments/assets/6dc85492-4f8e-4e7a-84b4-3ee10a48b8b3)

After changes:


![image](https://github.com/user-attachments/assets/9b35bbd3-159d-42a9-b22f-80febb707cfa)
 

</details>

<details>
<summary>Code used to make comparison images</summary>

```rs
fn color_text_format(ui: &Ui, color: Color32) -> TextFormat {
    TextFormat { font_id: FontId::monospace(ui.text_style_height(&egui::TextStyle::Monospace)), background: color, ..Default::default() }
}

fn color_sequence_galley(ui: &Ui, text: &str, colors: [Color32; 3]) -> Arc<Galley> {
    let mut layout_job = LayoutJob::default();
    for color in colors {
        layout_job.append(text, 0.0, color_text_format(ui, color));
    }
    ui.fonts(|f| f.layout_job(layout_job))
}

fn color_sequence_row(ui: &mut Ui, label_text: &str, text: &str, colors: [Color32; 3]) {
    ui.label(label_text);
    ui.label(color_sequence_galley(ui, text, colors));
    ui.end_row();
}

egui::Grid::new("comparison display").show(ui, |ui| {
    ui.ctx().set_pixels_per_point(2.0);
    let transparent = Color32::TRANSPARENT;
    let solid = Color32::RED;
    let solid_2 = Color32::GREEN;
    let translucent_1 = Color32::GRAY.gamma_multiply(0.5);
    let translucent_2 = Color32::GREEN.gamma_multiply(0.5);
    color_sequence_row(ui, "Transparent to Solid:", " ", [transparent, solid, transparent]);
    color_sequence_row(ui, "Translucent to Transparent:", " ", [transparent, translucent_1, transparent]);
    color_sequence_row(ui, "Solid to Transparent:", " ", [solid, solid_2, solid]);
    color_sequence_row(ui, "Solid to Solid:", " ", [solid, transparent, solid]);
    color_sequence_row(ui, "Solid to Translucent:", " ", [solid, translucent_1, solid]);
    color_sequence_row(ui, "Translucent to Translucent:", " ", [translucent_1, translucent_2, translucent_1]);
    
    color_sequence_row(ui, "Transparent to Solid:", "a", [transparent, solid, transparent]);
    color_sequence_row(ui, "Translucent to Transparent:", "a", [transparent, translucent_1, transparent]);
    color_sequence_row(ui, "Solid to Transparent:", "a", [solid, solid_2, solid]);
    color_sequence_row(ui, "Solid to Solid:", "a", [solid, transparent, solid]);
    color_sequence_row(ui, "Solid to Translucent:", "a", [solid, translucent_1, solid]);
    color_sequence_row(ui, "Translucent to Translucent:", "a", [translucent_1, translucent_2, translucent_1]);
})
```
</details>

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

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2025-03-21 13:45:34 +01:00
Emil Ernerfeldt 2058dcb881
Improve text sharpness (#5838)
This improves the sharpness of text slightly, thanks to
<https://hikogui.org/2022/10/24/the-trouble-with-anti-aliasing.html> by
@hikogui (🙏 ).

The difference is very small, but in dark mode (bright text on dark
background) text is sometimes significantly sharper, and also slightly
brighter.

The difference in light mode (dark text on light background) is much
smaller (barely perceptable).

To compare the before/after I suggest you open both in new tabs, then
quickly change between them.

### Low-DPI
#### Before
![Code Editor
old](https://github.com/user-attachments/assets/e10a3cad-932f-48cd-b7d6-5bfe70954c5e)

#### After
![Code
Editor](https://github.com/user-attachments/assets/2e7383fe-8023-4425-91c8-93df3c22c0fe)

#### Before

![old-white](https://github.com/user-attachments/assets/51c41c59-e897-4831-857a-f3ffe17ce7d4)

#### After

![new-white](https://github.com/user-attachments/assets/4ac6f951-8c57-4bcc-a5d5-788cf52ea7d8)

### High-DPI
The difference is starkest on low-DPI screens (like the above
screenshots). On high-DPI screens, the difference is much smaller

#### Before
![widget_gallery
old](https://github.com/user-attachments/assets/f2149a30-aef8-4383-b48c-73d33a03ca02)

#### After

![widget_gallery](https://github.com/user-attachments/assets/c9ceb8be-8a32-490c-9364-2c6562b741f6)
2025-03-21 12:56:47 +01:00
Emil Ernerfeldt 3f731ec794
Fix semi-transparent colors appearing too bright (#5824)
The bug was in `Color32::from_rgba_unmultiplied` and by extension
affects:

* `Color32::from_rgba_unmultiplied`
* `hex_color!`
* `HexColor`
* `ColorImage::from_rgba_unmultiplied`
* All images with transparency (png, webp, …)
* `Color32::from_white_alpha`

The bug caused translucent colors to appear too bright.

## More
Color is hard.

When I started out egui I thought "linear space is objectively better,
for everything!" and then I've been slowly walking that back for various
reasons:

* sRGB textures not available everywhere
* gamma-space is more _perceptually_ even, so it makes sense to use for
anti-aliasing
* other applications do everything in gamma space, so that's what people
expect (this PR)

Similarly, pre-multiplied alpha _makes sense_ for blending colors. It
also enables additive colors, which is nice. But it does complicate
things. Especially when mixed with sRGB/gamma (As @karhu [points
out](https://github.com/emilk/egui/pull/5824#issuecomment-2738099254)).

## Related
* Closes https://github.com/emilk/egui/issues/5751
* Closes https://github.com/emilk/egui/issues/5771 ? (probably; hard to
tell without a repro)
* But not https://github.com/emilk/egui/issues/5810

## TODO
* [x] I broke the RGBA u8 color picker. Fix it

---------

Co-authored-by: Andreas Reich <andreas@rerun.io>
2025-03-21 10:45:25 +01:00
Jim d54e29d375
macOS: Add `movable_by_window_background` option to viewport (#5412)
Add an option called `movable_by_window_background` alongside a new
builder method. When set to true, the window is movable by dragging its
background ([Apple
Docs](https://developer.apple.com/documentation/appkit/nswindow/ismovablebywindowbackground))

This is exclusive to macOS systems, similar to `fullsize_content_view`.

* [x] I have followed the instructions in the PR template
2025-03-20 11:05:22 +01:00
StratusFearMe21 52732b23a6
impl AsRef<[u8]> for FontData (#5757)
* [x] I have followed the instructions in the PR template

This PR implements `AsRef<[u8]>` for `FontData`, allowing it to be
passed into `fontdb`'s
[`Source`](https://docs.rs/fontdb/0.16.2/fontdb/enum.Source.html) type.
This would allow `egui` and `cosmic_text` to share font data with
eachother
2025-03-20 11:03:17 +01:00
Nicolas Gomez 1545dec7a8
[egui_extra] Allow loading multi-mime formats using the image_loader (#5769)
Hi ! 

I'm using egui and egui_extra to build a demo tool for a crate I'm
building. In this crate I load favicons from a lot of websites, and I
have some failures on some .ico files. After tracking this thing down, I
guess there is two issues (kinda), in the image crate,
'image/vnd.microsoft.icon' isn't recognized as the valid mime for an ico
image (I created a [PR](https://github.com/image-rs/image/pull/2434)),
and the code to detect if a given mime type is compatible with the image
crate decoders in this crate do not support multi-mime type formats.


[ImageFormat::to_mime_type](85f2412d55/src/image.rs (L216C12-L216C24))
is only returning one mime for a given format (which is fine), we
compare the result of this method to guess if the format is
valid/enabled. Retriveing the correct format using
[ImageFormat::from_mime_type](85f2412d55/src/image.rs (L166))
would allow more mime to be considered valid since multiple mime can
match the same format.

The same applies to the extension detection, which I also modified to
stay consistent

Thanks
2025-03-20 11:02:24 +01:00
valadaptive d0bd525b5d
Bump accesskit to 0.18 and make it a workspace dependency (#5783)
This can't be merged until [kittest's accesskit is
bumped](https://github.com/rerun-io/kittest/pull/9) ~~and [a new version
of rfd is released](https://github.com/PolyMeilex/rfd/pull/240)~~.

---------

Co-authored-by: Lucas Meurer <lucasmeurer96@gmail.com>
2025-03-20 11:00:12 +01:00
Juan Campa 77244cd4c5
⚠️ Close popup if `Memory::keep_popup_open` isn't called (#5814)
Breaking changes:
- When using the Memory::popup state, it's now required to call
keep_popup_open each frame or the popup will close.
- Usually handled by the `Popup` struct, but required for custom popups
using the state in `Memory` directly

-----

If a popup is abandoned `Memory::popup` would remain `Some`. This is
problematic if, for example, you have logic that checks
`is_any_popup_open`.

This PR adds a new requirement for popups keeping their open state in
`Memory::popup`. They must call `Memory::keep_popup_open` as long as
they are being rendered. The recent changes in #5716 make this easy to
implement.

Supersedes #4697 which had an awkward implementation

These two videos show a case where a context menu was open when the
underlying widget got removed.

Before (`any_popup_open` remains `true`)
![Screenshot 2025-03-16 at 18 22
50](https://github.com/user-attachments/assets/22db64dd-e6f2-4501-9bda-39f470b9210c)

After
![Screenshot 2025-03-16 at 18 21
14](https://github.com/user-attachments/assets/bd4631b1-a0ad-4047-a14d-cd4999710e07)



* Closes https://github.com/emilk/egui/issues/3657
* [x] I have followed the instructions in the PR template
2025-03-20 10:51:42 +01:00
Sven Niederberger b0bbca4e69
Add `OutputCommand::SetPointerPosition` to set mouse position (#5776)
<!--
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!
-->

This is not supported on the web and not yet on Wayland.

~~I also had to update `ring` and add an exception for `paste` being
unmaintained.~~ Has since been updated on master.

* [x] I have followed the instructions in the PR template
2025-03-20 10:51:02 +01:00
valadaptive 267485976b
Simplify the text cursor API (#5785)
<!--
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 N/A, but this is part of
https://github.com/emilk/egui/issues/3378
* [x] I have followed the instructions in the PR template

Other text layout libraries in Rust--namely, Parley and Cosmic
Text--have one canonical text cursor type (Parley's is a byte index,
Cosmic Text's also stores the line index). To prepare for migrating egui
to one of those libraries, it should also have only one text cursor
type. I also think simplifying the API is a good idea in and of
itself--having three different cursor types that you have to convert
between (and a `Cursor` struct which contains all three at once) is
confusing.

After a bit of experimentation, I found that the best cursor type to
coalesce around is `CCursor`. In the few places where we need a
paragraph index or row/column position, we can calculate them as
necessary.

I've removed `CursorRange` and `PCursorRange` (the latter appears to
have never been used), merging the functionality with `CCursorRange`. To
preserve the cursor position when navigating row-by-row, `CCursorRange`
now stores the previous horizontal position of the cursor.

I've also removed `PCursor`, and renamed `RowCursor` to `LayoutCursor`
(since it includes not only the row but the column). I have not renamed
either `CCursorRange` or `CCursor` as those names are used in a lot of
places, and I don't want to clutter this PR with a bunch of renames.
I'll leave it for a later PR.

Finally, I've removed the deprecated methods from `TextEditState`--it
made the refactoring easier, and it should be pretty easy to migrate to
the equivalent `TextCursorState` methods.

I'm not sure how many breaking changes people will actually encounter. A
lot of these APIs were technically public, but I don't think many were
useful. The `TextBuffer` trait now takes `&CCursorRange` instead of
`&CursorRange` in a couple of methods, and I renamed
`CCursorRange::sorted` to `CCursorRange::sorted_cursors` to match
`CursorRange`.

I did encounter a couple of apparent minor bugs when testing out text
cursor behavior, but I checked them against the current version of egui
and they're all pre-existing.
2025-03-20 10:49:38 +01:00
Trương Hoàng Long 6a8ee29a4e
Fix disabled `DragValue` eating focus, causing focus to reset (#5826)
<!--
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/5507
* [x] I have followed the instructions in the PR template
2025-03-20 10:45:16 +01:00
MStarha f408ccafbc
Fix `DragValue` expansion when editing (#5809)
* [x] I have followed the instructions in the PR template

This PR fixes an issue, where `DragValue` would expand when it enters
editing state. There were 3 contributing problems:
- A workaround introduced in #4276 caused the `DragValue` to report
incorrect outer size.
- The `DragValue` uses `TextEdit` internally and sets both `min_size`
and `desired_width` to the same value - desired width is used **before**
padding is applied - this is in contrast to `Button` (also used
internally by `DragValue`), which only uses `min_size`. This caused the
`DragValue` to expand horizontally by the size of button padding.
- The height of the `TextEdit` is (among other things) determined by the
height of the row, which was not present in `Button`. This caused a
small vertical expansion, when the contents (including padding) were
larger than the `min_size`.


![egui_drag_value_expansion](https://github.com/user-attachments/assets/b6fe9bd8-5755-4a43-8b61-a7e5b24e678d)
Here the dimensions set in code are:
- padding: 20 x 20 pt
- interact size: 80 x 30 pt

*Note: I do not know what's up with the tests. When I ran the check
script, they were failing because of 3 UI missmatches, so I updated the
snapshots. Now, the updated snapshots cause the same failure in CI, that
appeared locally before the update. Now the locally run tests fail with
`The platform you're compiling for is not supported by winit` and couple
more following errors coming from the same source (`winit 0.30.7`).*
2025-03-20 10:40:22 +01:00
Lucas Meurer 93c06c3405
Add color picker menu item example (#5755)
* To be merged after #5756 



https://github.com/user-attachments/assets/ad40c172-cad2-4cc5-a3ef-3284b6545e94
2025-03-19 09:33:17 +01:00
Lucas Meurer a2afc8d092
Make `close_popup` take an `Id` and add `close_all_popups` (#5820)
Ooops, fixes a regression introduced in #5799

* [x] I have followed the instructions in the PR template
2025-03-18 15:32:14 +01:00
Markus Krause 1aced06e47
refactor mime type support detection in image loader to allow for deferred handling and appended encoding info (#5686)
as recommended by @lucasmerlin in #5679

* Closes #5679
* [x] I have followed the instructions in the PR template
2025-03-18 11:51:00 +01:00
Lucas Meurer 6b38fd39a1
Use egui_demo_lib in android example (#5780)
* [x] I have followed the instructions in the PR template
2025-03-18 11:43:15 +01:00
Lucas Meurer 9604dae229
Fix kinetic scrolling on touch devices (#5778)
Fixes kinetic scrolling on android (and possibly other touch devices),
by calculating the final velocity before clearing the position history
on PointerGone events.

* Closes #5311 
* [X] I have followed the instructions in the PR template
2025-03-18 11:41:53 +01:00
Lucas Meurer 626cd9e227
Fix `Response::clicked_elsewhere` not returning true sometimes (#5798)
* Closes #5794
2025-03-18 11:40:33 +01:00
Lucas Meurer d3c1ac3798
Fix `context_menu` not closing when clicking widget (#5799)
The rerun timeline context menu wouldn't close when clicking outside,
this fixes it
2025-03-18 11:32:18 +01:00
Lucas Meurer cf756df14d
Clarify what happens when multiple modals are shown in the same frame (#5800)
* Closes #5788 
* [x] I have followed the instructions in the PR template
2025-03-18 11:30:32 +01:00
Lucas Meurer d698365dac
Fix the `StyleModifier` not being passed from popup to menu (#5805)
* [x] I have followed the instructions in the PR template
2025-03-18 11:29:20 +01:00
Sven Niederberger 024dc7b135
Add a toggle for the compact menu style (#5777)
<!--
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!
-->

Menus currently have their own style that removes outlines and
backgrounds. This is nice if the menu only contains buttons. However if
the menu contains other widgets, e.g. a drag value, the style change
makes it quite difficult to identify such widgets. This is a simple way
to make this configurable.


* [x] I have followed the instructions in the PR template
2025-03-18 11:13:59 +01:00
Adrian Blumer eb7ca72534
Fix`TextEdit` selection when placed in a `Scene`. (#5791)
* Closes https://github.com/emilk/egui/issues/5789
* [x] I have followed the instructions in the PR template

While this change fixes the TextEdit specific issue, I'm worried that
the underlying problem is more fundamental and could show up in other
widgets, and I'm wondering if there's a more general solution?
2025-03-17 10:00:47 +01:00
lucasmerlin d811940dcc
Allow unmaintained paste crate (#5787)
Should fix cargo deny CI
2025-03-13 11:45:29 +01:00
lucasmerlin 5941a27ed4
Update ring (#5786)
Upate ring to latest patch, should fix ci failures
2025-03-13 11:29:37 +01:00
lucasmerlin 962c7c7516
Deprecate `Ui::allocate_new_ui` in favor of `Ui::scope_builder` (#5764)
They had the same signature and slightly different implementations, now
it's streamlined
2025-03-05 12:08:43 +01:00
Gilberto Santos 1dea8fac9b
Fix scroll handle extending outside of `ScrollArea` (#5286)
* [x] I have followed the instructions in the PR template
* Closes https://github.com/emilk/egui/issues/3734

## Info

This PR addresses an issue where resizing a scroll handle can lead to
unwanted overlap.

It is also happening on the egui-demo.

![Screenshot 2024-10-18 at 17 35
25](https://github.com/user-attachments/assets/3a9527d9-fc46-4b25-b95a-9ba2fa54978e)

## Cause

*Note: The following explanation assumes a vertical scroll; however, the
logic applies equally to horizontal scrolling.*

When the scroll handle is positioned at the top or bottom of the scroll
area and the handle is resized to fit the minimum handle size, there is
a risk of overlap. This occurs if the handle’s new size extends beyond
the bounds of the scroll area.

## Proposed Solution

1. Check whether increasing the handle size will cause it to overlap
with the scroll area.
2. If an overlap is detected, adjust the handle’s center position by the
overlap amount, moving it towards the center of the scroll area.
2025-03-05 10:49:04 +01:00
Lucas Meurer 159ccb2fef Release 0.31.1 - text_edit and kittest fixes 2025-03-05 08:37:34 +01:00
lucasmerlin e1f5d68995
Improved git lfs instructions (#5707)
* Closes <https://github.com/emilk/egui/issues/5526>
* [x] I have followed the instructions in the PR template
2025-03-04 11:38:46 +01:00
lucasmerlin 26288d7dd7
Fix preview build failing (#5756)
The preview build randomly started failing:

https://github.com/emilk/egui/actions/runs/13633368357/job/38106240555?pr=5755
2025-03-03 17:08:54 +01:00
lucasmerlin 40bf21728d
Move gifs to git lfs (#5706)
Since we moved pngs to lfs I think we should also move the gifs there.

* [x] I have followed the instructions in the PR template
2025-03-03 15:51:43 +01:00
lucasmerlin cd22517280
⚠️ Improved menu based on `egui::Popup` (#5716)
Continuation of #5713

**Silently breaking changes:**
- Menus now close on click by default, this is configurable via
`PopupCloseBehavior`

**Additional additions:**
- `Button::right_text`
- `StyleModifier`

This is a rewrite of the egui menus, with the following goals:
- submenu buttons should work everywhere, in a popup, context menu,
area, in some random Ui
- remove the menu state from Ui
- should work just like the previous menu
- ~proper support for keyboard navigation~
  - It's better now but requires further work to be perfect
- support `PopupCloseBehavior`

* Closes #4607 
* [x] I have followed the instructions in the PR template
2025-03-03 14:56:30 +01:00
lucasmerlin 6e3575b4c7
Add `typ` to known words (#5754)
This recently started to fail:
https://github.com/emilk/egui/actions/runs/13628559355/job/38091065444?pr=5706
2025-03-03 11:40:28 +01:00
IaVashik e995c4c5b4
Fix sizing bug in `TextEdit::singleline` (#5640)
This PR reverts a change introduced in PR
https://github.com/emilk/egui/pull/3660 that caused a regression with
`TextEdit::singleline`. The original PR attempted to fix an issue with
the cursor in `TextEdit` inside `ScrollArea`, but it did so by adding
unnecessary size allocation to `TextEdit`, which breaks the layout when
`TextEdit::singleline` is used outside of `ScrollArea`.


![Image](https://github.com/user-attachments/assets/78fdf20a-0763-4b5f-b83b-64522f15b35b)

The regression introduced by #3660 is more severe, as it completely
breaks the layout of applications using `TextEdit::singleline`, as shown
in the following issues:

*   Closes https://github.com/emilk/egui/issues/5500
*   Closes https://github.com/emilk/egui/issues/5597

Furthermore, I was unable to reproduce the original bug from PR #3660 in
the current version of egui using the following code:

```rust
impl eframe::App for MyEguiApp {
    fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) {
        ctx.set_debug_on_hover(true);
        egui::CentralPanel::default().show(ctx, |ui| {
            ScrollArea::vertical().max_height(100.0).show(ui, |ui| {
                ui.add(TextEdit::multiline(&mut self.text).hint_text("Enter text here..."))
            });
        });
    }
}
```

This code attempts to recreate the layout shown in the video from PR
#3660, using a `ScrollArea` with limited height and a `TextEdit` inside.
However, the cursor hiding issue was not reproducible.

![Video_2025-01-26_17-54-24](https://github.com/user-attachments/assets/ca4750ea-8af8-4ab5-8c10-bdf73a090362)

Therefore, I believe the code added in PR #3660 is no longer necessary
and only creates more problems.

*   Closes https://github.com/emilk/egui/issues/5500
*   Closes https://github.com/emilk/egui/issues/5597
*   [x] I have followed the instructions in the PR template
2025-03-03 09:22:01 +01:00
Onè 4589cbb0fe
Fix typo in example (#5750)
* [x] I have followed the instructions in the PR template
2025-03-02 12:07:08 +01:00