Commit Graph

3277 Commits

Author SHA1 Message Date
Emil Ernerfeldt 159f8360fa
Fix doclinks in egui-wgpu docs (#4677) 2024-06-19 11:26:26 +02:00
Emil Ernerfeldt d23742cdb1
Make sure contents of a panel don't overflow (#4676)
* Closes https://github.com/emilk/egui/issues/4475
2024-06-19 10:41:01 +02:00
Emil Ernerfeldt 598dd53059
Fix buggy interaction with widgets outside of clip rect (#4675)
This fixes a bug which sometimes would make it possible to interact with
widgets that were outside the parent clip_rect.

Interaction with a widget is done with the `interact_rect`, which is the
intersection of the widget rect and the parent clip rect. If these
rectangles are disjoint (the widget is outside the parent clip rect),
this results in a _negative rectangle_ (a rectangle with a negative
width and/or height). The distance tests for negative rectangles were
broken, causing the bug.

* This is part of solving https://github.com/emilk/egui/issues/4475
* It is also likely this would have solved
https://github.com/emilk/egui/issues/4349 (which now has another fix for
it)


### Breaking changes
`Rect::distance_to_pos`, `distance_sq_to_pos`, `signed_distance_to_pos`
now all return `f32::INFINITY` if the rectangle is negative.
2024-06-19 10:21:54 +02:00
Emil Ernerfeldt 00ac5b2015 Add clippy lint `match_bool` 2024-06-18 23:45:25 +02:00
Joe Sorensen dd52291af4
Make `Debug` format of `Vec2/Pos2/Rot2` respect user precision (#4671)
* closes #4665

pretty self explanatory, i opted for 3 instead of 2 since i think that's
what display does
2024-06-18 23:03:23 +02:00
n4n5 44d7aab53d
egui_plot: use `f64` for translate (#4637)
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

Can fix translating with high zoom out
https://github.com/emilk/egui/issues/3462



* Maybe related to https://github.com/emilk/egui/issues/3656
2024-06-18 22:55:08 +02:00
Owen Diehl 413843dd7c
Make sure to call `raw_input_hook` on web (#4646)
## What's new
* Extends @varphone's excellent `raw_input_hook` idea from
https://github.com/emilk/egui/pull/4008 to `web/app_runner`.

## Details
Debugging this locally after my app's `raw_input_hook` wasn't being
called, I realized it's not in the code path of eframe's web runner,
only the native integration. Below is a toy example running on the web.


https://github.com/emilk/egui/assets/8173478/d470b7e6-d393-4ead-9745-3aafc72ae6bc
2024-06-18 22:37:04 +02:00
Aaron Manning f844873c08
Fix dead link to mycomarkup in easy_mark sample (#4643)
This is a very minor fix, but I noticed the link in the default text was
dead, so I found a link to the same project which works.
2024-06-18 22:36:56 +02:00
YgorSouza 3f53f1738b
Remove special case for 0 in DragValue default formatter (#4639)
* Closes <https://github.com/emilk/egui/issues/4610>
2024-06-18 22:36:42 +02:00
Nathan Adams 87021d3fbd
`egui_extras`: Make `serde` an optional feature (#4641)
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

All the other crates in egui have serde as an optional dependency -
which is great! But sadly egui_extras unconditionally includes it, which
adds a bunch of code to stuff that may not care for it. This PR gates
serde support behind a new `serde` feature.

This is a breaking change; if that's undesirable then we can add it as a
default feature instead, though that wouldn't match any of the other
crates.
2024-06-18 22:27:48 +02:00
crumblingstatue 49cb62b1ba
Replace `directories-next` dependency with `directories` (#4661)
`directories-next` was created because `directories` was not maintained
at the time. However, `directories` has gotten active maintainership
since, and it has received more updates than `directories-next`.

`directories` also has more recent downloads than its `next`
counterpart, so it might make sense to switch to it, to avoid
unnecessary duplicate dependencies, where a project depends transitively
on both `directories` and `directories-next`.

The main question is whether we depend on any specific behavior from
`directories-next`.
2024-06-18 22:17:21 +02:00
YgorSouza ee3b04ea17
Fix typos (#4640) 2024-06-18 22:10:59 +02:00
Andrew Farkas 3cdb667cd6
Fix typo in docs of `Ui::shrink_height_to_current()` (#4672)
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->
2024-06-18 21:57:19 +02:00
Emil Ernerfeldt 814ad0783c
Update to wgpu 0.20 (#4560)
* this PR reverts https://github.com/emilk/egui/pull/4559
* and re-applies https://github.com/emilk/egui/pull/4433

Before we merge, we're waiting for a wgpu 0.20.1 patch-release of

* https://github.com/gfx-rs/wgpu/pull/5681

---------

Co-authored-by: Andreas Reich <r_andreas2@web.de>
2024-06-13 15:00:23 +02:00
Emil Ernerfeldt ca36f3df63
Make sure tooltips are interactable (#4649)
…so you can't hover things underneath them.

* Better version of https://github.com/emilk/egui/pull/4648
2024-06-10 14:05:06 +02:00
Emil Ernerfeldt e2a127a381
RELEASES.md: document release process and checklist (#4633)
This should hopefully be clear enough that someone else than me could do
an egui release at some point, if needed.


[Rendered](https://github.com/emilk/egui/blob/emilk/releases.md/RELEASES.md)
2024-06-10 09:43:05 +02:00
Antoine Beyeler 9f12432bcf
Improve behavior of plot auto-bounds with reduced data (#4632)
* Fixes #3808
* Fixes #2307

This PR improves the behaviour of auto-bounds with data that:
- is a single point
- where all X values are the same (e.g. vertical line)
- where all Y values are the same (e.g. horizontal line)

In all case, the auto-bound now aim to center on the data. For span,
when available, it use the same as the other axis. If the data range of
the other axis is also degenerate, then it defaults to +/- 1.0.


https://github.com/emilk/egui/assets/49431240/a62d2b5b-7856-4415-8534-83dc58cfac98


<details>
<summary>Test code</summary>

```rust
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
#![allow(rustdoc::missing_crate_level_docs)] // it's an example

use eframe::egui;
use egui_plot::{Legend, Line, Plot, PlotPoints, Points};

fn main() -> Result<(), eframe::Error> {
    env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).

    let options = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default().with_inner_size([350.0, 200.0]),
        ..Default::default()
    };
    eframe::run_native(
        "My egui App with a plot",
        options,
        Box::new(|_cc| Ok(Box::<MyApp>::default())),
    )
}

#[derive(Default)]
struct MyApp {}

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        let mut plot_rect = None;
        egui::CentralPanel::default().show(ctx, |ui| {
            if ui.button("Save Plot").clicked() {
                ctx.send_viewport_cmd(egui::ViewportCommand::Screenshot);
            }

            let my_plot = Plot::new("My Plot").legend(Legend::default());

            // let's create a dummy line in the plot
            let inner = my_plot.show(ui, |plot_ui| {
                plot_ui.line(
                    Line::new(PlotPoints::from(vec![
                        [0.0, 10.0],
                        [2.0, 10.0],
                        [3.0, 10.0],
                    ]))
                    .name("y = 10.0"),
                );

                plot_ui.line(
                    Line::new(PlotPoints::from(vec![
                        [10.0, 10.0],
                        [10.0, 11.0],
                        [10.0, 12.0],
                    ]))
                    .name("x = 10.0"),
                );
                plot_ui.points(
                    Points::new(PlotPoints::from(vec![[5.0, 5.0]]))
                        .name("(5,5)")
                        .radius(3.0),
                );
                plot_ui.points(
                    Points::new(PlotPoints::from(vec![[5.0, 7.0]]))
                        .name("(5,7)")
                        .radius(3.0),
                );
            });
            // Remember the position of the plot
            plot_rect = Some(inner.response.rect);
        });

        // Check for returned screenshot:
        let screenshot = ctx.input(|i| {
            for event in &i.raw.events {
                if let egui::Event::Screenshot { image, .. } = event {
                    return Some(image.clone());
                }
            }
            None
        });

        if let (Some(screenshot), Some(plot_location)) = (screenshot, plot_rect) {
            if let Some(mut path) = rfd::FileDialog::new().save_file() {
                path.set_extension("png");

                // for a full size application, we should put this in a different thread,
                // so that the GUI doesn't lag during saving

                let pixels_per_point = ctx.pixels_per_point();
                let plot = screenshot.region(&plot_location, Some(pixels_per_point));
                // save the plot to png
                image::save_buffer(
                    &path,
                    plot.as_raw(),
                    plot.width() as u32,
                    plot.height() as u32,
                    image::ColorType::Rgba8,
                )
                .unwrap();
                eprintln!("Image saved to {path:?}.");
            }
        }
    }
}
```

</details>
2024-06-07 11:13:17 +02:00
Antoine Beyeler 2545939c15
Add `Color32::lerp_to_gamma` (#4627)
Add `lerp_to_gamma` utility function to `Color32`

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-06-06 15:41:10 +02:00
Sven Niederberger 1f008fb730
ScrollArea: Prevent drag interaction outside the area (#4611)
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

* Closes https://github.com/emilk/egui/issues/4349
2024-06-06 15:36:20 +02:00
Emil Ernerfeldt 29b12e1760
Easing functions (#4630)
This adds most of the "standard" easing functions from
https://easings.net/ to `emath::easing`, and adds helpers in `egui` for
using them.

In particular there is now `ctx.animate_bool_with_easing` and
`ctx.animate_bool_responsive`, that uses a cubic easing function.

All animations in egui now uses cubic ease-out, for a more responsive
feeling (fast at the start, slower towards the end).
2024-06-06 13:09:52 +02:00
Jan Procházka 3d632cd333
Move first `request_animation_frame` into resize observer (#4628)
This PR ensures the first animation frame happens _after_ the resize
observer has had a chance to do its job.

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

The first commit contains some `log` calls to observe the changed
behavior:

Before:
```
[eframe::web::app_runner] eframe/src/web/app_runner.rs:191: LOGIC [300.0 150.0]
[eframe::web::events] eframe/src/web/events.rs:633: ResizeObserver canvas=[300.0 150.0] to=(1920, 993)
[eframe::web::app_runner] eframe/src/web/app_runner.rs:191: LOGIC [1920.0 993.0]
[eframe::web::app_runner] eframe/src/web/app_runner.rs:191: LOGIC [1920.0 993.0]
```

After:
```
[eframe::web::events] eframe/src/web/events.rs:633: ResizeObserver canvas=[300.0 150.0] to=(1920, 993)
[eframe::web::app_runner] eframe/src/web/app_runner.rs:191: LOGIC [1920.0 993.0]
[eframe::web::app_runner] eframe/src/web/app_runner.rs:191: LOGIC [1920.0 993.0]
```
2024-06-06 10:30:32 +02:00
Emil Ernerfeldt cbb5d6aa93
Handle tooltips so large that they cover the widget (#4623)
Previously a tooltip that overlapped the original widget would case an
invisible or flickering tooltip.

* Closes https://github.com/emilk/egui/issues/4616
2024-06-05 19:08:51 +02:00
Emil Ernerfeldt bb8400853f
Add tags to `UiStack` (#4617)
You can now set custom tags on the `UiStack`. This allows you to write
code that is situationally aware at runtime. For instance, you could
decide wether or not a label should truncate its text depending on what
part of your ui it is in, without having to pass that info down via the
callstack.
2024-06-05 18:46:50 +02:00
Emil Ernerfeldt 321d2441c1
Make pinch-to-zoom more responsive on web (#4621)
It's 2x faster than before, more closely matching how pinch-to-zoom
feels natively on Mac
2024-06-05 18:32:04 +02:00
Emil Ernerfeldt 4837dc68b3
Fix pinch-to-zoom on web by using the "artificial" modifier keys (#4619)
* Introduced in https://github.com/emilk/egui/pull/4524
* Closes https://github.com/emilk/egui/issues/4615
2024-06-05 18:05:48 +02:00
Emil Ernerfeldt d72de1eab3
Deprecate `ui.set_enabled` and `set_visbile` (#4614)
These were confusing, because `set_enabled(true)` and
`set_visible(true)` did nothing.

Instead use one of:
* `ui.add_enabled`, `ui.add_enabled_ui` or `ui.disable()`
* `ui.add_visible`, `ui.add_visible_ui` or `ui.set_invisible()`

* Closes https://github.com/emilk/egui/issues/4327
2024-06-05 13:20:54 +02:00
Emil Ernerfeldt 0028764e02
Set the `sizing_pass` flag in first frame of `egui_extras::Table` (#4613)
* Closes https://github.com/emilk/egui/issues/4535

This should improve the auto-sizing of columns when nesting expanding
widgets (e.g. `Separator`), or centered or justified layouts.
2024-06-05 12:17:15 +02:00
Emil Ernerfeldt a50f253b76
`Grid`: set the `sizing_pass` flag during the initial sizing pass (#4612)
* Part of https://github.com/emilk/egui/issues/4535

This should improve the auto-sizing of columns when nesting expanding
widgets (e.g. `Separator`), or centered or justified layouts.
2024-06-05 12:17:08 +02:00
Antoine Beyeler a28792194d
Introduce `UiStack` (#4588)
* Closes #4534

This PR:
- Introduces `Ui::stack()`, which returns the `UiStack` structure
providing information on the current `Ui` hierarchy.
- **BREAKING**: `Ui::new()` now takes a `UiStackInfo` argument, which is
used to populate some of this `Ui`'s `UiStack`'s fields.
- **BREAKING**: `Ui::child_ui()` and `Ui::child_ui_with_id_source()` now
take an `Option<UiStackInfo>` argument, which is used to populate some
of the children `Ui`'s `UiStack`'s fields.
- New `Area::kind()` builder function, to set the `UiStackKind` value of
the `Area`'s `Ui`.
- Adds a (minimalistic) demo to egui demo (in the "Misc Demos" window).
- Adds a more thorough `test_ui_stack` test/playground demo.

TODO:
- [x] benchmarks
- [x] add example to demo

Future work:
- Add `UiStackKind` and related support for more container (e.g.
`CollapsingHeader`, etc.)
- Add a tag/property system that would allow adding arbitrary data to a
stack node. This data could then be queried by nested `Ui`s. Probably
needed for #3284.
- Add support to track columnar layouts.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-06-04 10:12:23 +02:00
Emil Ernerfeldt c0a9800d05
Support interactive widgets in tooltips (#4596)
* Closes https://github.com/emilk/egui/issues/1010

### In short
You can now put interactive widgets, like buttons and hyperlinks, in an
tooltip using `on_hover_ui`. If you do, the tooltip will stay open as
long as the user hovers it.

There is a new demo for this in the egui demo app (egui.rs):


![interactive-tooltips](https://github.com/emilk/egui/assets/1148717/97335ba6-fa3e-40dd-9da0-1276a051dbf2)

### Design
Tooltips can now contain interactive widgets, such as buttons and links.
If they do, they will stay open when the user moves their pointer over
them.

Widgets that do not contain interactive widgets disappear as soon as you
no longer hover the underlying widget, just like before. This is so that
they won't annoy the user.

To ensure not all tooltips with text in them are considered interactive,
`selectable_labels` is `false` for tooltips contents by default. If you
want selectable text in tooltips, either change the `selectable_labels`
setting, or use `Label::selectable`.

```rs
ui.label("Hover me").on_hover_ui(|ui| {
    ui.style_mut().interaction.selectable_labels = true;
    ui.label("This text can be selected.");

    ui.add(egui::Label::new("This too.").selectable(true));
});
```

### Changes
* Layers in `Order::Tooltip` can now be interacted with
2024-06-03 11:37:06 +02:00
trevyn 7b3752fde9
Update README to maintained Tetra integration (#4606)
Original integration https://github.com/tesselode/egui-tetra is
archived, so I forked and updated for latest `egui` and `tetra`.
2024-06-03 10:21:40 +02:00
Onè 4d9aed8f83
Add missing word (#4603)
Was reading the docs and noticed a typo.
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

* Closes <https://github.com/emilk/egui/issues/THE_RELEVANT_ISSUE>
2024-06-02 21:14:40 +02:00
Emil Ernerfeldt 78dfdb3684
`Rect::intersects_ray`: another bug fix (#4597)
Make sure it returns `true` if the ray starts inside the box
2024-05-31 17:28:38 +02:00
Emil Ernerfeldt b6805a8006
Fix bug in ray-rect intersection test (#4595)
This made submenu popups stay open when they perhaps shouldn't be
2024-05-31 17:10:46 +02:00
Emil Ernerfeldt d4ac91ab6d
Refactor: remove extra tooltip id salt (#4594) 2024-05-31 16:50:39 +02:00
Emil Ernerfeldt 86560554bc
Fix bug in context menu positioning when at bottom of the screen (#4593)
I think this broke with the sizing pass
2024-05-31 15:56:52 +02:00
rustbasic d3ea90f5ef
Fix dragging of `custom_window_frame` on Windows (#4592)
Fix: example `custom_window_frame`

Sending `ViewportCommand::StartDrag` when the secondary button is
clicked in Windows will disable drag, and drag will not be possible with
the primary button afterwards.

So in the example `custom_window_frame`, modified to use
`dragged_by(PointerButton::Primary)` instead of
`is_pointer_button_down_on()`.
2024-05-31 15:22:46 +02:00
Emil Ernerfeldt df8b9c2d75
Constrain `Area`s to screen by default (#4591)
Call `area.constrain(false)` if you want your areas to extend outside
the screen rect.
2024-05-31 10:48:06 +02:00
Emil Ernerfeldt c0479cadf3
The default constrain rect for `Area/Window` is now `ctx.screen_rect` (#4590)
By default, `Windows` can now cover already added panels. For instance:
in the egui demo app (egui.rs), windows can now cover the side-panels
and top bar.

To get the old behaviour, use
`window.constrain_to(ctx.available_rect())`.
2024-05-31 10:01:45 +02:00
sor-ca 8f5986125d
Make `egu::menu` types public (#4544)
Sometimes we need to fix the current state of the application in the
moment when you open the context menu, to save it, and to use it during
creation of context menu and response handling. Making some structs,
related with menu creating, allow us to create functions for this cases.
For example,
```rust
pub fn context_menu_custom<'a, T>(
    response: &Response,
    //variable for fixing state in the moment when you open context menu
    state: &mut T,
    //function which allow to get some king of state.
    //In this case state depends on cursor position, in other cases it may depend on system time or something else
    get_state: impl FnOnce(Pos2) -> T,
    //set contents of menu depending on state
    set_contents: impl 'a + FnOnce(&T) -> Box<dyn 'a + FnOnce(&mut Ui)>,
) -> Option<InnerResponse<()>> {
    let menu_id = Id::new("__egui::context_menu");
    let mut bar_state = BarState::load(&response.ctx, menu_id);
    let root = &mut bar_state;

    let menu_response = MenuRoot::context_interaction(response, root);
    if let egui::menu::MenuResponse::Create(p, _) = &menu_response {
        *state = get_state(*p);
    };

    let add_contents = set_contents(&state);

    MenuRoot::handle_menu_response(root, menu_response);
    let inner_response = bar_state.show(response, add_contents);

    bar_state.store(&response.ctx, menu_id);
    inner_response
}
```
The example of using such function you may see in [`my
repository`](https://github.com/sor-ca/context_menu)
It is very simple example, and is this case, the problem may be solved
without fn context_menu_custom, but in more complex situations, it may
be very useful
Related issue: https://github.com/emilk/egui/issues/4162

<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-05-31 09:02:02 +02:00
Emil Ernerfeldt 84d204246f
Fade in windows, tooltips, popups, etc (#4587)
All `Area`s now have a quick fade-in animation. You can turn it off with
`Area::fade_in` or `Window::fade_in` .

The `Window` fade-out animation is now nicer: it fades all elements of
the window, not just the frame.
It can be controlled with `Window::fade_out`.
2024-05-30 16:22:12 +02:00
Emil Ernerfeldt 6282844f65
Add `opacity` and `multiply_opacity` functions to `Ui` and `Painter` (#4586) 2024-05-30 16:07:42 +02:00
Emil Ernerfeldt a7eed0ae3c
Once you have waited for a tooltip to show, show the next one right away (#4585)
* Closes https://github.com/emilk/egui/issues/4582

User-story: there are multiple icons in a row, and the user wants them
explained. They hover over one until the tooltips appears. They then
move on to the next and don't want to wait for that tooltip again.
2024-05-30 13:23:01 +02:00
Emil Ernerfeldt 89968e6f96
Bug fix: ui opacity and gray-out not affecting strokes (#4581)
Bug introduced in https://github.com/emilk/egui/pull/4353
2024-05-29 22:37:55 +02:00
Emil Ernerfeldt 16277ebb86
Add `Response::show_tooltip_ui` and `show_tooltip_text` (#4580)
These functions will always show a tooltip under the widget when called,
even if the user is not hovering the widget.

This can be useful for tutorials and notification and similar.

* Closes https://github.com/emilk/egui/issues/890
2024-05-29 21:28:56 +02:00
Emil Ernerfeldt 00396145d1
Improve tooltip positioning (#4579)
This simplifies and improves the tooltip positioning

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

### For a follow-up PR
* [ ] Test if it closes https://github.com/emilk/egui/issues/4471
* [ ] Add an API to close https://github.com/emilk/egui/issues/890
2024-05-29 21:18:08 +02:00
Emil Ernerfeldt cc3b3629b8
Round text galley sizes to nearest ui point size (#4578)
Previously, many labels had non-integer widths. This lead to rounding
errors.

This was most notable for the new `Area` sizing code:

We would run the initial sizing pass, to measure the size of e.g. a
tooltip.
Say the tooltip contains text that was 100.123 ui points wide. With a
16pt border, that becomes 116.123, which is stored in the `Area` state
as the width. The next frame, we use that stored size as the wrapping
width. With perfect precision, we would then tell the label to wrap to
100.123 pts, which the text would _just_ fit in. However, due to
rounding errors we might end up asking it to wrap to 100.12**2** pts,
meaning the last word would now wrap and end up on the next line.

By rounding label sizes to perfect integers, we avoid such rounding
errors, and most ui elements will now end up on perfect integer point
coordinates (and `f32` can precisely express and do arithmetic on all
integers < 2^24).

Visually this has very little impact. Some labels move by a pixel here
and there, mostly for the better.
2024-05-29 18:23:11 +02:00
Emil Ernerfeldt 66f40de7a1
Don't persist `Area` state (#4577)
If you change your code for what is contained in a menu, tooltips,
combobox etc, it is helpful if egui will recompute the size of that Area
next frame. Now it will!

The user-chosen size of a `Window` is still persisted via other means.
2024-05-29 15:59:51 +02:00
Emil Ernerfeldt c7cb524bdb
Make `Area` state public (#4576) 2024-05-29 15:48:52 +02:00
Emil Ernerfeldt 913cef3361
Enforce eframe errors are `Send` and `Sync` (#4574)
* Follow-up to https://github.com/emilk/egui/pull/4565
2024-05-29 13:13:00 +02:00