Commit Graph

3099 Commits

Author SHA1 Message Date
Emil Ernerfeldt 8a10f81ca0 Forbid use of `std::time::Instant` on wasm 2024-03-26 11:15:08 +01:00
Emil Ernerfeldt a03604fce0 Add breaking change to changelog 2024-03-26 11:13:56 +01:00
Emil Ernerfeldt 884cf6de3d Add some tests for `Rect` 2024-03-26 11:13:04 +01:00
Emil Ernerfeldt 8a880d6d0f
Add `Area::sense` and improve hit-testing of buttons in menus (#4234)
Previously, putting the cursor in the gap between two menu buttons would
not hover any of the buttons, but the click-sensitive menu itself. Now
the menu is no longer click-sensitive.
2024-03-26 11:12:49 +01:00
Emil Ernerfeldt 9cfaf8b961
Better align menus with the button that opened them (#4233)
<img width="530" alt="Screenshot 2024-03-26 at 10 42 46"
src="https://github.com/emilk/egui/assets/1148717/4891047d-42a1-45b6-9363-c6ac93cefc8d">
<img width="268" alt="Screenshot 2024-03-26 at 10 42 57"
src="https://github.com/emilk/egui/assets/1148717/98865f38-10cc-4cbe-a80b-a767415e1469">
2024-03-26 10:54:15 +01:00
Emil Ernerfeldt c530504a04
CSS-like shadows with offset, spread, and blur (#4232)
This makes `epaint::Shadow` more like CSS's box-shadow, adding `offset`
and replacing `extrusion` with `blur` and `spread`.

* Closes https://github.com/emilk/egui/pull/3047

The offsets make for nice drop-shadow effects.

Old shadows:
<img width="1447" alt="old-shadows"
src="https://github.com/emilk/egui/assets/1148717/8a30f7b9-fb9d-49ea-9a2f-9367a60c448a">

New shadows:
<img width="1447" alt="new-shadows-full"
src="https://github.com/emilk/egui/assets/1148717/28cc9c1e-b0de-4c5b-a705-22e52c556584">
2024-03-26 10:37:12 +01:00
Emil Ernerfeldt 1634554032
Add `Margin` to `epaint` (#4231)
Moved from `egui`
2024-03-26 09:05:29 +01:00
Emil Ernerfeldt cf8c37c71e
Add some distance between parent menu and submenu (#4230)
Before:
<img width="502" alt="Screenshot 2024-03-26 at 08 37 16"
src="https://github.com/emilk/egui/assets/1148717/ca072cae-807a-4830-a59a-11ff822d0a7b">


After:
<img width="532" alt="Screenshot 2024-03-26 at 08 36 12"
src="https://github.com/emilk/egui/assets/1148717/f42d79f4-ff05-457f-9fab-67574839f025">
2024-03-26 08:43:38 +01:00
/lemon.sh ab6c3f9161
Add an API for customizing the return key in TextEdit (#4085)
This PR allows customizing the return key in the TextEdit widget. Right
now, it's hard-coded to the Enter key, which is problematic in cases
when you want to use the Enter key for something else, and insert the
newline in a different way instead.
2024-03-25 13:18:08 +01:00
Colin Kinloch 287a550b90
egui demo: Add drop down to resize the window (#4197)
An alternative to the "Phone Size" button useful for testing
`ViewportCommand::InnerSize`.

I created this to make it easy to debug
https://github.com/emilk/egui/issues/4196 there are more details there.
2024-03-25 13:11:39 +01:00
rustbasic d410bc5b9a
Fix `example/test_viewports` title change (#4221)
fix : `example/test_viewports` title Change accurately

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-03-25 12:40:49 +01:00
Emil Ernerfeldt 7f8aae4103
Don't show URLs when hovering hyperlinks (#4218)
Can be changed with `Style::url_in_tooltip`
2024-03-25 09:00:12 +01:00
Emil Ernerfeldt 20b0637d42 Some clippy fixes 2024-03-22 12:33:35 +01:00
Emil Ernerfeldt b7ec3fa1e3 Fix crash in `wants_keyboard_input` 2024-03-22 12:33:17 +01:00
rustbasic 21d045e8ef
Fix: IME bug when typing Chinese characters (#4210)
* Closes #4209 

Fix: IME bug when typing Chinese characters
2024-03-22 12:27:08 +01:00
rustbasic 769199648d
Prevent egui::Window from becoming larger than Viewport (#4199)
* Closes #3987  

* Closes #3988

There is a need to prevent egui::Window from becoming larger than the
Viewport.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-03-21 13:47:25 +01:00
dwuertz 0299663cdd
Expose `PlotGeometry` in public API (#4193)
Expose `egui_plot::items::values::PlotGeometry` in public API so that
`PlotItem`, which is already public, can actually be implemented by
applications. Fixes #3464.

---------

Co-authored-by: Dominique Würtz <dom@blaukraut.info>
2024-03-21 12:27:18 +01:00
Zeenobit e4f209ec50
Expose state override for `HeaderResponse` (#4200)
I'm trying to create some custom collapsing headers that add additional
buttons inside the header itself. Because of this, I load the
`CollapsingState` in my special widget manually. But because
`HeaderResponse` owns the `Ui` and the `CollapsingState`, there is no
way for me to open/close the collapsing header based on response of the
inner widget.

Initially, I considered just exposing `state` member of
`HeaderResponse`, but that exposes too much of the API at the wrong
time, in my opinion.

So instead I found it'd be safer to just expose the open/close API to
the response itself, and that's what this PR does.
2024-03-21 12:13:32 +01:00
rustbasic 7d3d7ce0ca
typos : intersects_ray() (#4201)
typos : intersects_ray()
2024-03-21 12:10:02 +01:00
Seth Rider 2c9c5f0dea
Add x11 window type settings to viewport builder (#4175)
Not sure about the api, currently I've mapped the whole XWindowType
enum, but maybe there's something more sensible to do?

* Closes <https://github.com/emilk/egui/issues/4150>

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-03-21 12:07:20 +01:00
hiyosilver 365d035b20
Added ability to disable highlighting of weekend days in DatePickerPopup. (#4151)
I added a handfull of lines to allow for the red highlight on weekends
in `DatePickerPopup` to be disabled.

I tried to follow the rules, but I've never done any kind of PR before,
and I'm also not sure if this is at all the kind of thing that is wanted
at the moment. If it is not, I'm happy to just have this removed. Just a
tiny little addition I would find useful.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-03-21 11:09:19 +01:00
rustbasic 861a1b6225
Adjustable Slider rail height (#4092)
Adjustable Slider rail height 


![explain20240312-2](https://github.com/emilk/egui/assets/127506429/d5edfe10-8191-44ed-8567-d9d2127ce4b8)

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-03-21 10:48:40 +01:00
zaaarf 8ca270e78e
Option to change date picker format (#4180)
Simply allows date picker buttons to show other formats than `%Y-%m-%d`,
while keeping that as default to not break compatibility.

I'm not that experienced with Rust, so I was unsure whether you'd prefer
`&'a str` rather than a `String`, let me know if I should change that.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-03-20 13:54:14 +01:00
Eris bce257adb3
`epaint`: Add `EllipseShape` (#4122)
Adds an Ellipse shape draw-able with the Painter, brings egui closer to
the SVG Specification.

I've done some optimization towards using less vertices and doing less
calculations.

~~Currently the vertices are evenly distributed.
It's possible this could be optimized further taking into account the
gradient and increasing the concentration of vertices where the change
in gradient is larger.~~


![EllipseTall](https://github.com/emilk/egui/assets/50041841/b105230c-ce68-49c1-b162-d1f066bf9d6a)

![EllipseWide](https://github.com/emilk/egui/assets/50041841/6f9106d2-75cb-4f2a-b0c2-039b3aadec86)
2024-03-20 13:23:21 +01:00
ming08108 8d47ab8bb9
Don't clear modifier state on focus change (#4157)
I believe that the underlying issue that caused the stuck modifier keys
was resolved in the 0.29 winit keyboard refactor.

This probably needs to tested on other desktop platforms however since I
am only able to test this on windows 11.

* Closes <https://github.com/emilk/egui/issues/2332>
2024-03-20 13:06:45 +01:00
rustbasic 1b34289608
Fix bug in `Context::parent_viewport_id` (#4190)
* Closes #4084 

Fix : Display parent viewport id Issues
2024-03-20 12:55:44 +01:00
Emil Ernerfeldt d449cb1d48
On touch screens, press-and-hold equals a secondary click (#4195)
* Closes https://github.com/emilk/egui/issues/3444
* Closes https://github.com/emilk/egui/issues/865

On a touch screen, if you press down on a widget and hold for 0.6
seconds (`MAX_CLICK_DURATION`), it will now trigger a secondary click,
i.e. `Response::secondary_clicked` will be `true`. This means you can
now open context menus on touch screens.
2024-03-20 11:49:17 +01:00
Emil Ernerfeldt cd1ed73388
Change the definition of `clicked_by` (#4192)
This is a refactor on the way to add support for opening context menus
on touch screens via press-and-hold.

This PR changes what `InputState::button_clicked` does (it was ver badly
named before), and also changes `Response::clicked_by` to no longer be
true if clicking with keyboard (i.e. a widget has keyboard focus and the
user presses Space or Enter).
2024-03-19 18:16:04 +01:00
Emil Ernerfeldt 820fa3c43a
`Location::query_map`: support repeated key (#4183)
This adds support for parsing e.g. `?foo=hello&foo=world`, returning
both "hello" and "world" in `Location::query_map`
2024-03-17 17:50:33 +01:00
Antoine Beyeler 3258cd2a7f
Fix two `ScrollArea` bugs: leaking scroll target and broken animation to target offset (#4174)
This PR fixes two issues related to `ScrollArea`.

1) When a `ScrollArea` would have `drag_to_scroll` set to `false` (e.g.
because some custom logic is at play or some other reason), it would not
animate to the `target_offset`, effectively making
`Response::scroll_to_me()` ineffective.
2) Single-direction `ScrollArea`s would leak the `scroll_target`'s other
direction. In certain specific circumstances (e.g. an horizontal area
nested in a vertical one, or inversely), this _could_ work as intended,
but in many other cases it could cause unwanted effects. With this PR,
both `scroll_target` directions are consumed by nearest enclosing
`ScrollArea`, regardless of the actually enabled scroll axes.
2024-03-17 17:12:41 +01:00
Emil Ernerfeldt bf7ffb982a
Fix bug parsing url query with escaped & or = (#4172)
I have tested this manually:

<img width="727" alt="Screenshot 2024-03-14 at 19 38 34"
src="https://github.com/emilk/egui/assets/1148717/fa1f6da4-d9e3-4f08-9812-1d61479dfd52">
2024-03-15 06:43:27 +01:00
Jan Procházka c5eaba43cd
Fix crash on `request_animation_frame` when destroying web runner (#4169)
Previously, any frames in flight (`requestAnimationFrame`) on web were
not being cancelled (`cancelAnimationFrame`) when `WebRunner::destroy`
was called. If a user called `destroy`, then immediately removed the
canvas from the DOM, eframe could panic with a "failed to find (canvas)
element by id" error message.

This PR changes two things:
- The canvas element is directly referenced everywhere it's needed
instead of being looked up by `canvas_id`[^1]
- The RAF handle is stored in `WebRunner` and `cancelAnimationFrame` is
called on it inside of `WebRunner::destroy`[^2]

[^1]: The WebGL/WGPU backends were already holding onto the canvas (and
associated GPU context), so the change is just converting all the
`get_element_by_id` lookups to retrieve the canvas from the web runner
handle.

[^2]: There is only ever one frame in flight, so we store it directly as
a scalar field.
2024-03-14 10:26:34 +01:00
Emil Ernerfeldt 00e8ce6d7e Reduce log-level of processing ViewportCommands 2024-03-14 10:18:07 +01:00
lomekragow 47fbce665a
Add `get_proc_address` in CreationContext (#4145)
<!--
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 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/4144>
2024-03-13 13:07:27 +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
rustbasic f019032033
TextEdit: fix crash when hitting SHIFT + TAB around non-ASCII text (#3984)
* Closes #3846 
* Closes #3878

Dear emilk.

Leaving aside other function,
I think this is all you need to fix to patch the panic that occurs when
Shift + TAB.

Thank you, emilk.
2024-03-12 11:21:33 +01:00
Vincent Alsteen c87bcc4bcc
Remove unnecessary allocation in `RepaintCause::new` (#4146)
Hi!

I'm using egui for the UI of a VST3/Clap plugin, and this kind of
environment is rather picky on performance. I use
[assert_no_alloc](https://crates.io/crates/assert_no_alloc) to make sure
the audio thread is never allocating. The audio thread may request a
repaint of the GUI tho, and this is where a saw that it may allocate
when tracing the repaint reason.

Turns out it's not necessary, `Location::caller` is `'static`, so using
a `&'static str` instead of a `String` in `RepaintCause::file` will just
work, so this PR just does that.
2024-03-12 11:15:13 +01:00
ming08108 efc0a6385c
Update kb modifiers from web mouse events (#4156)
Update modifier state from web mouse events. This allows modifiers to be
correctly updated when the window is not in focus but the mouse is still
moving over the window.
2024-03-12 11:14:40 +01:00
CrazyCraftix 4a330de53d
Fix scaling of rounded corners for rect shape (#4152) (#4161)
When scaling an `egui::Shape` of variant `Rect` using the new
`transform` function, corner rounding isn't taken into account.

The fix is to multiply the rounding by the scaling factor.

* Closes <https://github.com/emilk/egui/issues/4152>
2024-03-12 11:14:24 +01:00
Emil Ernerfeldt d0a6bbf2b8
Fix style of disabled widgets (#4163)
* Broke in https://github.com/emilk/egui/pull/4026/files

The `Response::sense` for `enabled: false` widgets was wrong, leading to
the wrong widget style.
2024-03-12 11:14:12 +01:00
Varphone Wong 827fdefd83
eframe: Added `App::raw_input_hook` allows for the manipulation or filtering of raw input events (#4008)
# What's New

* eframe: Added `App::raw_input_hook` allows for the manipulation or
filtering of raw input events
   A filter applied to raw input before [`Self::update`]
This allows for the manipulation or filtering of input events before
they are processed by egui.
This can be used to exclude specific keyboard shortcuts, mouse events,
etc.
Additionally, it can be used to add custom keyboard or mouse events
generated by a virtual keyboard.
* examples: Added an example to demonstrates how to implement a custom
virtual keyboard.


[eframe-custom-keypad.webm](https://github.com/emilk/egui/assets/1274171/a9dc8e34-2c35-4172-b7ef-41010b794fb8)
2024-03-12 11:06:08 +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
Varphone Wong a93c6cd5d2
`egui`: Fixed the incorrect display of the Window frame with a wide border or large rounding (#4032)
Currently, the Window frame is displayed incorrectly when using a wide
border or large rounding.

* Closes #3806
* Closes #4024 
* Closes #4025 

* Screencast of egui demo app (emilk:master)


[window-frame-bug.webm](https://github.com/emilk/egui/assets/1274171/391f67fa-ae6f-445a-8c64-1bb575770127)

* Screencast of egui demo app (varphone:hotfix/window-custom-frame)


[window-frame-fixed.webm](https://github.com/emilk/egui/assets/1274171/1953124e-9f7a-4c2d-9024-5d2eece6b87c)
2024-03-08 10:32:23 +01:00
Varphone Wong 1f414c059d
`egui_extras`: Fixed handling of `file://` protocol for images (#4107)
* Remove the leading slash from the path if the target OS is Windows.

This is because Windows paths are not supposed to start with a slash.
For example, `file:///C:/path/to/file` is a valid URI, but
`/C:/path/to/file` is not a valid path.

* Use the input URI consistently as the cache key.

Currently, the cache key is inconsistently set as either the path or the
URI, while the forget key is always the URI. This inconsistency should
be resolved.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-03-08 10:24:34 +01:00
Varphone Wong 4d776fd84e
`epaint`: Added `Shape::{scale,translate}` wrappers (#4090)
The `Shape::translate` method has been replaced with `Shape::transform`,
which introduces breaking changes that could negatively impact existing
users.

This patch adds a `Shape::translate` wrapper to prevent these breaking
changes.
2024-03-08 10:07:31 +01:00
rustbasic 385daeb354
Fix IME bug where currently typed characters got copied
* Closes #3730 

Fix IME: Currently typed characters get copied when switching TextEdit
fields
2024-03-08 10:00:28 +01:00
Arnold Loubriat 76411b5d74
Add accessibility to `ProgressBar` and `Spinner` (#4139)
- Introduces `WidgetType::ProgressIndicator` and maps it to the
corresponding AccessKit role.
- A `Spinner` is now exposed as a widget indicating a progress for which
a completion state is not known.
- On the other hand, a `ProgressBar` reports a completion state and can
possibly be labeled. Note that a label is not used if not explicitly
asked by the user, as it would be redundant information. Assistive
technologies prefer the numerical value so they can, for instance, emit
beeps of which the frequency rise as the completion state increase. I
had to call `floor` on the progression as it seems all the ATs I tested
would round the value, hence reporting something different than what is
displayed on the label.
2024-03-08 09:54:21 +01:00
Antoine Beyeler a1d5145c16
Hide hover UI when showing the context menu (#4138)
This PR hides the hover UI for a given widget whenever a corresponding
context menu is opened.

Fixes:
- https://github.com/rerun-io/rerun/issues/5310
2024-03-06 16:30:20 +01:00
Cameron Taggart ca1f453c47
add webgpu feature by default for wgpu feature of eframe (#4124)
Fix #4123. Looks like it was caused by #3875.
2024-03-04 20:20:03 +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