Commit Graph

3111 Commits

Author SHA1 Message Date
YgorSouza c4f16af721
Prevent plot from resetting one axis while zooming/dragging the other (#4252)
* Closes <https://github.com/emilk/egui/issues/4251>
2024-03-28 10:43:28 +01:00
Emil Ernerfeldt 3dba73e63e
Improve the UI for changing the egui theme (#4257)
I added a new demo - a `Frame` editor:

![frame-editor](https://github.com/emilk/egui/assets/1148717/d0bec169-c211-45a3-9f53-5059fb8fc224)

This whole menu is now just a a bit nicer to use:
<img width="406" alt="Screenshot 2024-03-28 at 09 49 16"
src="https://github.com/emilk/egui/assets/1148717/32d12067-7cf0-4312-aa12-42909a5ed5ac">
2024-03-28 10:09:28 +01:00
Emil Ernerfeldt e183655aac
Don't apply a clip rect to the contents of an `Area` or `Window` (#4258)
The edges were rather arbitrarily chosen anyway, and I'm not sure who it
was supposed to help.
2024-03-28 10:09:21 +01:00
Emil Ernerfeldt 58a27882b0
Fix touch-and-hold to open context menu (#4249)
This was broken in cases where the ui wasn't waking up, i.e. when
nothing else was happening.
2024-03-27 16:39:06 +01:00
Nicolas PASCAL 9fa8aa7e30
`Plot::Items:allow_hover` give possibility to masked the interaction on hovered item (#2558)
This is particularly interesting if you want to authorize a single hover
tooltip on an item in the event of an interaction.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-03-27 16:35:36 +01:00
lomekragow 570e7cf71b
Add `register_native_texture` in `eframe::Frame` (#4246)
<!--
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/4243

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-03-27 16:35:25 +01:00
Emil Ernerfeldt 3c029a45ac
Fix `Context::repaint_causes` returning no causes (#4248)
It would return the causes for repainting again collected this frame,
instead of the cause for repainting the current frame.

* Part of https://github.com/emilk/egui/issues/3931
2024-03-27 16:14:22 +01:00
Emil Ernerfeldt bc5ce77819
Fix `InputState::any_touches` and add `InputState::has_touch_screen` (#4247)
Add `InputState::has_touch_screen` to query if there ever has been any
touches (which is what `any_touches` used to return).
2024-03-27 16:14:17 +01:00
Emil Ernerfeldt a15e6c2122
Prevent visual glitch when shadow blur width is very high (#4245)
* Closes https://github.com/emilk/egui/issues/4238

The comment in the code explains it well, but the short of it is this:
we can't handle a shadow blur width larger than the shadow rectangle, so
we need to clamp the blur. This means smaller things will cast shadows
with a smaller blur width, but that's better than having visual
glitches.
2024-03-27 11:22:38 +01:00
Emil Ernerfeldt 947b5813d7
Fix visual glitch on the right side of highly rounded rectangles (#4244)
* Part of https://github.com/emilk/egui/issues/4238

When one side of a rectangle is all rounding we need to take care not to
produce duplicated vertices in the rectangle path generator.

The old code only handled three sides, but forgot the last side (the
right side).
The new code handles the right side, and also handles the other sides
more robustly (with a floating point eps) and efficiently (in a single
pass).

The glitch was most notable in shadows with a high blur width.

Examples of the glitch:

<img width="203" alt="Screenshot 2024-03-26 at 20 15 38"
src="https://github.com/emilk/egui/assets/1148717/dc1c0a06-35f0-4fda-a011-0e37d18454a0">

<img width="220" alt="Screenshot 2024-03-27 at 09 48 48"
src="https://github.com/emilk/egui/assets/1148717/c278b28e-c3f9-4c82-ba20-0480621efd2f">

<img width="33" alt="Screenshot 2024-03-27 at 09 49 21"
src="https://github.com/emilk/egui/assets/1148717/379ddf77-6590-4444-9c2e-67ab1e071f0f">
2024-03-27 10:13:49 +01:00
Emil Ernerfeldt 4d4cb3d20d Release 0.27.0 - Nicer menus and new hit test logic 2024-03-26 17:13:57 +01:00
Emil Ernerfeldt f8d7d0ebaa
Enforce writing username in TODO comments (#4235) 2024-03-26 11:48:24 +01:00
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