Commit Graph

56 Commits

Author SHA1 Message Date
Emil Ernerfeldt 42b9491364 Fix docstring 2024-06-26 09:00:11 +02:00
zkldi 8cef6fc872
doc(emath): Add `top_left` as an alias for `left_top`, etc. (#4689)
# What

Adds `#[doc(alias = "top_left")]` as an alias for `left_top`, and so on
for `right_top`, `right_bottom`, `left_bottom`.

# Why

Extremely minor doc-only change, but I keep going to type "top left" to
look for the top left of a rectangle.
I'm unsure whether this is just a british-english thing or an
english-in-general thing, but `top left corner` is far more common than
`left top corner`.
These doc aliases don't conflict with anything, and mean that
rust-analyzer will suggest the correct function when I search for the
wrong thing.

This improves ergonomics and discoverability in my opinion, even if not
by much.
2024-06-23 11:50:35 +02:00
Emil Ernerfeldt 902b4d960d Add `Rect::from_pos` 2024-06-19 11:27:33 +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
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
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
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 a768d74411
Add `Ui::is_sizing_pass` for better size estimation of `Area`s, and menus in particular (#4557)
* Part of https://github.com/emilk/egui/issues/4535
* Closes https://github.com/emilk/egui/issues/3974

This adds a special `sizing_pass` mode to `Ui`, in which we have no
centered or justified layouts, and everything is hidden. This is used by
`Area` to use the first frame to measure the size of its contents so
that it can then set the perfectly correct size the subsequent frames.

For menus, where buttons are justified (span the full width), this
finally the problem of auto-sizing. Before you would have to pick a
width manually, and all buttons would expand to that width. If it was
too wide, it looked weird. If it was too narrow, text would wrap. Now
all menus are exactly the width they need to be. By default menus will
wrap at `Spacing::menu_width`.

This affects all situations when you have something that should be as
small as possible, but still span the full width/height of the parent.
For instance: the `egui::Separator` widget now checks the
`ui.is_sizing_pass` flag before deciding on a size. In the sizing pass a
horizontal separator is always 0 wide, and only in subsequent passes
will it span the full width.
2024-05-29 10:27:04 +02:00
Emil Ernerfeldt c3f386aa30
Remove work-around for `unsafe` in puffin macro (#4484)
…since it is no longer in the puffin macro
2024-05-11 20:17:19 +02:00
Emil Ernerfeldt f19f99180e
Remove `extra_asserts` and `extra_debug_asserts` feature flags (#4478)
Removes `egui_assert` etc and replaces it with normal `debug_assert`
calls.

Previously you could opt-in to more runtime checks using feature flags.
Now these extra runtime checks are always enabled for debug builds.

You are most likely to encounter them if you use negative sizes or NaNs
or other similar bugs.
These usually indicate bugs in user space.
2024-05-10 19:39:08 +02:00
Emil Ernerfeldt ded8dbd45b
Fix some clippy warning from Rust 1.78.0 (#4444) 2024-05-02 17:04:25 +02:00
Trevor Gross 2fabde1396
Add a `Display` impl for `Vec2`, `Pos2`, and `Rect` (#4428)
These three types currently have a `Debug` implementation that only ever
prints one decimal point. Sometimes it is useful to see more of the
number, or otherwise have specific formatting.

Add `Display` implementations that pass the format specification to the
member `f32`s for an easier way to control what is shown when debugging.

This allows doing e.g. `ui.label(format!("{:.4}", rect * scale))` which
currently prints zeroes if scale is small.
2024-04-29 14:22:34 +02:00
Emil Ernerfeldt 87b294534e
Add `emath::OrderedFloat` (moved from `epaint::util::OrderedFloat`) (#4389)
It makes much more sense in `emath`
2024-04-21 20:36:32 +02:00
Emil Ernerfeldt 884cf6de3d Add some tests for `Rect` 2024-03-26 11:13:04 +01:00
rustbasic 7d3d7ce0ca
typos : intersects_ray() (#4201)
typos : intersects_ray()
2024-03-21 12:10:02 +01:00
Emil Ernerfeldt 0afbefc884
Improve logic for when submenus are kept open (#4166)
* Closes https://github.com/emilk/egui/issues/2853
* Closes https://github.com/emilk/egui/issues/4101
* Reverts parts of https://github.com/emilk/egui/pull/3055
2024-03-13 12:32:54 +01:00
Emil Ernerfeldt 00a399b2f7
A `Window` can now be resizable in only one direction (#4155)
For instance: `Window::new(…).resizable([true, false])` is a window that
is only resizable in the horizontal direction.

This PR also removes a hack added in
https://github.com/emilk/egui/pull/3039 which is no longer needed since
https://github.com/emilk/egui/pull/4026
2024-03-11 09:29:48 +01:00
Emil Ernerfeldt 18eeb01f57
Quickly animate scroll when calling `ui.scroll_to_cursor` etc (#4119)
Uses ease-in-ease-out interpolation, with a time between 0.1s and 0.3s,
depending on the distance needed to scroll.


![smooth-scroll-to-target](https://github.com/emilk/egui/assets/1148717/c5c8556d-476b-4597-842b-aa0e5927fbb9)
2024-03-04 20:00:13 +01:00
Georg Weisert e8af6f38fc
Serde feature: Add serde derives to input related structs (#4100)
We plan to store input data for creating automated tests, hence the need
for more serde derives on input related structs.

---------

Co-authored-by: Georg Weisert <georg.weisert@freshx.de>
2024-02-26 13:33:43 +01:00
Francis Chua 069d7a634d
Add layer transforms, interaction in layer (#3906)
⚠️ Removes `Context::translate_layer`, replacing it with a sticky
`set_transform_layer`

Adds the capability to scale layers.
Allows interaction with scaled and transformed widgets inside
transformed layers.

I've also added a demo of how to have zooming and panning in a window
(see the video below).

This probably closes #1811. Having a panning and zooming container would
just be creating a new
`Area` with a new id, and applying zooming and panning with
`ctx.transform_layer`.

I've run the github workflow scripts in my repository, so hopefully the
formatting and `cargo cranky` is satisfied.

I'm not sure if all call sites where transforms would be relevant have
been handled. This might also be missing are transforming clipping
rects, but I'm not sure where / how to accomplish that. In the demo, the
clipping rect is transformed to match, which seems to work.


https://github.com/emilk/egui/assets/70821802/77e7e743-cdfe-402f-86e3-7744b3ee7b0f

---------

Co-authored-by: tweoss <fchua@puffer5.stanford.edu>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-02-17 11:02:56 +01:00
Emil Ernerfeldt 527f4bfdf6
Expand plot axes thickness to fit their labels (#3921)
Expand the plot axis thickness as the contained plot axis labels get
wider.

This fixes a problem where the plot labels would otherwise get clipped.


![plot-axis-expansion](https://github.com/emilk/egui/assets/1148717/4500a26e-4a11-401d-9e8e-2d98d02ef3b7)
2024-01-30 12:45:27 +01:00
Emil Ernerfeldt 41aad74552
Cross-widget text select (#3870)
* Closes https://github.com/emilk/egui/issues/3816


![cross-widget-text-selection](https://github.com/emilk/egui/assets/1148717/5582b9d2-8b04-47b7-9637-f48e44064a70)

Turn off with `style.interaction.multi_widget_text_select`.

There is an API for this in `LabelSelectionState`, but it's pretty
bare-bones.

This became really hairy implementation-wise, but it works decently
well.

# Limitations
* Drag-select to scroll doesn't work
* A selection disappears if you scroll past one of its end-points
* Only the text of labels and links are selectable
 
## TODO
* [x] An option to turn it off
* [x] An API for querying about the selected text, and to deselect it.
* [x] Scrolling past selection behaves weird
* [x] Shift-click to select a range
2024-01-24 15:45:22 +01:00
Emil Ernerfeldt 31cc31a67b
Add `Align2::anchor_size` (#3863) 2024-01-22 16:47:50 +01:00
Emil Ernerfeldt 401de05630
Use `Self` everywhere (#3787)
This turns on the clippy lint
[`clippy::use_self`](https://rust-lang.github.io/rust-clippy/v0.0.212/index.html#use_self)
and fixes it everywhere.
2024-01-08 17:41:21 +01:00
Emil Ernerfeldt 8c30e8c5f7
Highlight submenu buttons when hovered and open (#3780)
Submenu buttons in menues now properly highlight when hovered and when
opened.

…plus a bunch of other cleanup
2024-01-07 22:08:32 +01:00
Emil Ernerfeldt 4060d02f27 Add a bunch of `#[inline]` 2023-12-18 17:28:47 +01:00
Emil Ernerfeldt 8d4de866d4
Remove deprecated functions (#3692) 2023-12-08 11:02:57 +01:00
YgorSouza 4ece25bd05
Keep unsafe code forbidden when puffin is disabled (#3603)
This helps document what unsafe is being used for, and prevent other
uses from going unnoticed.
2023-11-22 20:37:46 +01:00
Emil Ernerfeldt 1bbd5a9fc8
Update puffin to 0.18 (#3600)
THe profiling macros now contain unsafe code (but in a safe way), so
`#[foribd(unsafe)]` had to become `#[deny(unsafe)]`
2023-11-21 17:58:33 +01:00
Antoine Beyeler f20b7b43bf
Plot auto-bounds API improvement (part 1/2): clean-up (#3587)
Part 1 of 2 of adding a better API for egui_plot's auto-bounds feature.

In this PR:
- change the `Plot` builder struct field to `default_auto_bounds` (was
`auto_bounds`)
- change the `Plot` state field to `auto_bounds` (was `bounds_modified`)
- minor improvements to `Vec2b`
2023-11-21 11:22:19 +01:00
Emil Ernerfeldt 1571027556
Replace `eframe::Frame` commands and `WindowInfo` with egui (#3564)
* Part of https://github.com/emilk/egui/issues/3556

## In short
You now almost never need to use `eframe::Frame` - instead use
`ui.input(|i| i.viewport())` for information about the current viewport
(native window), and use `ctx.send_viewport_cmd` to modify it.

## In detail

This PR removes most commands from `eframe::Frame`, and replaces them
with `ViewportCommand`.
So `frame.close()` becomes
`ctx.send_viewport_cmd(ViewportCommand::Close)`, etc.

`frame.info().window_info` is now also gone, replaced with `ui.input(|i|
i.viewport())`.

`frame.info().native_pixels_per_point` is replaced with `ui.input(|i|
i.raw.native_pixels_per_point)`.

`RawInput` now contains one `ViewportInfo` for each viewport.

Screenshots are taken with
`ctx.send_viewport_cmd(ViewportCommand::Screenshots)` and are returned
in `egui::Event` which you can check with:

``` ust
ui.input(|i| {
    for event in &i.raw.events {
        if let egui::Event::Screenshot { viewport_id, image } = event {
            // handle it here
        }
    }
});
```

### Motivation
You no longer need to pass around the `&eframe::Frame` everywhere.
This also opens the door for other integrations to use the same API of
`ViewportCommand`s.
2023-11-18 19:27:53 +01:00
YgorSouza 3e37e9dfc7
Update hyperlink doc (#3561)
<!--
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 <https://github.com/emilk/egui/issues/3474>.
2023-11-18 17:13:03 +01:00
Emil Ernerfeldt a243180600
Add `#[inline]` to all builder-pattern functions (#3557)
Better performance and maybe code size
2023-11-16 13:50:05 +01:00
Emil Ernerfeldt 6ba356d3d8
Replace `Id::null()` with `Id::NULL` (#3544)
Shorter and more idiomatic
2023-11-11 21:40:02 +01:00
Emil Ernerfeldt b27aa27e94
Add `emath::Vec2b`, replacing `egui_plot::AxisBools` (#3543)
Thanks to `impl From<bool> for Vec2b` one can now shorten some builder
calls, like:

Previous:
```rust
 egui::ScrollArea::vertical()
        .auto_shrink([false; 2])
```

New:
```rust
 egui::ScrollArea::vertical()
        .auto_shrink(false)
```
2023-11-11 21:31:36 +01:00
Phen-Ro 5f4046d68a
Use `impl Into<Stroke>` as argument in a few more places (#3420)
* Functions that take Stroke were updated to take Into<Stroke> to make
them consistent with other Into<Stroke> parameters.
* Vec2 implements DivAssign<f32>, to make it consistent with already
implementing MulAssign<f32> and Div<f32>.
* Vec2::angled() uses sin_cos() rather than an individual sin() and
cos() call for an immeasurable but hypothetical performance improvement.
* Disable the lock_reentry_single_thread() mutex test. Lock()ing twice
on the same thread is not guaranteed to panic.

* Closes <https://github.com/emilk/egui/issues/3419>.
2023-11-10 21:36:51 +01:00
YgorSouza 7e2c65a82a
Fix upside down slider in the vertical orientation (#3424) 2023-11-10 11:16:38 +01:00
Emil Ernerfeldt 41f9df5cb3
Floating scroll bars (#3539)
* Move scroll bar spacing settings to a `struct ScrollSpacing`

* Add a demo for changing scroll bar appearance

* Add setting for ScrollBarVisibility in demo

* Add `#[inline]` to a `ScrollArea` builder methods

* Refactor how scroll bar show/hide is computed

* Add support for floating scroll bars

* Tweak color and opacity of the scroll handle

* Allow allocating a fixed size even for floating scroll bars

* Add three pre-sets of scroll bars: solid, thin, floating

* Use floating scroll bars as the default

* Fix id-clash with bidir scroll areas

* Improve demo

* Fix doclink

* Remove reset button from demo

* Fix doclinks

* Fix visual artifact with thin rounded rectangles

* Fix doclink

* typos
2023-11-09 18:41:58 +01:00
Emil Ernerfeldt fdd493d48f
Misc cleanup (#3381)
* Give credit to recent big-time contributors in the main README.md

* Better named profiling scopes

* Document everything in memory.rs

* Better doc-strings

* Add a section about dependencies to the main README.md

* Improve egui_extras docs

* fix typos
2023-09-24 09:32:31 +02:00
Emil Ernerfeldt 82704bebbf
Update MSRV to Rust 1.70.0 (#3310)
* Update to Rust 1.70

* Fix renamed clippy lint

* Use let-else more

* Code cleanup

* Remove derelict Safety comments

* Enable more clippy lints
2023-09-06 07:59:24 +02:00
Timon ea15987ad4
Change focused widget with arrow keys (#3272)
* Allow widget focus change with keyboard arrows

* remove set id function

* docs

* Emilk feedback round 1

* Fix compile error

* undo example

* Move out functions from range to memory.rs

* remove contains range

* Use docstrings

* code cleanup

* Improve candidate logic

* More tweaks

* Less `pub`

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2023-08-30 10:28:21 +02:00
Emil Ernerfeldt 3c4223c6b1
Support images with rounded corners (#3257)
* Add `Rect::ZERO`

* Add `Rounding::ZERO`

* Add `RectShape::new`

* Add `Image::rounding` to support images with rounded corners
2023-08-15 09:29:30 +02:00
Emil Ernerfeldt 08fb447fb5
Increase MSRV to 1.67 (#3234)
* Bump MSRV to 1.67

* clippy fixes

* cargo clippy: inline format args

* Add `clippy::uninlined_format_args` to cranky lints

* Fix clippy on wasm

* More clippy fixes
2023-08-11 13:54:02 +02:00
Emil Ernerfeldt 8cdffc4e2d
Replace uses of `RangeInclusive<f32>` with `emath::Rangef` (#3221)
* Replace uses of `RangeInclusive<f32>` with `emath::Rangef`

* Fix doc-test
2023-08-10 13:07:00 +02:00
Valeriy V. Vorotyntsev 4c3b380889
Fix the "ever-growing height" problem of Strip and Table demos (#3122)
* Fix the "ever-growing height" problem of Strip and Table Demos

Problem
-------

The height of "Table Demo" or "Strip Demo" floating window grows
when the demo app is interacted with. If 'Continuous' mode is enabled
in 'Backend' settings, the window grows irrespectively of user interaction.

Observations
------------

I noticed that [`area_content_ui.min_rect().max.y`][1] is increasing
monotonically with speed 0.5 px/frame.

I also noticed that commenting out `ui.add(crate::egui_github_link_file!());`
[statement][2] in `table_demo.rs` makes the problem disappear.

The "Fix"
---------

I added 0.5 to the height of the row with GitHub link.
This solved the problem.

Closes #3029.

Warning
-------

I failed to find the root cause of the problem.
I don't understand why this change makes the problem disappear.

[1]: 9478e50d01/crates/egui/src/containers/window.rs (L403)
[2]: 9478e50d01/crates/egui_demo_lib/src/demo/table_demo.rs (L114)

* Document `Rect::size`

Other changes:

- `area.rs`: Use existing API.
- `table_demo.rs`: Remove unnecessary call.
2023-08-10 12:35:40 +02:00
Emil Ernerfeldt faf31365d2
Add `emath::Rangef` and helpers for splitting a `Rect` (#2978)
* emath: add Rangef helper

* emath: Add Rect splitting helper

* Add helper for interpolating Pos2
2023-05-08 12:20:26 +02:00
Emil Ernerfeldt 4d357b0f02 clippy fixes from 1.69.0 2023-04-21 11:33:18 +02:00
YgorSouza 8ec9233e28
Add #![forbid(unsafe_code)] where unsafe isn't needed (#2773)
To be consistent with the use of the safety badge in the README.
2023-03-29 14:39:51 +02:00
Emil Ernerfeldt 530e9f667c format: add some blank lines where it was needed 2023-02-10 18:03:46 +01:00