<!--
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.
* Unless this is a trivial change, add a line to the relevant
`CHANGELOG.md` under "Unreleased".
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./sh/check.sh`.
* When you have addressed a PR comment, mark it as resolved.
Please be patient! I will review you PR, but my time is limited!
-->
- Added methods to zoom the plot programmatically, to match the
previously added `translate_bounds()`.
- Added an example of how this method can be used to customize the plot
navigation.
Closes#1164.
Compiled changelog below:
- On X11, fix Xft.dpi reload during runtime.
- On X11, fix window minimize.
- On Web, fix context menu not being disabled by
with_prevent_default(true).
- On Wayland, fix WindowEvent::Destroyed not being delivered after
destroying window.
- Fix EventLoopExtRunOnDemand::run_on_demand not working for consequent
invocation
- On macOS, remove spurious error logging when handling Fn.
- On X11, fix an issue where floating point data from the server is
- misinterpreted during a drag and drop operation.
- On X11, fix a bug where focusing the window would panic.
- On macOS, fix refresh_rate_millihertz.
- On Wayland, disable Client Side Decorations when wl_subcompositor is
not supported.
- On X11, fix Xft.dpi detection from Xresources.
- On Windows, fix consecutive calls to
window.set_fullscreen(Some(Fullscreen::Borderless(None))) resulting in
losing previous window state when eventually exiting fullscreen using
window.set_fullscreen(None).
- On Wayland, fix resize being sent on focus change.
- On Windows, fix set_ime_cursor_area.
Update `resvg` from v0.28 to v0.37.
Remove related, unnecessary entries from `deny.toml`.
⚠ In example `images` ferris is scaled differently, but I guess that now
it scales in expected way (takes all available space; before this PR it
takes up to space that, was available at first render- it does not
upscale).
This PR is minimal adaptation to new `resvg` api and small related
simplification, however it should be considered to update loaders
(currently if svg image initially was small and was scaled up it will be
blurred, see https://github.com/emilk/egui/issues/3501). As svg image
now scales over render size, problem will be more often seen now.
(currently `SvgLoader` theoretically should rerender for different sizes
(but I guess it will result in memory leak in that case), but refreshing
is stopped earlier in `DefaultTextureLoader`).
I have initial version of loaders update, that will fix issue with svg
scaling (and also enable e.g. reloading image if file has been changed),
I will submit these changes in separate PR once this one is merged.
Closes <https://github.com/emilk/egui/issues/3652>.
We were using [`tts`](https://github.com/ndarilek/tts-rs) for the
web-only screen reader. This was overkill, to say the least. It is now
replaced with ten lines of `web-sys` calls.
* Closes https://github.com/emilk/egui/issues/3602
You can now zoom any egui app by pressing Cmd+Plus, Cmd+Minus or Cmd+0,
just like in a browser. This will change the current `zoom_factor`
(default 1.0) which is persisted in the egui memory, and is the same for
all viewports.
You can turn off the keyboard shortcuts with `ctx.options_mut(|o|
o.zoom_with_keyboard = false);`
`zoom_factor` can also be explicitly read/written with
`ctx.zoom_factor()` and `ctx.set_zoom_factor()`.
This redefines `pixels_per_point` as `zoom_factor *
native_pixels_per_point`, where `native_pixels_per_point` is whatever is
the native scale factor for the monitor that the current viewport is in.
This adds some complexity to the interaction with winit, since we need
to know the current `zoom_factor` in a lot of places, because all egui
IO is done in ui points. I'm pretty sure this PR fixes a bunch of subtle
bugs though that used to be in this code.
`egui::gui_zoom::zoom_with_keyboard_shortcuts` is now gone, and is no
longer needed, as this is now the default behavior.
`Context::set_pixels_per_point` is still there, but it is recommended
you use `Context::set_zoom_factor` instead.
* Closes#1044
---
(new PR description written by @emilk)
## Overview
This PR introduces the concept of `Viewports`, which on the native
eframe backend corresponds to native OS windows.
You can spawn a new viewport using `Context::show_viewport` and
`Cotext::show_viewport_immediate`.
These needs to be called every frame the viewport should be visible.
This is implemented by the native `eframe` backend, but not the web one.
## Viewport classes
The viewports form a tree of parent-child relationships.
There are different classes of viewports.
### Root vieport
The root viewport is the original viewport, and cannot be closed without
closing the application.
### Deferred viewports
These are created with `Context::show_viewport`.
Deferred viewports take a closure that is called by the integration at a
later time, perhaps multiple times.
Deferred viewports are repainted independenantly of the parent viewport.
This means communication with them need to done via channels, or
`Arc/Mutex`.
This is the most performant type of child viewport, though a bit more
cumbersome to work with compared to immediate viewports.
### Immediate viewports
These are created with `Context::show_viewport_immediate`.
Immediate viewports take a `FnOnce` closure, similar to other egui
functions, and is called immediately. This makes communication with them
much simpler than with deferred viewports, but this simplicity comes at
a cost: whenever tha parent viewports needs to be repainted, so will the
child viewport, and vice versa. This means that if you have `N`
viewports you are poentially doing `N` times as much CPU work. However,
if all your viewports are showing animations, and thus are repainting
constantly anyway, this doesn't matter.
In short: immediate viewports are simpler to use, but can waste a lot of
CPU time.
### Embedded viewports
These are not real, independenant viewports, but is a fallback mode for
when the integration does not support real viewports. In your callback
is called with `ViewportClass::Embedded` it means you need to create an
`egui::Window` to wrap your ui in, which will then be embedded in the
parent viewport, unable to escape it.
## Using the viewports
Only one viewport is active at any one time, identified wth
`Context::viewport_id`.
You can send commands to other viewports using
`Context::send_viewport_command_to`.
There is an example in
<https://github.com/emilk/egui/tree/master/examples/multiple_viewports/src/main.rs>.
## For integrations
There are several changes relevant to integrations.
* There is a [`crate::RawInput::viewport`] with information about the
current viewport.
* The repaint callback set by `Context::set_request_repaint_callback`
now points to which viewport should be repainted.
* `Context::run` now returns a list of viewports in `FullOutput` which
should result in their own independant windows
* There is a new `Context::set_immediate_viewport_renderer` for setting
up the immediate viewport integration
* If you support viewports, you need to call
`Context::set_embed_viewports(false)`, or all new viewports will be
embedded (the default behavior).
## Future work
* Make it easy to wrap child viewports in the same chrome as
`egui::Window`
* Automatically show embedded viewports using `egui::Window`
* Use the new `ViewportBuilder` in `eframe::NativeOptions`
* Automatically position new viewport windows (they currently cover each
other)
* Add a `Context` method for listing all existing viewports
Find more at https://github.com/emilk/egui/issues/3556
---
<details>
<summary>
Outdated PR description by @konkitoman
</summary>
## Inspiration
- Godot because the app always work desktop or single_window because of
embedding
- Dear ImGui viewport system
## What is a Viewport
A Viewport is a egui isolated component!
Can be used by the egui integration to create native windows!
When you create a Viewport is possible that the backend do not supports
that!
So you need to check if the Viewport was created or you are in the
normal egui context!
This is how you can do that:
```rust
if ctx.viewport_id() != ctx.parent_viewport_id() {
// In here you add the code for the viewport context, like
egui::CentralPanel::default().show(ctx, |ui|{
ui.label("This is in a native window!");
});
}else{
// In here you add the code for when viewport cannot be created!
// You cannot use CentralPanel in here because you will override the app CentralPanel
egui::Window::new("Virtual Viewport").show(ctx, |ui|{
ui.label("This is without a native window!\nThis is in a embedded viewport");
});
}
```
This PR do not support for drag and drop between Viewports!
After this PR is accepted i will begin work to intregrate the Viewport
system in `egui::Window`!
The `egui::Window` i want to behave the same on desktop and web
The `egui::Window` will be like Godot Window
## Changes and new
These are only public structs and functions!
<details>
<summary>
## New
</summary>
- `egui::ViewportId`
- `egui::ViewportBuilder`
This is like winit WindowBuilder
- `egui::ViewportCommand`
With this you can set any winit property on a viewport, when is a native
window!
- `egui::Context::new`
- `egui::Context::create_viewport`
- `egui::Context::create_viewport_sync`
- `egui::Context::viewport_id`
- `egui::Context::parent_viewport_id`
- `egui::Context::viewport_id_pair`
- `egui::Context::set_render_sync_callback`
- `egui::Context::is_desktop`
- `egui::Context::force_embedding`
- `egui::Context::set_force_embedding`
- `egui::Context::viewport_command`
- `egui::Context::send_viewport_command_to`
- `egui::Context::input_for`
- `egui::Context::input_mut_for`
- `egui::Context::frame_nr_for`
- `egui::Context::request_repaint_for`
- `egui::Context::request_repaint_after_for`
- `egui::Context::requested_repaint_last_frame`
- `egui::Context::requested_repaint_last_frame_for`
- `egui::Context::requested_repaint`
- `egui::Context::requested_repaint_for`
- `egui::Context::inner_rect`
- `egui::Context::outer_rect`
- `egui::InputState::inner_rect`
- `egui::InputState::outer_rect`
- `egui::WindowEvent`
</details>
<details>
<summary>
## Changes
</summary>
- `egui::Context::run`
Now needs the viewport that we want to render!
- `egui::Context::begin_frame`
Now needs the viewport that we want to render!
- `egui::Context::tessellate`
Now needs the viewport that we want to render!
- `egui::FullOutput`
```diff
- repaint_after
+ viewports
+ viewport_commands
```
- `egui::RawInput`
```diff
+ inner_rect
+ outer_rect
```
- `egui::Event`
```diff
+ WindowEvent
```
</details>
### Async Viewport
Async means that is independent from other viewports!
Is created by `egui::Context::create_viewport`
To be used you will need to wrap your state in `Arc<RwLock<T>>`
Look at viewports example to understand how to use it!
### Sync Viewport
Sync means that is dependent on his parent!
Is created by `egui::Context::create_viewport_sync`
This will pause the parent then render itself the resumes his parent!
#### ⚠️ This currently will make the fps/2 for every sync
viewport
### Common
#### ⚠️ Attention
You will need to do this when you render your content
```rust
ctx.create_viewport(ViewportBuilder::new("Simple Viewport"), | ctx | {
let content = |ui: &mut egui::Ui|{
ui.label("Content");
};
// This will make the content a popup if cannot create a native window
if ctx.viewport_id() != ctx.parent_viewport_id() {
egui::CentralPanel::default().show(ctx, content);
} else {
egui::Area::new("Simple Viewport").show(ctx, |ui| {
egui::Frame::popup(ui.style()).show(ui, content);
});
};
});
````
## What you need to know as egui user
### If you are using eframe
You don't need to change anything!
### If you have a manual implementation
Now `egui::run` or `egui::begin` and `egui::tessellate` will need the
current viewport id!
You cannot create a `ViewportId` only `ViewportId::MAIN`
If you make a single window app you will set the viewport id to be
`egui::ViewportId::MAIN` or see the `examples/pure_glow`
If you want to have multiples window support look at `crates/eframe`
glow or wgpu implementations!
## If you want to try this
- cargo run -p viewports
## This before was wanted to change
This will probably be in feature PR's
### egui::Window
To create a native window when embedded was set to false
You can try that in viewports example before:
[78a0ae8](78a0ae879e)
### egui popups, context_menu, tooltip
To be a native window
</details>
---------
Co-authored-by: Konkitoman <konkitoman@users.noreply.github.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Co-authored-by: Pablo Sichert <mail@pablosichert.com>
Tested on M1 Mac:
* native
* webgl, firefox
* webgpu, chrome
all looking normal
Updated minor ahash version because 0.8.1 got yanked. Added some deny
exceptions for now - we'll have to update winit soon to resolve glow
related cargo deny errors (not a big issue though since we don't expect
wgpu and glow backends to be used at the same time)
Bumps [rustix](https://github.com/bytecodealliance/rustix) from 0.37.23
to 0.37.25.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="00b84d6aac"><code>00b84d6</code></a>
chore: Release rustix version 0.37.25</li>
<li><a
href="cad15a7076"><code>cad15a7</code></a>
Fixes for <code>Dir</code> on macOS, FreeBSD, and WASI.</li>
<li><a
href="df3c3a192c"><code>df3c3a1</code></a>
Merge pull request from GHSA-c827-hfw6-qwvm</li>
<li><a
href="b78aeff1a2"><code>b78aeff</code></a>
chore: Release rustix version 0.37.24</li>
<li><a
href="c0c3f01d7c"><code>c0c3f01</code></a>
Add GNU/Hurd support (<a
href="https://redirect.github.com/bytecodealliance/rustix/issues/852">#852</a>)</li>
<li><a
href="f416b6b27b"><code>f416b6b</code></a>
Fix the <code>test_ttyname_ok</code> test when /dev/stdin is
inaccessable. (<a
href="https://redirect.github.com/bytecodealliance/rustix/issues/821">#821</a>)</li>
<li><a
href="aee5b0954e"><code>aee5b09</code></a>
Downgrade dependencies and disable tests to compile under Rust
1.48.</li>
<li><a
href="6d42c38311"><code>6d42c38</code></a>
Disable MIPS in CI. (<a
href="https://redirect.github.com/bytecodealliance/rustix/issues/793">#793</a>)</li>
<li>See full diff in <a
href="https://github.com/bytecodealliance/rustix/compare/v0.37.23...v0.37.25">compare
view</a></li>
</ul>
</details>
<br />
[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=rustix&package-manager=cargo&previous-version=0.37.23&new-version=0.37.25)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
<details>
<summary>Dependabot commands and options</summary>
<br />
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts page](https://github.com/emilk/egui/network/alerts).
</details>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Revert ttf-parser from 0.19.2 to 0.19.1
0.19.2's doesn't work with wasm in debug builds
* Update to poll-promise 0.3.0
* Publish new web demo
* Fix typo in changelog
* Explain why image_viewer is not part of the official web demo app
* Fix typos
* Make rfd native-only dependency
* Update images in README.md
* Add ferris image to hello_world example
* Clean up and improve README.md, with top-level link to Rerun
* Move sections around
* Add syntax highlighing feature to egui_extras
Enable "syntect" feature for great syntax highlighting of any language.
If not a simple fallback is used that works fine for C++, Rust, Python
* Check --no-default-features of egui_extras on CI
* spelling
* Fix building egui_extras without additional features
* rework loading around `Arc<Loaders>`
* use `Bytes` instead of splitting api
* remove unwraps in `texture_handle`
* make `FileLoader` optional under `file` feature
* hide http load error stack trace from UI
* implement image fit
* support more image sources
* center spinner if we know size ahead of time
* allocate final size for spinner
* improve image format guessing
* remove `ui.image`, `Image`, add `RawImage`
* deprecate `RetainedImage`
* `image2` -> `image`
* add viewer example
* update `examples/image` + remove `svg` and `download_image` exapmles
* fix lints and tests
* fix doc link
* add image controls to `images` example
* add more `From` str-like types
* add api to forget all images
* fix max size
* do not scale original size unless necessary
* fix doc link
* add more docs for `Image` and `RawImage`
* make paint_at `pub`
* update `ImageButton` to use new `Image` API
* fix double rendering
* `SizeHint::Original` -> `Scale` + remove `Option` wrapper
* Update crates/egui/src/load.rs
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* remove special `None` value for `forget`
* Update crates/egui/src/load.rs
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* add more examples to `ui.image` + add `include_image` macro
* Update crates/egui/src/ui.rs
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* update `menu_image_button` to use `ImageSource`
* `OrderedFloat::get` -> `into_inner`
* derive `Eq` on `SizedTexture`
* add `id` to loaders + `is_installed` check
* move `images` to demo + simplify `images` example
* log trace when installing loaders
* fix lint
* fix doc link
* add more documentation
* more `egui_extras::loaders` docs
* Update examples/images/src/main.rs
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* update `images` example screenshots + readme
* remove unused `rfd` from `images` example
* Update crates/egui_extras/src/loaders/ehttp_loader.rs
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* add `must_use` on `Image` and `RawImage`
* document `loaders::install` multiple call safety
* Update crates/egui_extras/Cargo.toml
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* reshuffle `is_loader_installed`
* make `include_image` produce `ImageSource` + update docs
* update `include_image` docs
* remove `None` mentions from loader `forget`
* inline `From` texture id + size for `SizedTexture`
* add warning about statically known path
* change image load error + use in image button
* add `.size()` to `Image`
* Update crates/egui_demo_app/Cargo.toml
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* add explanations to image viewer ui
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* add types from proposal
* add load methods on `egui::Context`
* implement loaders from proposal in `egui_extras`
* impl `From<Vec2>` for `SizeHint`
* re-export `SizeHint` from `egui` root
* rework `svg` example to use new managed `Image`
* split loaders into separate files + add logging
* add `log_trace`
* clean up `RetainedImage` from `svg` example
* refactor ehttp loader response to bytes mapping
* remove spammy trace
* load images even without extension
* fix lints
* remove unused imports
* use `Image2` in `download_image`
* use `visuals.error_fg_color` in `Image2` error state
* update lockfile
* use `Arc<ColorImage>` in `ImageData` + add `forget` API
* add `ui.image2`
* add byte size query api
* use iterators to sum loader byte sizes
* add static image loading
* use static image in `svg` example
* small refactor of `Image2::ui` texture loading code
* add `ImageFit` to size images properly
* remove println calls
* add bad image load to `download_image` example
* add loader file extension support tests
* fix lint errors in `loaders`
* remove unused `poll-promise` dependency
* add some docs to `Image2`
* add some docs to `egui_extras::loaders::install`
* explain `loaders::install` in examples
* fix lint
* upgrade `ehttp` to `0.3` for some crates
* Remove some unused dependencies
* Remove unnecessary context clone
* Turn on the `log` create feature of egui_extras in all examples
* rename `forget` and document it
* derive `Debug` on `SizeHint`
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* round when converting SizeHint from vec2
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* add `load` module docs
* docstring `add_loader` methods
* expose + document `load_include_bytes`
* cache texture handles in `DefaultTextureLoader`
* add `image2` doctest + further document `Image2`
* use `Default` for default `Image2` options
* update `image2` doc comment
* mention immediate-mode safety
* more fit calculation into inherent impl
* add hover text on spinner
* add `all-loaders` feature
* clarify `egui_extras::loaders::install` behavior
* explain how to enable image formats
* properly format `uri`
* use `thread::Builder` instead of `spawn`
* use eq op instead of `matches`
* inline `From<Arc<ColorImage>>` for `ImageData`
* allow non-`'static` bytes + `forget` in `DefaultTextureLoader`
* sort features
* change `ehttp` feature to `http`
* update `Image2` docs
* refactor loader cache type
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* Silence a few clippy warnings
* Use named threads
* Remove some deprecated functions
* Document Context and Ui fully
* Use `parking_lot::Mutex` in `eframe`
* Expand clippy.toml files
* build fix
* Bump `wgpu` to 0.17.0
This required bumping wasm-bindgen to 0.2.87
* cargo deny exception for `foreign-types`
* sort deny.toml
* Add fragile-send-sync-non-atomic-wasm feature to wgpu
* cargo deny: ignore children of foreign-types
---------
Co-authored-by: Andreas Reich <r_andreas2@web.de>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* implement save_plot
* fix for check.sh
* clippy
* add save_plot to Cargo.lock
* adapted for PR #2676 (removes unsafe code)
* add some comments
* implemented the comments from emilk
* update comments in code
* rustfmt
* remove picked_path
* add more comments
* removed unused import
* use `inner.response.rect` as the plot position
* remove plot_location from MyApp members
* sort entries
* Update examples/save_plot/src/main.rs
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* use env_logger instead of tracing subscriber
* use env_logger instead of tracing subscriber and combine if let
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* Expose raw window and display handles in eframe
* Ensure that no one implements `Clone` in the future
* Cleanup
---------
Co-authored-by: Matti Virkkunen <mvirkkunen@gmail.com>