Compare commits
66 commits
wgpu_upgra
...
master
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7215fdfb7c | ||
![]() |
e2778d9d6a | ||
![]() |
38849fe381 | ||
![]() |
df7e5bd57a | ||
![]() |
e3e781ced8 | ||
![]() |
97756bc246 | ||
![]() |
f71d79a0ff | ||
![]() |
95247daa17 | ||
![]() |
530e9f667c | ||
![]() |
409fb968d3 | ||
![]() |
1581f0229e | ||
![]() |
ae722ab0cf | ||
![]() |
1384fa3287 | ||
![]() |
83b5b81227 | ||
![]() |
63fa3aec10 | ||
![]() |
ebeb788b1f | ||
![]() |
0fc25c2680 | ||
![]() |
449dd1c23c | ||
![]() |
636a39cbe1 | ||
![]() |
be9b5a3641 | ||
![]() |
e8b9e706ca | ||
![]() |
a8d5a82a7f | ||
![]() |
c2d37571f7 | ||
![]() |
90cd178117 | ||
![]() |
7397be3401 | ||
![]() |
1edd333864 | ||
![]() |
b40dba18c6 | ||
![]() |
4721a0a680 | ||
![]() |
8d6c2580f4 | ||
![]() |
8bc88c9bf4 | ||
![]() |
b52cd2052f | ||
![]() |
b1e214bbdf | ||
![]() |
cef0c0b6d8 | ||
![]() |
d5dcc87ace | ||
![]() |
853d492724 | ||
![]() |
d15ce22e2e | ||
![]() |
628c84cbee | ||
![]() |
212656f3fc | ||
![]() |
660566c499 | ||
![]() |
430cbe541c | ||
![]() |
53f8e4049f | ||
![]() |
f0718a61d3 | ||
![]() |
fb5cb3052d | ||
![]() |
9c270448a6 | ||
![]() |
d15f4ef992 | ||
![]() |
21a59143a4 | ||
![]() |
06d753c289 | ||
![]() |
8344e88f8a | ||
![]() |
e4eaf99072 | ||
![]() |
1353a5733f | ||
![]() |
8aa07e9d43 | ||
![]() |
a6b60d5d58 | ||
![]() |
8c59888ebd | ||
![]() |
5725868b57 | ||
![]() |
8c3d8b3ba5 | ||
![]() |
312cab5355 | ||
![]() |
5444ab269a | ||
![]() |
d01e4342f0 | ||
![]() |
cc20dcb9d0 | ||
![]() |
f222ee044e | ||
![]() |
c72bdb77b5 | ||
![]() |
e7c0547e23 | ||
![]() |
fe7ff66266 | ||
![]() |
ce62b61e15 | ||
![]() |
4a0bafbeab | ||
![]() |
5b1cad2b72 |
130 changed files with 2989 additions and 2835 deletions
6
.cargo/config.toml
Normal file
6
.cargo/config.toml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# clipboard api is still unstable, so web-sys requires the below flag to be passed for copy (ctrl + c) to work
|
||||||
|
# https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html
|
||||||
|
# check status at https://developer.mozilla.org/en-US/docs/Web/API/Clipboard#browser_compatibility
|
||||||
|
# we don't use `[build]` because of rust analyzer's build cache invalidation https://github.com/emilk/eframe_template/issues/93
|
||||||
|
[target.wasm32-unknown-unknown]
|
||||||
|
rustflags = ["--cfg=web_sys_unstable_apis"]
|
72
.github/workflows/rust.yml
vendored
72
.github/workflows/rust.yml
vendored
|
@ -16,66 +16,93 @@ jobs:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
profile: default
|
profile: default
|
||||||
toolchain: 1.65.0
|
toolchain: 1.65.0
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
- name: Install packages (Linux)
|
- name: Install packages (Linux)
|
||||||
if: runner.os == 'Linux'
|
if: runner.os == 'Linux'
|
||||||
run: sudo apt-get update && sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libspeechd-dev libxkbcommon-dev libssl-dev libgtk-3-dev # libgtk-3-dev is used by rfd
|
#uses: awalsh128/cache-apt-pkgs-action@v1.2.2
|
||||||
|
#TODO(emilk) use upstream when https://github.com/awalsh128/cache-apt-pkgs-action/pull/90 is merged
|
||||||
|
uses: rerun-io/cache-apt-pkgs-action@59534850182063abf1b2c11bb3686722a12a8397
|
||||||
|
with:
|
||||||
|
packages: libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev libgtk-3-dev # libgtk-3-dev is used by rfd
|
||||||
|
version: 1.0
|
||||||
|
execute_install_scripts: true
|
||||||
|
|
||||||
- name: Set up cargo cache
|
- name: Set up cargo cache
|
||||||
uses: Swatinem/rust-cache@v2
|
uses: Swatinem/rust-cache@v2
|
||||||
|
|
||||||
- name: Rustfmt
|
- name: Rustfmt
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: fmt
|
command: fmt
|
||||||
args: --all -- --check
|
args: --all -- --check
|
||||||
|
|
||||||
- name: Install cargo-cranky
|
- name: Install cargo-cranky
|
||||||
uses: baptiste0928/cargo-install@v1
|
uses: baptiste0928/cargo-install@v1
|
||||||
with:
|
with:
|
||||||
crate: cargo-cranky
|
crate: cargo-cranky
|
||||||
- name: Check all features
|
|
||||||
|
- name: check --all-features
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: check
|
command: check
|
||||||
args: --locked --all-features
|
args: --locked --all-features --all-targets
|
||||||
- name: Check default features
|
|
||||||
|
- name: check default features
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: check
|
command: check
|
||||||
args: --locked
|
args: --locked --all-targets
|
||||||
- name: Check no default features
|
|
||||||
|
- name: check --no-default-features
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: check
|
command: check
|
||||||
args: --locked --no-default-features --lib
|
args: --locked --no-default-features --lib --all-targets
|
||||||
|
|
||||||
|
- name: check eframe --no-default-features
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: check
|
||||||
|
args: --locked --no-default-features --lib --all-targets -p eframe
|
||||||
|
|
||||||
- name: Test doc-tests
|
- name: Test doc-tests
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
args: --doc --all-features
|
args: --doc --all-features
|
||||||
|
|
||||||
- name: cargo doc --lib
|
- name: cargo doc --lib
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: doc
|
command: doc
|
||||||
args: --lib --no-deps --all-features
|
args: --lib --no-deps --all-features
|
||||||
|
|
||||||
- name: cargo doc --document-private-items
|
- name: cargo doc --document-private-items
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: doc
|
command: doc
|
||||||
args: --document-private-items --no-deps --all-features
|
args: --document-private-items --no-deps --all-features
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
args: --all-features
|
args: --all-features
|
||||||
|
|
||||||
- name: Cranky
|
- name: Cranky
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: cranky
|
command: cranky
|
||||||
args: --all-targets --all-features -- -D warnings
|
args: --all-targets --all-features -- -D warnings
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
check_wasm:
|
check_wasm:
|
||||||
name: Check wasm32 + wasm-bindgen
|
name: Check wasm32 + wasm-bindgen
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
|
@ -119,7 +146,7 @@ jobs:
|
||||||
- name: wasm-bindgen
|
- name: wasm-bindgen
|
||||||
uses: jetli/wasm-bindgen-action@v0.1.0
|
uses: jetli/wasm-bindgen-action@v0.1.0
|
||||||
with:
|
with:
|
||||||
version: "0.2.83"
|
version: "0.2.84"
|
||||||
|
|
||||||
- run: ./sh/wasm_bindgen_check.sh --skip-setup
|
- run: ./sh/wasm_bindgen_check.sh --skip-setup
|
||||||
|
|
||||||
|
@ -129,6 +156,8 @@ jobs:
|
||||||
command: cranky
|
command: cranky
|
||||||
args: --target wasm32-unknown-unknown --all-features -p egui_demo_app --lib -- -D warnings
|
args: --target wasm32-unknown-unknown --all-features -p egui_demo_app --lib -- -D warnings
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
cargo-deny:
|
cargo-deny:
|
||||||
name: cargo deny
|
name: cargo deny
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
|
@ -138,18 +167,45 @@ jobs:
|
||||||
with:
|
with:
|
||||||
rust-version: "1.65.0"
|
rust-version: "1.65.0"
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
android:
|
android:
|
||||||
name: android
|
name: android
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
profile: minimal
|
profile: minimal
|
||||||
toolchain: 1.65.0
|
toolchain: 1.65.0
|
||||||
target: aarch64-linux-android
|
target: aarch64-linux-android
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
- name: Set up cargo cache
|
- name: Set up cargo cache
|
||||||
uses: Swatinem/rust-cache@v2
|
uses: Swatinem/rust-cache@v2
|
||||||
|
|
||||||
- run: cargo check --features wgpu --target aarch64-linux-android
|
- run: cargo check --features wgpu --target aarch64-linux-android
|
||||||
working-directory: crates/eframe
|
working-directory: crates/eframe
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
windows:
|
||||||
|
name: Check Windows
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: 1.65.0
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: Set up cargo cache
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
|
||||||
|
- name: Check
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: check
|
||||||
|
args: --all-targets --all-features
|
||||||
|
|
14
CHANGELOG.md
14
CHANGELOG.md
|
@ -5,6 +5,9 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG
|
||||||
|
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
|
||||||
|
## 0.21.0 - 2023-02-08 - Deadlock fix and style customizability
|
||||||
* ⚠️ BREAKING: `egui::Context` now use closures for locking ([#2625](https://github.com/emilk/egui/pull/2625)):
|
* ⚠️ BREAKING: `egui::Context` now use closures for locking ([#2625](https://github.com/emilk/egui/pull/2625)):
|
||||||
* `ctx.input().key_pressed(Key::A)` -> `ctx.input(|i| i.key_pressed(Key::A))`
|
* `ctx.input().key_pressed(Key::A)` -> `ctx.input(|i| i.key_pressed(Key::A))`
|
||||||
* `ui.memory().toggle_popup(popup_id)` -> `ui.memory_mut(|mem| mem.toggle_popup(popup_id))`
|
* `ui.memory().toggle_popup(popup_id)` -> `ui.memory_mut(|mem| mem.toggle_popup(popup_id))`
|
||||||
|
@ -23,18 +26,27 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG
|
||||||
* Add `Button::rounding` to enable round buttons ([#2616](https://github.com/emilk/egui/pull/2616)).
|
* Add `Button::rounding` to enable round buttons ([#2616](https://github.com/emilk/egui/pull/2616)).
|
||||||
* Add `WidgetVisuals::optional_bg_color` - set it to `Color32::TRANSPARENT` to hide button backgrounds ([#2621](https://github.com/emilk/egui/pull/2621)).
|
* Add `WidgetVisuals::optional_bg_color` - set it to `Color32::TRANSPARENT` to hide button backgrounds ([#2621](https://github.com/emilk/egui/pull/2621)).
|
||||||
* Add `Context::screen_rect` and `Context::set_cursor_icon` ([#2625](https://github.com/emilk/egui/pull/2625)).
|
* Add `Context::screen_rect` and `Context::set_cursor_icon` ([#2625](https://github.com/emilk/egui/pull/2625)).
|
||||||
|
* You can turn off the vertical line left of indented regions with `Visuals::indent_has_left_vline` ([#2636](https://github.com/emilk/egui/pull/2636)).
|
||||||
|
* Add `Response.highlight` to highlight a widget ([#2632](https://github.com/emilk/egui/pull/2632)).
|
||||||
|
* Add `Separator::grow` and `Separator::shrink` ([#2665](https://github.com/emilk/egui/pull/2665)).
|
||||||
|
* Add `Slider::trailing_fill` for trailing color behind the circle like a `ProgressBar` ([#2660](https://github.com/emilk/egui/pull/2660)).
|
||||||
|
|
||||||
### Changed 🔧
|
### Changed 🔧
|
||||||
* Improved plot grid appearance ([#2412](https://github.com/emilk/egui/pull/2412)).
|
* Improved plot grid appearance ([#2412](https://github.com/emilk/egui/pull/2412)).
|
||||||
* Improved the algorithm for picking the number of decimals to show when hovering values in the `Plot`.
|
* Improved the algorithm for picking the number of decimals to show when hovering values in the `Plot`.
|
||||||
* Default `ComboBox` is now controlled with `Spacing::combo_width` ([#2621](https://github.com/emilk/egui/pull/2621)).
|
* Default `ComboBox` is now controlled with `Spacing::combo_width` ([#2621](https://github.com/emilk/egui/pull/2621)).
|
||||||
|
* `DragValue` and `Slider` now use the proportional font ([#2638](https://github.com/emilk/egui/pull/2638)).
|
||||||
|
* `ScrollArea` is less aggressive about clipping its contents ([#2665](https://github.com/emilk/egui/pull/2665)).
|
||||||
|
* Updated to be compatible with a major breaking change in AccessKit that drastically reduces memory usage when accessibility is enabled ([#2678](https://github.com/emilk/egui/pull/2678)).
|
||||||
|
* Improve `DragValue` behavior ([#2649](https://github.com/emilk/egui/pull/2649), [#2650](https://github.com/emilk/egui/pull/2650), [#2688](https://github.com/emilk/egui/pull/2688), [#2638](https://github.com/emilk/egui/pull/2638)).
|
||||||
|
|
||||||
### Fixed 🐛
|
### Fixed 🐛
|
||||||
* Trigger `PointerEvent::Released` for drags ([#2507](https://github.com/emilk/egui/pull/2507)).
|
* Trigger `PointerEvent::Released` for drags ([#2507](https://github.com/emilk/egui/pull/2507)).
|
||||||
* Expose `TextEdit`'s multiline flag to AccessKit ([#2448](https://github.com/emilk/egui/pull/2448)).
|
* Expose `TextEdit`'s multiline flag to AccessKit ([#2448](https://github.com/emilk/egui/pull/2448)).
|
||||||
* Don't render `\r` (Carriage Return) ([#2452](https://github.com/emilk/egui/pull/2452)).
|
* Don't render `\r` (Carriage Return) ([#2452](https://github.com/emilk/egui/pull/2452)).
|
||||||
* The `button_padding` style option works closer as expected with image+text buttons now ([#2510](https://github.com/emilk/egui/pull/2510)).
|
* The `button_padding` style option works closer as expected with image+text buttons now ([#2510](https://github.com/emilk/egui/pull/2510)).
|
||||||
* Fixed rendering of `…` (ellipsis).
|
* Menus are now moved to fit on the screen.
|
||||||
|
* Fix `Window::pivot` causing windows to move around ([#2694](https://github.com/emilk/egui/pull/2694)).
|
||||||
|
|
||||||
|
|
||||||
## 0.20.1 - 2022-12-11 - Fix key-repeat
|
## 0.20.1 - 2022-12-11 - Fix key-repeat
|
||||||
|
|
1850
Cargo.lock
generated
1850
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -5,7 +5,6 @@ members = [
|
||||||
"crates/egui_demo_app",
|
"crates/egui_demo_app",
|
||||||
"crates/egui_demo_lib",
|
"crates/egui_demo_lib",
|
||||||
"crates/egui_extras",
|
"crates/egui_extras",
|
||||||
"crates/egui_glium",
|
|
||||||
"crates/egui_glow",
|
"crates/egui_glow",
|
||||||
"crates/egui-wgpu",
|
"crates/egui-wgpu",
|
||||||
"crates/egui-winit",
|
"crates/egui-winit",
|
||||||
|
@ -27,7 +26,8 @@ opt-level = 2 # fast and small wasm, basically same as `opt-level = 's'`
|
||||||
|
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
split-debuginfo = "unpacked" # faster debug builds on mac
|
# Can't leave this on by default, because it breaks the Windows build. Related: https://github.com/rust-lang/cargo/issues/4897
|
||||||
|
# split-debuginfo = "unpacked" # faster debug builds on mac
|
||||||
# opt-level = 1 # Make debug builds run faster
|
# opt-level = 1 # Make debug builds run faster
|
||||||
|
|
||||||
# Optimize all dependencies even in debug builds (does not affect workspace packages):
|
# Optimize all dependencies even in debug builds (does not affect workspace packages):
|
||||||
|
|
13
README.md
13
README.md
|
@ -66,11 +66,11 @@ To test the demo app locally, run `cargo run --release -p egui_demo_app`.
|
||||||
|
|
||||||
The native backend is [`egui_glow`](https://github.com/emilk/egui/tree/master/crates/egui_glow) (using [`glow`](https://crates.io/crates/glow)) and should work out-of-the-box on Mac and Windows, but on Linux you need to first run:
|
The native backend is [`egui_glow`](https://github.com/emilk/egui/tree/master/crates/egui_glow) (using [`glow`](https://crates.io/crates/glow)) and should work out-of-the-box on Mac and Windows, but on Linux you need to first run:
|
||||||
|
|
||||||
`sudo apt-get install -y libclang-dev libgtk-3-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libspeechd-dev libxkbcommon-dev libssl-dev`
|
`sudo apt-get install -y libclang-dev libgtk-3-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev`
|
||||||
|
|
||||||
On Fedora Rawhide you need to run:
|
On Fedora Rawhide you need to run:
|
||||||
|
|
||||||
`dnf install clang clang-devel clang-tools-extra speech-dispatcher-devel libxkbcommon-devel pkg-config openssl-devel libxcb-devel`
|
`dnf install clang clang-devel clang-tools-extra libxkbcommon-devel pkg-config openssl-devel libxcb-devel`
|
||||||
|
|
||||||
**NOTE**: This is just for the demo app - egui itself is completely platform agnostic!
|
**NOTE**: This is just for the demo app - egui itself is completely platform agnostic!
|
||||||
|
|
||||||
|
@ -158,17 +158,17 @@ An integration needs to do the following each frame:
|
||||||
* **Input**: Gather input (mouse, touches, keyboard, screen size, etc) and give it to egui
|
* **Input**: Gather input (mouse, touches, keyboard, screen size, etc) and give it to egui
|
||||||
* Run the application code
|
* Run the application code
|
||||||
* **Output**: Handle egui output (cursor changes, paste, texture allocations, …)
|
* **Output**: Handle egui output (cursor changes, paste, texture allocations, …)
|
||||||
* **Painting**: Render the triangle mesh egui produces (see [OpenGL example](https://github.com/emilk/egui/blob/master/crates/egui_glium/src/painter.rs))
|
* **Painting**: Render the triangle mesh egui produces (see [OpenGL example](https://github.com/emilk/egui/blob/master/crates/egui_glow/src/painter.rs))
|
||||||
|
|
||||||
### Official integrations
|
### Official integrations
|
||||||
|
|
||||||
These are the official egui integrations:
|
These are the official egui integrations:
|
||||||
|
|
||||||
* [`eframe`](https://github.com/emilk/egui/tree/master/crates/eframe) for compiling the same app to web/wasm and desktop/native. Uses `egui_glow` and `egui-winit`.
|
* [`eframe`](https://github.com/emilk/egui/tree/master/crates/eframe) for compiling the same app to web/wasm and desktop/native. Uses `egui-winit` and `egui_glow` or `egui-wgpu`.
|
||||||
* [`egui_glium`](https://github.com/emilk/egui/tree/master/crates/egui_glium) for compiling native apps with [Glium](https://github.com/glium/glium).
|
|
||||||
* [`egui_glow`](https://github.com/emilk/egui/tree/master/crates/egui_glow) for rendering egui with [glow](https://github.com/grovesNL/glow) on native and web, and for making native apps.
|
* [`egui_glow`](https://github.com/emilk/egui/tree/master/crates/egui_glow) for rendering egui with [glow](https://github.com/grovesNL/glow) on native and web, and for making native apps.
|
||||||
* [`egui-wgpu`](https://github.com/emilk/egui/tree/master/crates/egui-wgpu) for [wgpu](https://crates.io/crates/wgpu) (WebGPU API).
|
* [`egui-wgpu`](https://github.com/emilk/egui/tree/master/crates/egui-wgpu) for [wgpu](https://crates.io/crates/wgpu) (WebGPU API).
|
||||||
* [`egui-winit`](https://github.com/emilk/egui/tree/master/crates/egui-winit) for integrating with [winit](https://github.com/rust-windowing/winit).
|
* [`egui-winit`](https://github.com/emilk/egui/tree/master/crates/egui-winit) for integrating with [winit](https://github.com/rust-windowing/winit).
|
||||||
|
* [`egui_glium`](https://github.com/emilk/egui/tree/master/crates/egui_glium) for compiling native apps with [Glium](https://github.com/glium/glium) (DEPRECATED - looking for new maintainer).
|
||||||
|
|
||||||
### 3rd party integrations
|
### 3rd party integrations
|
||||||
|
|
||||||
|
@ -186,13 +186,14 @@ These are the official egui integrations:
|
||||||
* [`egui-tetra`](https://crates.io/crates/egui-tetra) for [Tetra](https://crates.io/crates/tetra), a 2D game framework.
|
* [`egui-tetra`](https://crates.io/crates/egui-tetra) for [Tetra](https://crates.io/crates/tetra), a 2D game framework.
|
||||||
* [`egui-winit-ash-integration`](https://github.com/MatchaChoco010/egui-winit-ash-integration) for [winit](https://github.com/rust-windowing/winit) and [ash](https://github.com/MaikKlein/ash).
|
* [`egui-winit-ash-integration`](https://github.com/MatchaChoco010/egui-winit-ash-integration) for [winit](https://github.com/rust-windowing/winit) and [ash](https://github.com/MaikKlein/ash).
|
||||||
* [`fltk-egui`](https://crates.io/crates/fltk-egui) for [fltk-rs](https://github.com/fltk-rs/fltk-rs).
|
* [`fltk-egui`](https://crates.io/crates/fltk-egui) for [fltk-rs](https://github.com/fltk-rs/fltk-rs).
|
||||||
* [`ggez-egui`](https://github.com/NemuiSen/ggez-egui) for the [ggez](https://ggez.rs/) game framework.
|
* [`ggegui`](https://github.com/NemuiSen/ggegui) for the [ggez](https://ggez.rs/) game framework.
|
||||||
* [`godot-egui`](https://github.com/setzer22/godot-egui) for [godot-rust](https://github.com/godot-rust/godot-rust).
|
* [`godot-egui`](https://github.com/setzer22/godot-egui) for [godot-rust](https://github.com/godot-rust/godot-rust).
|
||||||
* [`nannou_egui`](https://github.com/nannou-org/nannou/tree/master/nannou_egui) for [nannou](https://nannou.cc).
|
* [`nannou_egui`](https://github.com/nannou-org/nannou/tree/master/nannou_egui) for [nannou](https://nannou.cc).
|
||||||
* [`notan_egui`](https://github.com/Nazariglez/notan/tree/main/crates/notan_egui) for [notan](https://github.com/Nazariglez/notan).
|
* [`notan_egui`](https://github.com/Nazariglez/notan/tree/main/crates/notan_egui) for [notan](https://github.com/Nazariglez/notan).
|
||||||
* [`screen-13-egui`](https://github.com/attackgoat/screen-13/tree/master/contrib/screen-13-egui) for [Screen 13](https://github.com/attackgoat/screen-13).
|
* [`screen-13-egui`](https://github.com/attackgoat/screen-13/tree/master/contrib/screen-13-egui) for [Screen 13](https://github.com/attackgoat/screen-13).
|
||||||
* [`egui_skia`](https://github.com/lucasmerlin/egui_skia) for [skia](https://github.com/rust-skia/rust-skia/tree/master/skia-safe).
|
* [`egui_skia`](https://github.com/lucasmerlin/egui_skia) for [skia](https://github.com/rust-skia/rust-skia/tree/master/skia-safe).
|
||||||
* [`smithay-egui`](https://github.com/Smithay/smithay-egui) for [smithay](https://github.com/Smithay/smithay/).
|
* [`smithay-egui`](https://github.com/Smithay/smithay-egui) for [smithay](https://github.com/Smithay/smithay/).
|
||||||
|
* [`tauri-egui`](https://github.com/tauri-apps/tauri-egui) for [tauri](https://github.com/tauri-apps/tauri).
|
||||||
|
|
||||||
Missing an integration for the thing you're working on? Create one, it's easy!
|
Missing an integration for the thing you're working on? Create one, it's easy!
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,9 @@ All notable changes to the `ecolor` crate will be noted in this file.
|
||||||
|
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
|
||||||
|
## 0.21.0 - 2023-02-08
|
||||||
* Add `Color32::gamma_multiply` ([#2437](https://github.com/emilk/egui/pull/2437)).
|
* Add `Color32::gamma_multiply` ([#2437](https://github.com/emilk/egui/pull/2437)).
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ecolor"
|
name = "ecolor"
|
||||||
version = "0.20.0"
|
version = "0.21.0"
|
||||||
authors = [
|
authors = [
|
||||||
"Emil Ernerfeldt <emil.ernerfeldt@gmail.com>",
|
"Emil Ernerfeldt <emil.ernerfeldt@gmail.com>",
|
||||||
"Andreas Reich <reichandreas@gmx.de>",
|
"Andreas Reich <reichandreas@gmx.de>",
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
# ecolor - egui color library
|
# ecolor - egui color library
|
||||||
|
|
||||||
|
[](https://crates.io/crates/ecolor)
|
||||||
|
[](https://docs.rs/ecolor)
|
||||||
|
[](https://github.com/rust-secure-code/safety-dance/)
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
A simple color storage and conversion library.
|
A simple color storage and conversion library.
|
||||||
|
|
||||||
Made for [`egui`](https://github.com/emilk/egui/).
|
Made for [`egui`](https://github.com/emilk/egui/).
|
||||||
|
|
|
@ -198,4 +198,19 @@ impl Color32 {
|
||||||
// we need a somewhat expensive conversion to linear space and back.
|
// we need a somewhat expensive conversion to linear space and back.
|
||||||
Rgba::from(self).multiply(factor).into()
|
Rgba::from(self).multiply(factor).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Converts to floating point values in the range 0-1 without any gamma space conversion.
|
||||||
|
///
|
||||||
|
/// Use this with great care! In almost all cases, you want to convert to [`crate::Rgba`] instead
|
||||||
|
/// in order to obtain linear space color values.
|
||||||
|
#[inline]
|
||||||
|
pub fn to_normalized_gamma_f32(self) -> [f32; 4] {
|
||||||
|
let Self([r, g, b, a]) = self;
|
||||||
|
[
|
||||||
|
r as f32 / 255.0,
|
||||||
|
g as f32 / 255.0,
|
||||||
|
b as f32 / 255.0,
|
||||||
|
a as f32 / 255.0,
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,37 @@ NOTE: [`egui-winit`](../egui-winit/CHANGELOG.md), [`egui_glium`](../egui_glium/C
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
|
||||||
|
## 0.21.3 - 2023-02-15
|
||||||
|
* Fix typing the letter 'P' on web ([#2740](https://github.com/emilk/egui/pull/2740)).
|
||||||
|
|
||||||
|
|
||||||
|
## 0.21.2 - 2023-02-12
|
||||||
|
* Allow compiling `eframe` with `--no-default-features` ([#2728](https://github.com/emilk/egui/pull/2728)).
|
||||||
|
|
||||||
|
|
||||||
|
## 0.21.1 - 2023-02-12
|
||||||
|
* Fixed crash when native window position is in an invalid state, which could happen e.g. due to changes in monitor size or DPI ([#2722](https://github.com/emilk/egui/issues/2722)).
|
||||||
|
|
||||||
|
|
||||||
|
## 0.21.0 - 2023-02-08 - Update to `winit` 0.28
|
||||||
|
* ⚠️ BREAKING: `App::clear_color` now expects you to return a raw float array ([#2666](https://github.com/emilk/egui/pull/2666)).
|
||||||
|
* The `screen_reader` feature has now been renamed `web_screen_reader` and only work on web. On other platforms, use the `accesskit` feature flag instead ([#2669](https://github.com/emilk/egui/pull/2669)).
|
||||||
|
|
||||||
#### Desktop/Native:
|
#### Desktop/Native:
|
||||||
* `eframe::run_native` now returns a `Result` ([#2433](https://github.com/emilk/egui/pull/2433)).
|
* `eframe::run_native` now returns a `Result` ([#2433](https://github.com/emilk/egui/pull/2433)).
|
||||||
|
* Update to `winit` 0.28, adding support for mac trackpad zoom ([#2654](https://github.com/emilk/egui/pull/2654)).
|
||||||
|
* Fix bug where the cursor could get stuck using the wrong icon.
|
||||||
|
* `NativeOptions::transparent` now works with the wgpu backend ([#2684](https://github.com/emilk/egui/pull/2684)).
|
||||||
|
* Add `Frame::set_minimized` and `set_maximized` ([#2292](https://github.com/emilk/egui/pull/2292), [#2672](https://github.com/emilk/egui/pull/2672)).
|
||||||
|
* Fixed persistence of native window position on Windows OS ([#2583](https://github.com/emilk/egui/issues/2583)).
|
||||||
|
|
||||||
#### Web:
|
#### Web:
|
||||||
* Prevent ctrl-P/cmd-P from opening the print dialog ([#2598](https://github.com/emilk/egui/pull/2598)).
|
* Prevent ctrl-P/cmd-P from opening the print dialog ([#2598](https://github.com/emilk/egui/pull/2598)).
|
||||||
|
|
||||||
|
|
||||||
## 0.20.1 - 2022-12-11
|
## 0.20.1 - 2022-12-11
|
||||||
* Fix docs.rs build ([#2420](https://github.com/emilk/egui/pull/2420)).
|
* Fix [docs.rs](https://docs.rs/eframe) build ([#2420](https://github.com/emilk/egui/pull/2420)).
|
||||||
|
|
||||||
|
|
||||||
## 0.20.0 - 2022-12-08 - AccessKit integration and `wgpu` web support
|
## 0.20.0 - 2022-12-08 - AccessKit integration and `wgpu` web support
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "eframe"
|
name = "eframe"
|
||||||
version = "0.20.1"
|
version = "0.21.3"
|
||||||
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||||
description = "egui framework - write GUI apps that compiles to web and/or natively"
|
description = "egui framework - write GUI apps that compiles to web and/or natively"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
@ -14,9 +14,7 @@ keywords = ["egui", "gui", "gamedev"]
|
||||||
include = ["../LICENSE-APACHE", "../LICENSE-MIT", "**/*.rs", "Cargo.toml"]
|
include = ["../LICENSE-APACHE", "../LICENSE-MIT", "**/*.rs", "Cargo.toml"]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
# Avoid speech-dispatcher dependencies - see https://docs.rs/crate/eframe/0.20.0/builds/695200
|
all-features = true
|
||||||
no-default-features = true
|
|
||||||
features = ["document-features", "glow", "wgpu", "persistence", "wgpu"]
|
|
||||||
targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]
|
targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
@ -38,7 +36,7 @@ dark-light = ["dep:dark-light"]
|
||||||
default_fonts = ["egui/default_fonts"]
|
default_fonts = ["egui/default_fonts"]
|
||||||
|
|
||||||
## Use [`glow`](https://github.com/grovesNL/glow) for painting, via [`egui_glow`](https://github.com/emilk/egui/tree/master/crates/egui_glow).
|
## Use [`glow`](https://github.com/grovesNL/glow) for painting, via [`egui_glow`](https://github.com/emilk/egui/tree/master/crates/egui_glow).
|
||||||
glow = ["dep:glow", "dep:egui_glow", "dep:glutin"]
|
glow = ["dep:glow", "dep:egui_glow", "dep:glutin", "dep:glutin-winit"]
|
||||||
|
|
||||||
## Enable saving app state to disk.
|
## Enable saving app state to disk.
|
||||||
persistence = [
|
persistence = [
|
||||||
|
@ -55,8 +53,10 @@ persistence = [
|
||||||
## `eframe` will call `puffin::GlobalProfiler::lock().new_frame()` for you
|
## `eframe` will call `puffin::GlobalProfiler::lock().new_frame()` for you
|
||||||
puffin = ["dep:puffin", "egui_glow?/puffin", "egui-wgpu?/puffin"]
|
puffin = ["dep:puffin", "egui_glow?/puffin", "egui-wgpu?/puffin"]
|
||||||
|
|
||||||
## Enable screen reader support (requires `ctx.options_mut(|o| o.screen_reader = true);`)
|
## Enable screen reader support (requires `ctx.options_mut(|o| o.screen_reader = true);`) on web.
|
||||||
screen_reader = ["egui-winit/screen_reader", "tts"]
|
##
|
||||||
|
## For other platforms, use the "accesskit" feature instead.
|
||||||
|
web_screen_reader = ["tts"]
|
||||||
|
|
||||||
## If set, eframe will look for the env-var `EFRAME_SCREENSHOT_TO` and write a screenshot to that location, and then quit.
|
## If set, eframe will look for the env-var `EFRAME_SCREENSHOT_TO` and write a screenshot to that location, and then quit.
|
||||||
## This is used to generate images for the examples.
|
## This is used to generate images for the examples.
|
||||||
|
@ -68,7 +68,7 @@ wgpu = ["dep:wgpu", "dep:egui-wgpu", "dep:pollster"]
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { version = "0.20.0", path = "../egui", default-features = false, features = [
|
egui = { version = "0.21.0", path = "../egui", default-features = false, features = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"tracing",
|
"tracing",
|
||||||
] }
|
] }
|
||||||
|
@ -79,44 +79,38 @@ tracing = { version = "0.1", default-features = false, features = ["std"] }
|
||||||
## Enable this when generating docs.
|
## Enable this when generating docs.
|
||||||
document-features = { version = "0.2", optional = true }
|
document-features = { version = "0.2", optional = true }
|
||||||
|
|
||||||
egui_glow = { version = "0.20.0", path = "../egui_glow", optional = true, default-features = false }
|
egui_glow = { version = "0.21.0", path = "../egui_glow", optional = true, default-features = false }
|
||||||
glow = { version = "0.11", optional = true }
|
glow = { version = "0.12", optional = true }
|
||||||
ron = { version = "0.8", optional = true, features = ["integer128"] }
|
ron = { version = "0.8", optional = true, features = ["integer128"] }
|
||||||
serde = { version = "1", optional = true, features = ["derive"] }
|
serde = { version = "1", optional = true, features = ["derive"] }
|
||||||
|
|
||||||
# -------------------------------------------
|
# -------------------------------------------
|
||||||
# native:
|
# native:
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
egui-winit = { version = "0.20.0", path = "../egui-winit", default-features = false, features = [
|
egui-winit = { version = "0.21.1", path = "../egui-winit", default-features = false, features = [
|
||||||
"clipboard",
|
"clipboard",
|
||||||
"links",
|
"links",
|
||||||
] }
|
] }
|
||||||
raw-window-handle = { version = "0.5.0" }
|
raw-window-handle = { version = "0.5.0" }
|
||||||
winit = "0.27.2"
|
winit = "0.28.1"
|
||||||
|
|
||||||
# optional native:
|
# optional native:
|
||||||
dark-light = { version = "0.2.1", optional = true }
|
dark-light = { version = "1.0", optional = true }
|
||||||
directories-next = { version = "2", optional = true }
|
directories-next = { version = "2", optional = true }
|
||||||
egui-wgpu = { version = "0.20.0", path = "../egui-wgpu", optional = true, features = [
|
egui-wgpu = { version = "0.21.0", path = "../egui-wgpu", optional = true, features = [
|
||||||
"winit",
|
"winit",
|
||||||
] } # if wgpu is used, use it with winit
|
] } # if wgpu is used, use it with winit
|
||||||
pollster = { version = "0.2", optional = true } # needed for wgpu
|
pollster = { version = "0.3", optional = true } # needed for wgpu
|
||||||
|
|
||||||
# we can expose these to user so that they can select which backends they want to enable to avoid compiling useless deps.
|
# we can expose these to user so that they can select which backends they want to enable to avoid compiling useless deps.
|
||||||
# this can be done at the same time we expose x11/wayland features of winit crate.
|
# this can be done at the same time we expose x11/wayland features of winit crate.
|
||||||
glutin = { version = "0.30.0", optional = true, es = [
|
glutin = { version = "0.30", optional = true }
|
||||||
"egl",
|
glutin-winit = { version = "0.3.0", optional = true }
|
||||||
"glx",
|
|
||||||
"x11",
|
|
||||||
"wayland",
|
|
||||||
"wgl",
|
|
||||||
] }
|
|
||||||
|
|
||||||
image = { version = "0.24", optional = true, default-features = false, features = [
|
image = { version = "0.24", optional = true, default-features = false, features = [
|
||||||
"png",
|
"png",
|
||||||
] }
|
] }
|
||||||
puffin = { version = "0.14", optional = true }
|
puffin = { version = "0.14", optional = true }
|
||||||
wgpu = { version = "0.14", optional = true }
|
wgpu = { version = "0.15.0", optional = true }
|
||||||
|
|
||||||
# -------------------------------------------
|
# -------------------------------------------
|
||||||
# web:
|
# web:
|
||||||
|
@ -124,7 +118,7 @@ wgpu = { version = "0.14", optional = true }
|
||||||
bytemuck = "1.7"
|
bytemuck = "1.7"
|
||||||
js-sys = "0.3"
|
js-sys = "0.3"
|
||||||
percent-encoding = "2.1"
|
percent-encoding = "2.1"
|
||||||
wasm-bindgen = "0.2"
|
wasm-bindgen = "=0.2.84"
|
||||||
wasm-bindgen-futures = "0.4"
|
wasm-bindgen-futures = "0.4"
|
||||||
web-sys = { version = "0.3.58", features = [
|
web-sys = { version = "0.3.58", features = [
|
||||||
"BinaryType",
|
"BinaryType",
|
||||||
|
@ -170,6 +164,6 @@ web-sys = { version = "0.3.58", features = [
|
||||||
] }
|
] }
|
||||||
|
|
||||||
# optional web:
|
# optional web:
|
||||||
egui-wgpu = { version = "0.20.0", path = "../egui-wgpu", optional = true } # if wgpu is used, use it without (!) winit
|
egui-wgpu = { version = "0.21.0", path = "../egui-wgpu", optional = true } # if wgpu is used, use it without (!) winit
|
||||||
tts = { version = "0.24", optional = true }
|
tts = { version = "0.25", optional = true, default-features = false }
|
||||||
wgpu = { version = "0.14", optional = true, features = ["webgl"] }
|
wgpu = { version = "0.15.0", optional = true, features = ["webgl"] }
|
||||||
|
|
|
@ -22,7 +22,7 @@ For how to use `egui`, see [the egui docs](https://docs.rs/egui).
|
||||||
To use on Linux, first run:
|
To use on Linux, first run:
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libspeechd-dev libxkbcommon-dev libssl-dev
|
sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
You need to either use `edition = "2021"`, or set `resolver = "2"` in the `[workspace]` section of your to-level `Cargo.toml`. See [this link](https://doc.rust-lang.org/edition-guide/rust-2021/default-cargo-resolver.html) for more info.
|
You need to either use `edition = "2021"`, or set `resolver = "2"` in the `[workspace]` section of your to-level `Cargo.toml`. See [this link](https://doc.rust-lang.org/edition-guide/rust-2021/default-cargo-resolver.html) for more info.
|
||||||
|
|
|
@ -10,9 +10,11 @@
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
pub use crate::native::run::UserEvent;
|
pub use crate::native::run::UserEvent;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
pub use winit::event_loop::EventLoopBuilder;
|
pub use winit::event_loop::EventLoopBuilder;
|
||||||
|
|
||||||
/// Hook into the building of an event loop before it is run
|
/// Hook into the building of an event loop before it is run
|
||||||
|
@ -20,6 +22,7 @@ pub use winit::event_loop::EventLoopBuilder;
|
||||||
/// You can configure any platform specific details required on top of the default configuration
|
/// You can configure any platform specific details required on top of the default configuration
|
||||||
/// done by `EFrame`.
|
/// done by `EFrame`.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
pub type EventLoopBuilderHook = Box<dyn FnOnce(&mut EventLoopBuilder<UserEvent>)>;
|
pub type EventLoopBuilderHook = Box<dyn FnOnce(&mut EventLoopBuilder<UserEvent>)>;
|
||||||
|
|
||||||
/// This is how your app is created.
|
/// This is how your app is created.
|
||||||
|
@ -149,13 +152,21 @@ pub trait App {
|
||||||
egui::Vec2::INFINITY
|
egui::Vec2::INFINITY
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Background color for the app, e.g. what is sent to `gl.clearColor`.
|
/// Background color values for the app, e.g. what is sent to `gl.clearColor`.
|
||||||
|
///
|
||||||
/// This is the background of your windows if you don't set a central panel.
|
/// This is the background of your windows if you don't set a central panel.
|
||||||
fn clear_color(&self, _visuals: &egui::Visuals) -> egui::Rgba {
|
///
|
||||||
|
/// ATTENTION:
|
||||||
|
/// Since these float values go to the render as-is, any color space conversion as done
|
||||||
|
/// e.g. by converting from [`egui::Color32`] to [`egui::Rgba`] may cause incorrect results.
|
||||||
|
/// egui recommends that rendering backends use a normal "gamma-space" (non-sRGB-aware) blending,
|
||||||
|
/// which means the values you return here should also be in `sRGB` gamma-space in the 0-1 range.
|
||||||
|
/// You can use [`egui::Color32::to_normalized_gamma_f32`] for this.
|
||||||
|
fn clear_color(&self, _visuals: &egui::Visuals) -> [f32; 4] {
|
||||||
// NOTE: a bright gray makes the shadows of the windows look weird.
|
// NOTE: a bright gray makes the shadows of the windows look weird.
|
||||||
// We use a bit of transparency so that if the user switches on the
|
// We use a bit of transparency so that if the user switches on the
|
||||||
// `transparent()` option they get immediate results.
|
// `transparent()` option they get immediate results.
|
||||||
egui::Color32::from_rgba_unmultiplied(12, 12, 12, 180).into()
|
egui::Color32::from_rgba_unmultiplied(12, 12, 12, 180).to_normalized_gamma_f32()
|
||||||
|
|
||||||
// _visuals.window_fill() would also be a natural choice
|
// _visuals.window_fill() would also be a natural choice
|
||||||
}
|
}
|
||||||
|
@ -309,6 +320,7 @@ pub struct NativeOptions {
|
||||||
pub hardware_acceleration: HardwareAcceleration,
|
pub hardware_acceleration: HardwareAcceleration,
|
||||||
|
|
||||||
/// What rendering backend to use.
|
/// What rendering backend to use.
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
pub renderer: Renderer,
|
pub renderer: Renderer,
|
||||||
|
|
||||||
/// Only used if the `dark-light` feature is enabled:
|
/// Only used if the `dark-light` feature is enabled:
|
||||||
|
@ -347,6 +359,7 @@ pub struct NativeOptions {
|
||||||
/// event loop before it is run.
|
/// event loop before it is run.
|
||||||
///
|
///
|
||||||
/// Note: A [`NativeOptions`] clone will not include any `event_loop_builder` hook.
|
/// Note: A [`NativeOptions`] clone will not include any `event_loop_builder` hook.
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
pub event_loop_builder: Option<EventLoopBuilderHook>,
|
pub event_loop_builder: Option<EventLoopBuilderHook>,
|
||||||
|
|
||||||
#[cfg(feature = "glow")]
|
#[cfg(feature = "glow")]
|
||||||
|
@ -373,9 +386,13 @@ impl Clone for NativeOptions {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
icon_data: self.icon_data.clone(),
|
icon_data: self.icon_data.clone(),
|
||||||
|
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
event_loop_builder: None, // Skip any builder callbacks if cloning
|
event_loop_builder: None, // Skip any builder callbacks if cloning
|
||||||
|
|
||||||
#[cfg(feature = "wgpu")]
|
#[cfg(feature = "wgpu")]
|
||||||
wgpu_options: self.wgpu_options.clone(),
|
wgpu_options: self.wgpu_options.clone(),
|
||||||
|
|
||||||
..*self
|
..*self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -389,8 +406,10 @@ impl Default for NativeOptions {
|
||||||
maximized: false,
|
maximized: false,
|
||||||
decorated: true,
|
decorated: true,
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
fullsize_content: false,
|
fullsize_content: false,
|
||||||
|
|
||||||
drag_and_drop_support: true,
|
drag_and_drop_support: true,
|
||||||
icon_data: None,
|
icon_data: None,
|
||||||
initial_window_pos: None,
|
initial_window_pos: None,
|
||||||
|
@ -405,14 +424,22 @@ impl Default for NativeOptions {
|
||||||
depth_buffer: 0,
|
depth_buffer: 0,
|
||||||
stencil_buffer: 0,
|
stencil_buffer: 0,
|
||||||
hardware_acceleration: HardwareAcceleration::Preferred,
|
hardware_acceleration: HardwareAcceleration::Preferred,
|
||||||
|
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
renderer: Renderer::default(),
|
renderer: Renderer::default(),
|
||||||
|
|
||||||
follow_system_theme: cfg!(target_os = "macos") || cfg!(target_os = "windows"),
|
follow_system_theme: cfg!(target_os = "macos") || cfg!(target_os = "windows"),
|
||||||
default_theme: Theme::Dark,
|
default_theme: Theme::Dark,
|
||||||
run_and_return: true,
|
run_and_return: true,
|
||||||
|
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
event_loop_builder: None,
|
event_loop_builder: None,
|
||||||
|
|
||||||
#[cfg(feature = "glow")]
|
#[cfg(feature = "glow")]
|
||||||
shader_version: None,
|
shader_version: None,
|
||||||
|
|
||||||
centered: false,
|
centered: false,
|
||||||
|
|
||||||
#[cfg(feature = "wgpu")]
|
#[cfg(feature = "wgpu")]
|
||||||
wgpu_options: egui_wgpu::WgpuConfiguration::default(),
|
wgpu_options: egui_wgpu::WgpuConfiguration::default(),
|
||||||
}
|
}
|
||||||
|
@ -429,6 +456,7 @@ impl NativeOptions {
|
||||||
match dark_light::detect() {
|
match dark_light::detect() {
|
||||||
dark_light::Mode::Dark => Some(Theme::Dark),
|
dark_light::Mode::Dark => Some(Theme::Dark),
|
||||||
dark_light::Mode::Light => Some(Theme::Light),
|
dark_light::Mode::Light => Some(Theme::Light),
|
||||||
|
dark_light::Mode::Default => None,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -550,6 +578,7 @@ pub enum WebGlContextOption {
|
||||||
/// What rendering backend to use.
|
/// What rendering backend to use.
|
||||||
///
|
///
|
||||||
/// You need to enable the "glow" and "wgpu" features to have a choice.
|
/// You need to enable the "glow" and "wgpu" features to have a choice.
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
|
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
|
||||||
|
@ -563,6 +592,7 @@ pub enum Renderer {
|
||||||
Wgpu,
|
Wgpu,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
impl Default for Renderer {
|
impl Default for Renderer {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
#[cfg(feature = "glow")]
|
#[cfg(feature = "glow")]
|
||||||
|
@ -578,6 +608,7 @@ impl Default for Renderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
impl std::fmt::Display for Renderer {
|
impl std::fmt::Display for Renderer {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
@ -590,6 +621,7 @@ impl std::fmt::Display for Renderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
impl std::str::FromStr for Renderer {
|
impl std::str::FromStr for Renderer {
|
||||||
type Err = String;
|
type Err = String;
|
||||||
|
|
||||||
|
@ -709,6 +741,18 @@ impl Frame {
|
||||||
self.output.close = true;
|
self.output.close = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Minimize or unminimize window. (native only)
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub fn set_minimized(&mut self, minimized: bool) {
|
||||||
|
self.output.minimized = Some(minimized);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Maximize or unmaximize window. (native only)
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub fn set_maximized(&mut self, maximized: bool) {
|
||||||
|
self.output.maximized = Some(maximized);
|
||||||
|
}
|
||||||
|
|
||||||
/// Tell `eframe` to close the desktop window.
|
/// Tell `eframe` to close the desktop window.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
#[deprecated = "Renamed `close`"]
|
#[deprecated = "Renamed `close`"]
|
||||||
|
@ -790,6 +834,7 @@ impl Frame {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// for integrations only: call once per frame
|
/// for integrations only: call once per frame
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
pub(crate) fn take_app_output(&mut self) -> backend::AppOutput {
|
pub(crate) fn take_app_output(&mut self) -> backend::AppOutput {
|
||||||
std::mem::take(&mut self.output)
|
std::mem::take(&mut self.output)
|
||||||
}
|
}
|
||||||
|
@ -820,6 +865,12 @@ pub struct WindowInfo {
|
||||||
/// Are we in fullscreen mode?
|
/// Are we in fullscreen mode?
|
||||||
pub fullscreen: bool,
|
pub fullscreen: bool,
|
||||||
|
|
||||||
|
/// Are we minimized?
|
||||||
|
pub minimized: bool,
|
||||||
|
|
||||||
|
/// Are we maximized?
|
||||||
|
pub maximized: bool,
|
||||||
|
|
||||||
/// Window inner size in egui points (logical pixels).
|
/// Window inner size in egui points (logical pixels).
|
||||||
pub size: egui::Vec2,
|
pub size: egui::Vec2,
|
||||||
|
|
||||||
|
@ -1002,5 +1053,13 @@ pub(crate) mod backend {
|
||||||
/// Set to some bool to tell the window always on top.
|
/// Set to some bool to tell the window always on top.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub always_on_top: Option<bool>,
|
pub always_on_top: Option<bool>,
|
||||||
|
|
||||||
|
/// Set to some bool to minimize or unminimize window.
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub minimized: Option<bool>,
|
||||||
|
|
||||||
|
/// Set to some bool to maximize or unmaximize window.
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub maximized: Option<bool>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,6 +137,7 @@ pub async fn start_web(
|
||||||
// When compiling natively
|
// When compiling natively
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
mod native;
|
mod native;
|
||||||
|
|
||||||
/// This is how you start a native (desktop) app.
|
/// This is how you start a native (desktop) app.
|
||||||
|
@ -179,6 +180,7 @@ mod native;
|
||||||
/// This function can fail if we fail to set up a graphics context.
|
/// This function can fail if we fail to set up a graphics context.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
#[allow(clippy::needless_pass_by_value)]
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
pub fn run_native(
|
pub fn run_native(
|
||||||
app_name: &str,
|
app_name: &str,
|
||||||
native_options: NativeOptions,
|
native_options: NativeOptions,
|
||||||
|
@ -221,36 +223,40 @@ pub enum Error {
|
||||||
Glutin(#[from] glutin::error::Error),
|
Glutin(#[from] glutin::error::Error),
|
||||||
|
|
||||||
#[cfg(all(feature = "glow", not(target_arch = "wasm32")))]
|
#[cfg(all(feature = "glow", not(target_arch = "wasm32")))]
|
||||||
#[error("Found no glutin configs matching the template: {0:?}")]
|
#[error("Found no glutin configs matching the template: {0:?}. error: {1:?}")]
|
||||||
NoGlutinConfigs(glutin::config::ConfigTemplate),
|
NoGlutinConfigs(glutin::config::ConfigTemplate, Box<dyn std::error::Error>),
|
||||||
|
|
||||||
#[cfg(feature = "wgpu")]
|
#[cfg(feature = "wgpu")]
|
||||||
#[error("WGPU error: {0}")]
|
#[error("WGPU error: {0}")]
|
||||||
Wgpu(#[from] wgpu::RequestDeviceError),
|
Wgpu(#[from] egui_wgpu::WgpuError),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
/// Profiling macro for feature "puffin"
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
|
mod profiling_scopes {
|
||||||
|
/// Profiling macro for feature "puffin"
|
||||||
macro_rules! profile_function {
|
macro_rules! profile_function {
|
||||||
($($arg: tt)*) => {
|
($($arg: tt)*) => {
|
||||||
#[cfg(feature = "puffin")]
|
#[cfg(feature = "puffin")]
|
||||||
puffin::profile_function!($($arg)*);
|
puffin::profile_function!($($arg)*);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub(crate) use profile_function;
|
pub(crate) use profile_function;
|
||||||
|
|
||||||
/// Profiling macro for feature "puffin"
|
/// Profiling macro for feature "puffin"
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
macro_rules! profile_scope {
|
macro_rules! profile_scope {
|
||||||
($($arg: tt)*) => {
|
($($arg: tt)*) => {
|
||||||
#[cfg(feature = "puffin")]
|
#[cfg(feature = "puffin")]
|
||||||
puffin::profile_scope!($($arg)*);
|
puffin::profile_scope!($($arg)*);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub(crate) use profile_scope;
|
pub(crate) use profile_scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
|
pub(crate) use profiling_scopes::*;
|
||||||
|
|
|
@ -12,6 +12,14 @@ use egui_winit::{native_pixels_per_point, EventResponse, WindowSettings};
|
||||||
|
|
||||||
use crate::{epi, Theme, WindowInfo};
|
use crate::{epi, Theme, WindowInfo};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct WindowState {
|
||||||
|
// We cannot simply call `winit::Window::is_minimized/is_maximized`
|
||||||
|
// because that deadlocks on mac.
|
||||||
|
pub minimized: bool,
|
||||||
|
pub maximized: bool,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn points_to_size(points: egui::Vec2) -> winit::dpi::LogicalSize<f64> {
|
pub fn points_to_size(points: egui::Vec2) -> winit::dpi::LogicalSize<f64> {
|
||||||
winit::dpi::LogicalSize {
|
winit::dpi::LogicalSize {
|
||||||
width: points.x as f64,
|
width: points.x as f64,
|
||||||
|
@ -19,7 +27,11 @@ pub fn points_to_size(points: egui::Vec2) -> winit::dpi::LogicalSize<f64> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_window_info(window: &winit::window::Window, pixels_per_point: f32) -> WindowInfo {
|
pub fn read_window_info(
|
||||||
|
window: &winit::window::Window,
|
||||||
|
pixels_per_point: f32,
|
||||||
|
window_state: &WindowState,
|
||||||
|
) -> WindowInfo {
|
||||||
let position = window
|
let position = window
|
||||||
.outer_position()
|
.outer_position()
|
||||||
.ok()
|
.ok()
|
||||||
|
@ -38,9 +50,13 @@ pub fn read_window_info(window: &winit::window::Window, pixels_per_point: f32) -
|
||||||
.inner_size()
|
.inner_size()
|
||||||
.to_logical::<f32>(pixels_per_point.into());
|
.to_logical::<f32>(pixels_per_point.into());
|
||||||
|
|
||||||
|
// NOTE: calling window.is_minimized() or window.is_maximized() deadlocks on Mac.
|
||||||
|
|
||||||
WindowInfo {
|
WindowInfo {
|
||||||
position,
|
position,
|
||||||
fullscreen: window.fullscreen().is_some(),
|
fullscreen: window.fullscreen().is_some(),
|
||||||
|
minimized: window_state.minimized,
|
||||||
|
maximized: window_state.maximized,
|
||||||
size: egui::Vec2 {
|
size: egui::Vec2 {
|
||||||
x: size.width,
|
x: size.width,
|
||||||
y: size.height,
|
y: size.height,
|
||||||
|
@ -56,7 +72,6 @@ pub fn window_builder<E>(
|
||||||
window_settings: Option<WindowSettings>,
|
window_settings: Option<WindowSettings>,
|
||||||
) -> winit::window::WindowBuilder {
|
) -> winit::window::WindowBuilder {
|
||||||
let epi::NativeOptions {
|
let epi::NativeOptions {
|
||||||
always_on_top,
|
|
||||||
maximized,
|
maximized,
|
||||||
decorated,
|
decorated,
|
||||||
fullscreen,
|
fullscreen,
|
||||||
|
@ -70,6 +85,7 @@ pub fn window_builder<E>(
|
||||||
max_window_size,
|
max_window_size,
|
||||||
resizable,
|
resizable,
|
||||||
transparent,
|
transparent,
|
||||||
|
centered,
|
||||||
..
|
..
|
||||||
} = native_options;
|
} = native_options;
|
||||||
|
|
||||||
|
@ -77,7 +93,6 @@ pub fn window_builder<E>(
|
||||||
|
|
||||||
let mut window_builder = winit::window::WindowBuilder::new()
|
let mut window_builder = winit::window::WindowBuilder::new()
|
||||||
.with_title(title)
|
.with_title(title)
|
||||||
.with_always_on_top(*always_on_top)
|
|
||||||
.with_decorations(*decorated)
|
.with_decorations(*decorated)
|
||||||
.with_fullscreen(fullscreen.then(|| winit::window::Fullscreen::Borderless(None)))
|
.with_fullscreen(fullscreen.then(|| winit::window::Fullscreen::Borderless(None)))
|
||||||
.with_maximized(*maximized)
|
.with_maximized(*maximized)
|
||||||
|
@ -105,13 +120,16 @@ pub fn window_builder<E>(
|
||||||
|
|
||||||
window_builder = window_builder_drag_and_drop(window_builder, *drag_and_drop_support);
|
window_builder = window_builder_drag_and_drop(window_builder, *drag_and_drop_support);
|
||||||
|
|
||||||
if let Some(mut window_settings) = window_settings {
|
let inner_size_points = if let Some(mut window_settings) = window_settings {
|
||||||
// Restore pos/size from previous session
|
// Restore pos/size from previous session
|
||||||
window_settings.clamp_to_sane_values(largest_monitor_point_size(event_loop));
|
window_settings.clamp_to_sane_values(largest_monitor_point_size(event_loop));
|
||||||
|
#[cfg(windows)]
|
||||||
|
window_settings.clamp_window_to_sane_position(&event_loop);
|
||||||
window_builder = window_settings.initialize_window(window_builder);
|
window_builder = window_settings.initialize_window(window_builder);
|
||||||
|
window_settings.inner_size_points()
|
||||||
} else {
|
} else {
|
||||||
if let Some(pos) = *initial_window_pos {
|
if let Some(pos) = *initial_window_pos {
|
||||||
window_builder = window_builder.with_position(winit::dpi::PhysicalPosition {
|
window_builder = window_builder.with_position(winit::dpi::LogicalPosition {
|
||||||
x: pos.x as f64,
|
x: pos.x as f64,
|
||||||
y: pos.y as f64,
|
y: pos.y as f64,
|
||||||
});
|
});
|
||||||
|
@ -122,9 +140,37 @@ pub fn window_builder<E>(
|
||||||
initial_window_size.at_most(largest_monitor_point_size(event_loop));
|
initial_window_size.at_most(largest_monitor_point_size(event_loop));
|
||||||
window_builder = window_builder.with_inner_size(points_to_size(initial_window_size));
|
window_builder = window_builder.with_inner_size(points_to_size(initial_window_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*initial_window_size
|
||||||
|
};
|
||||||
|
|
||||||
|
if *centered {
|
||||||
|
if let Some(monitor) = event_loop.available_monitors().next() {
|
||||||
|
let monitor_size = monitor.size();
|
||||||
|
let inner_size = inner_size_points.unwrap_or(egui::Vec2 { x: 800.0, y: 600.0 });
|
||||||
|
if monitor_size.width > 0 && monitor_size.height > 0 {
|
||||||
|
let x = (monitor_size.width - inner_size.x as u32) / 2;
|
||||||
|
let y = (monitor_size.height - inner_size.y as u32) / 2;
|
||||||
|
window_builder = window_builder.with_position(winit::dpi::LogicalPosition {
|
||||||
|
x: x as f64,
|
||||||
|
y: y as f64,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window_builder
|
||||||
}
|
}
|
||||||
|
|
||||||
window_builder
|
pub fn apply_native_options_to_window(
|
||||||
|
window: &winit::window::Window,
|
||||||
|
native_options: &crate::NativeOptions,
|
||||||
|
) {
|
||||||
|
use winit::window::WindowLevel;
|
||||||
|
window.set_window_level(if native_options.always_on_top {
|
||||||
|
WindowLevel::AlwaysOnTop
|
||||||
|
} else {
|
||||||
|
WindowLevel::Normal
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn largest_monitor_point_size<E>(event_loop: &EventLoopWindowTarget<E>) -> egui::Vec2 {
|
fn largest_monitor_point_size<E>(event_loop: &EventLoopWindowTarget<E>) -> egui::Vec2 {
|
||||||
|
@ -169,6 +215,7 @@ pub fn handle_app_output(
|
||||||
window: &winit::window::Window,
|
window: &winit::window::Window,
|
||||||
current_pixels_per_point: f32,
|
current_pixels_per_point: f32,
|
||||||
app_output: epi::backend::AppOutput,
|
app_output: epi::backend::AppOutput,
|
||||||
|
window_state: &mut WindowState,
|
||||||
) {
|
) {
|
||||||
let epi::backend::AppOutput {
|
let epi::backend::AppOutput {
|
||||||
close: _,
|
close: _,
|
||||||
|
@ -180,6 +227,8 @@ pub fn handle_app_output(
|
||||||
window_pos,
|
window_pos,
|
||||||
visible: _, // handled in post_present
|
visible: _, // handled in post_present
|
||||||
always_on_top,
|
always_on_top,
|
||||||
|
minimized,
|
||||||
|
maximized,
|
||||||
} = app_output;
|
} = app_output;
|
||||||
|
|
||||||
if let Some(decorated) = decorated {
|
if let Some(decorated) = decorated {
|
||||||
|
@ -216,7 +265,22 @@ pub fn handle_app_output(
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(always_on_top) = always_on_top {
|
if let Some(always_on_top) = always_on_top {
|
||||||
window.set_always_on_top(always_on_top);
|
use winit::window::WindowLevel;
|
||||||
|
window.set_window_level(if always_on_top {
|
||||||
|
WindowLevel::AlwaysOnTop
|
||||||
|
} else {
|
||||||
|
WindowLevel::Normal
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(minimized) = minimized {
|
||||||
|
window.set_minimized(minimized);
|
||||||
|
window_state.minimized = minimized;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(maximized) = maximized {
|
||||||
|
window.set_maximized(maximized);
|
||||||
|
window_state.maximized = maximized;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,6 +307,7 @@ pub struct EpiIntegration {
|
||||||
/// When set, it is time to close the native window.
|
/// When set, it is time to close the native window.
|
||||||
close: bool,
|
close: bool,
|
||||||
can_drag_window: bool,
|
can_drag_window: bool,
|
||||||
|
window_state: WindowState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EpiIntegration {
|
impl EpiIntegration {
|
||||||
|
@ -262,12 +327,17 @@ impl EpiIntegration {
|
||||||
|
|
||||||
let native_pixels_per_point = window.scale_factor() as f32;
|
let native_pixels_per_point = window.scale_factor() as f32;
|
||||||
|
|
||||||
|
let window_state = WindowState {
|
||||||
|
minimized: window.is_minimized().unwrap_or(false),
|
||||||
|
maximized: window.is_maximized(),
|
||||||
|
};
|
||||||
|
|
||||||
let frame = epi::Frame {
|
let frame = epi::Frame {
|
||||||
info: epi::IntegrationInfo {
|
info: epi::IntegrationInfo {
|
||||||
system_theme,
|
system_theme,
|
||||||
cpu_usage: None,
|
cpu_usage: None,
|
||||||
native_pixels_per_point: Some(native_pixels_per_point),
|
native_pixels_per_point: Some(native_pixels_per_point),
|
||||||
window_info: read_window_info(window, egui_ctx.pixels_per_point()),
|
window_info: read_window_info(window, egui_ctx.pixels_per_point(), &window_state),
|
||||||
},
|
},
|
||||||
output: epi::backend::AppOutput {
|
output: epi::backend::AppOutput {
|
||||||
visible: Some(true),
|
visible: Some(true),
|
||||||
|
@ -292,6 +362,7 @@ impl EpiIntegration {
|
||||||
pending_full_output: Default::default(),
|
pending_full_output: Default::default(),
|
||||||
close: false,
|
close: false,
|
||||||
can_drag_window: false,
|
can_drag_window: false,
|
||||||
|
window_state,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,7 +381,7 @@ impl EpiIntegration {
|
||||||
egui_ctx.enable_accesskit();
|
egui_ctx.enable_accesskit();
|
||||||
// Enqueue a repaint so we'll receive a full tree update soon.
|
// Enqueue a repaint so we'll receive a full tree update soon.
|
||||||
egui_ctx.request_repaint();
|
egui_ctx.request_repaint();
|
||||||
egui::accesskit_placeholder_tree_update()
|
egui_ctx.accesskit_placeholder_tree_update()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,12 +444,16 @@ impl EpiIntegration {
|
||||||
) -> egui::FullOutput {
|
) -> egui::FullOutput {
|
||||||
let frame_start = std::time::Instant::now();
|
let frame_start = std::time::Instant::now();
|
||||||
|
|
||||||
self.frame.info.window_info = read_window_info(window, self.egui_ctx.pixels_per_point());
|
self.frame.info.window_info =
|
||||||
|
read_window_info(window, self.egui_ctx.pixels_per_point(), &self.window_state);
|
||||||
let raw_input = self.egui_winit.take_egui_input(window);
|
let raw_input = self.egui_winit.take_egui_input(window);
|
||||||
|
|
||||||
|
// Run user code:
|
||||||
let full_output = self.egui_ctx.run(raw_input, |egui_ctx| {
|
let full_output = self.egui_ctx.run(raw_input, |egui_ctx| {
|
||||||
crate::profile_scope!("App::update");
|
crate::profile_scope!("App::update");
|
||||||
app.update(egui_ctx, &mut self.frame);
|
app.update(egui_ctx, &mut self.frame);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.pending_full_output.append(full_output);
|
self.pending_full_output.append(full_output);
|
||||||
let full_output = std::mem::take(&mut self.pending_full_output);
|
let full_output = std::mem::take(&mut self.pending_full_output);
|
||||||
|
|
||||||
|
@ -391,7 +466,12 @@ impl EpiIntegration {
|
||||||
tracing::debug!("App::on_close_event returned {}", self.close);
|
tracing::debug!("App::on_close_event returned {}", self.close);
|
||||||
}
|
}
|
||||||
self.frame.output.visible = app_output.visible; // this is handled by post_present
|
self.frame.output.visible = app_output.visible; // this is handled by post_present
|
||||||
handle_app_output(window, self.egui_ctx.pixels_per_point(), app_output);
|
handle_app_output(
|
||||||
|
window,
|
||||||
|
self.egui_ctx.pixels_per_point(),
|
||||||
|
app_output,
|
||||||
|
&mut self.window_state,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let frame_time = frame_start.elapsed().as_secs_f64() as f32;
|
let frame_time = frame_start.elapsed().as_secs_f64() as f32;
|
||||||
|
|
|
@ -38,6 +38,7 @@ pub use epi::NativeOptions;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum EventResult {
|
enum EventResult {
|
||||||
Wait,
|
Wait,
|
||||||
|
|
||||||
/// Causes a synchronous repaint inside the event handler. This should only
|
/// Causes a synchronous repaint inside the event handler. This should only
|
||||||
/// be used in special situations if the window must be repainted while
|
/// be used in special situations if the window must be repainted while
|
||||||
/// handling a specific event. This occurs on Windows when handling resizes.
|
/// handling a specific event. This occurs on Windows when handling resizes.
|
||||||
|
@ -45,20 +46,28 @@ enum EventResult {
|
||||||
/// `RepaintNow` creates a new frame synchronously, and should therefore
|
/// `RepaintNow` creates a new frame synchronously, and should therefore
|
||||||
/// only be used for extremely urgent repaints.
|
/// only be used for extremely urgent repaints.
|
||||||
RepaintNow,
|
RepaintNow,
|
||||||
|
|
||||||
/// Queues a repaint for once the event loop handles its next redraw. Exists
|
/// Queues a repaint for once the event loop handles its next redraw. Exists
|
||||||
/// so that multiple input events can be handled in one frame. Does not
|
/// so that multiple input events can be handled in one frame. Does not
|
||||||
/// cause any delay like `RepaintNow`.
|
/// cause any delay like `RepaintNow`.
|
||||||
RepaintNext,
|
RepaintNext,
|
||||||
|
|
||||||
RepaintAt(Instant),
|
RepaintAt(Instant),
|
||||||
|
|
||||||
Exit,
|
Exit,
|
||||||
}
|
}
|
||||||
|
|
||||||
trait WinitApp {
|
trait WinitApp {
|
||||||
fn is_focused(&self) -> bool;
|
fn is_focused(&self) -> bool;
|
||||||
|
|
||||||
fn integration(&self) -> Option<&EpiIntegration>;
|
fn integration(&self) -> Option<&EpiIntegration>;
|
||||||
|
|
||||||
fn window(&self) -> Option<&winit::window::Window>;
|
fn window(&self) -> Option<&winit::window::Window>;
|
||||||
|
|
||||||
fn save_and_destroy(&mut self);
|
fn save_and_destroy(&mut self);
|
||||||
|
|
||||||
fn paint(&mut self) -> EventResult;
|
fn paint(&mut self) -> EventResult;
|
||||||
|
|
||||||
fn on_event(
|
fn on_event(
|
||||||
&mut self,
|
&mut self,
|
||||||
event_loop: &EventLoopWindowTarget<UserEvent>,
|
event_loop: &EventLoopWindowTarget<UserEvent>,
|
||||||
|
@ -152,8 +161,8 @@ fn run_and_return(
|
||||||
event => match winit_app.on_event(event_loop, event) {
|
event => match winit_app.on_event(event_loop, event) {
|
||||||
Ok(event_result) => event_result,
|
Ok(event_result) => event_result,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
tracing::error!("Exiting because of error: {err:?} on event {event:?}");
|
||||||
returned_result = Err(err);
|
returned_result = Err(err);
|
||||||
tracing::debug!("Exiting because of an error");
|
|
||||||
EventResult::Exit
|
EventResult::Exit
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -290,27 +299,6 @@ fn run_and_exit(event_loop: EventLoop<UserEvent>, mut winit_app: impl WinitApp +
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn center_window_pos(
|
|
||||||
monitor: Option<winit::monitor::MonitorHandle>,
|
|
||||||
native_options: &mut epi::NativeOptions,
|
|
||||||
) {
|
|
||||||
// Get the current_monitor.
|
|
||||||
if let Some(monitor) = monitor {
|
|
||||||
let monitor_size = monitor.size();
|
|
||||||
let inner_size = native_options
|
|
||||||
.initial_window_size
|
|
||||||
.unwrap_or(egui::Vec2 { x: 800.0, y: 600.0 });
|
|
||||||
if monitor_size.width > 0 && monitor_size.height > 0 {
|
|
||||||
let x = (monitor_size.width - inner_size.x as u32) / 2;
|
|
||||||
let y = (monitor_size.height - inner_size.y as u32) / 2;
|
|
||||||
native_options.initial_window_pos = Some(egui::Pos2 {
|
|
||||||
x: x as _,
|
|
||||||
y: y as _,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/// Run an egui app
|
/// Run an egui app
|
||||||
#[cfg(feature = "glow")]
|
#[cfg(feature = "glow")]
|
||||||
|
@ -318,6 +306,12 @@ mod glow_integration {
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use egui::NumExt as _;
|
use egui::NumExt as _;
|
||||||
|
use glutin::{
|
||||||
|
display::GetGlDisplay,
|
||||||
|
prelude::{GlDisplay, NotCurrentGlContextSurfaceAccessor, PossiblyCurrentGlContext},
|
||||||
|
surface::GlSurface,
|
||||||
|
};
|
||||||
|
use raw_window_handle::HasRawWindowHandle;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
@ -342,132 +336,260 @@ mod glow_integration {
|
||||||
painter: egui_glow::Painter,
|
painter: egui_glow::Painter,
|
||||||
integration: epi_integration::EpiIntegration,
|
integration: epi_integration::EpiIntegration,
|
||||||
app: Box<dyn epi::App>,
|
app: Box<dyn epi::App>,
|
||||||
|
|
||||||
// Conceptually this will be split out eventually so that the rest of the state
|
// Conceptually this will be split out eventually so that the rest of the state
|
||||||
// can be persistent.
|
// can be persistent.
|
||||||
gl_window: GlutinWindowContext,
|
gl_window: GlutinWindowContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This struct will contain both persistent and temporary glutin state.
|
||||||
|
///
|
||||||
|
/// Platform Quirks:
|
||||||
|
/// * Microsoft Windows: requires that we create a window before opengl context.
|
||||||
|
/// * Android: window and surface should be destroyed when we receive a suspend event. recreate on resume event.
|
||||||
|
///
|
||||||
|
/// winit guarantees that we will get a Resumed event on startup on all platforms.
|
||||||
|
/// * Before Resumed event: `gl_config`, `gl_context` can be created at any time. on windows, a window must be created to get `gl_context`.
|
||||||
|
/// * Resumed: `gl_surface` will be created here. `window` will be re-created here for android.
|
||||||
|
/// * Suspended: on android, we drop window + surface. on other platforms, we don't get Suspended event.
|
||||||
|
///
|
||||||
|
/// The setup is divided between the `new` fn and `on_resume` fn. we can just assume that `on_resume` is a continuation of
|
||||||
|
/// `new` fn on all platforms. only on android, do we get multiple resumed events because app can be suspended.
|
||||||
struct GlutinWindowContext {
|
struct GlutinWindowContext {
|
||||||
window: winit::window::Window,
|
builder: winit::window::WindowBuilder,
|
||||||
gl_context: glutin::context::PossiblyCurrentContext,
|
swap_interval: glutin::surface::SwapInterval,
|
||||||
gl_display: glutin::display::Display,
|
gl_config: glutin::config::Config,
|
||||||
gl_surface: glutin::surface::Surface<glutin::surface::WindowSurface>,
|
current_gl_context: Option<glutin::context::PossiblyCurrentContext>,
|
||||||
|
gl_surface: Option<glutin::surface::Surface<glutin::surface::WindowSurface>>,
|
||||||
|
not_current_gl_context: Option<glutin::context::NotCurrentContext>,
|
||||||
|
window: Option<winit::window::Window>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlutinWindowContext {
|
impl GlutinWindowContext {
|
||||||
// refactor this function to use `glutin-winit` crate eventually.
|
/// There is a lot of complexity with opengl creation, so prefer extensivve logging to get all the help we can to debug issues.
|
||||||
// preferably add android support at the same time.
|
///
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn new(
|
unsafe fn new(
|
||||||
winit_window: winit::window::Window,
|
winit_window_builder: winit::window::WindowBuilder,
|
||||||
native_options: &epi::NativeOptions,
|
native_options: &epi::NativeOptions,
|
||||||
|
event_loop: &EventLoopWindowTarget<UserEvent>,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
use glutin::prelude::*;
|
use glutin::prelude::*;
|
||||||
use raw_window_handle::*;
|
// convert native options to glutin options
|
||||||
let hardware_acceleration = match native_options.hardware_acceleration {
|
let hardware_acceleration = match native_options.hardware_acceleration {
|
||||||
crate::HardwareAcceleration::Required => Some(true),
|
crate::HardwareAcceleration::Required => Some(true),
|
||||||
crate::HardwareAcceleration::Preferred => None,
|
crate::HardwareAcceleration::Preferred => None,
|
||||||
crate::HardwareAcceleration::Off => Some(false),
|
crate::HardwareAcceleration::Off => Some(false),
|
||||||
};
|
};
|
||||||
|
|
||||||
let raw_display_handle = winit_window.raw_display_handle();
|
|
||||||
let raw_window_handle = winit_window.raw_window_handle();
|
|
||||||
|
|
||||||
// EGL is crossplatform and the official khronos way
|
|
||||||
// but sometimes platforms/drivers may not have it, so we use back up options where possible.
|
|
||||||
// TODO: check whether we can expose these options as "features", so that users can select the relevant backend they want.
|
|
||||||
|
|
||||||
// try egl and fallback to windows wgl. Windows is the only platform that *requires* window handle to create display.
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
let preference =
|
|
||||||
glutin::display::DisplayApiPreference::EglThenWgl(Some(raw_window_handle));
|
|
||||||
// try egl and fallback to x11 glx
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
let preference = glutin::display::DisplayApiPreference::EglThenGlx(Box::new(
|
|
||||||
winit::platform::unix::register_xlib_error_hook,
|
|
||||||
));
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
let preference = glutin::display::DisplayApiPreference::Cgl;
|
|
||||||
#[cfg(target_os = "android")]
|
|
||||||
let preference = glutin::display::DisplayApiPreference::Egl;
|
|
||||||
|
|
||||||
let gl_display = glutin::display::Display::new(raw_display_handle, preference)?;
|
|
||||||
let swap_interval = if native_options.vsync {
|
let swap_interval = if native_options.vsync {
|
||||||
glutin::surface::SwapInterval::Wait(std::num::NonZeroU32::new(1).unwrap())
|
glutin::surface::SwapInterval::Wait(std::num::NonZeroU32::new(1).unwrap())
|
||||||
} else {
|
} else {
|
||||||
glutin::surface::SwapInterval::DontWait
|
glutin::surface::SwapInterval::DontWait
|
||||||
};
|
};
|
||||||
|
/* opengl setup flow goes like this:
|
||||||
let config_template = glutin::config::ConfigTemplateBuilder::new()
|
1. we create a configuration for opengl "Display" / "Config" creation
|
||||||
|
2. choose between special extensions like glx or egl or wgl and use them to create config/display
|
||||||
|
3. opengl context configuration
|
||||||
|
4. opengl context creation
|
||||||
|
*/
|
||||||
|
// start building config for gl display
|
||||||
|
let config_template_builder = glutin::config::ConfigTemplateBuilder::new()
|
||||||
.prefer_hardware_accelerated(hardware_acceleration)
|
.prefer_hardware_accelerated(hardware_acceleration)
|
||||||
.with_depth_size(native_options.depth_buffer);
|
.with_depth_size(native_options.depth_buffer)
|
||||||
|
.with_stencil_size(native_options.stencil_buffer)
|
||||||
|
.with_transparency(native_options.transparent);
|
||||||
// we don't know if multi sampling option is set. so, check if its more than 0.
|
// we don't know if multi sampling option is set. so, check if its more than 0.
|
||||||
let config_template = if native_options.multisampling > 0 {
|
let config_template_builder = if native_options.multisampling > 0 {
|
||||||
config_template.with_multisampling(
|
config_template_builder.with_multisampling(
|
||||||
native_options
|
native_options
|
||||||
.multisampling
|
.multisampling
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("failed to fit multisamples into u8"),
|
.expect("failed to fit multisamples option of native_options into u8"),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
config_template
|
config_template_builder
|
||||||
};
|
};
|
||||||
let config_template = config_template
|
|
||||||
.with_stencil_size(native_options.stencil_buffer)
|
|
||||||
.with_transparency(native_options.transparent)
|
|
||||||
.compatible_with_native_window(raw_window_handle)
|
|
||||||
.build();
|
|
||||||
// finds all valid configurations supported by this display that match the config_template
|
|
||||||
// this is where we will try to get a "fallback" config if we are okay with ignoring some native
|
|
||||||
// options required by user like multi sampling, srgb, transparency etc..
|
|
||||||
// TODO: need to figure out a good fallback config template
|
|
||||||
let config = gl_display
|
|
||||||
.find_configs(config_template.clone())?
|
|
||||||
.next()
|
|
||||||
.ok_or(crate::Error::NoGlutinConfigs(config_template))?;
|
|
||||||
|
|
||||||
|
tracing::debug!(
|
||||||
|
"trying to create glutin Display with config: {:?}",
|
||||||
|
&config_template_builder
|
||||||
|
);
|
||||||
|
// create gl display. this may probably create a window too on most platforms. definitely on `MS windows`. never on android.
|
||||||
|
let (window, gl_config) = glutin_winit::DisplayBuilder::new()
|
||||||
|
// we might want to expose this option to users in the future. maybe using an env var or using native_options.
|
||||||
|
.with_preference(glutin_winit::ApiPrefence::FallbackEgl) // https://github.com/emilk/egui/issues/2520#issuecomment-1367841150
|
||||||
|
.with_window_builder(Some(winit_window_builder.clone()))
|
||||||
|
.build(
|
||||||
|
event_loop,
|
||||||
|
config_template_builder.clone(),
|
||||||
|
|mut config_iterator| {
|
||||||
|
let config = config_iterator.next().expect(
|
||||||
|
"failed to find a matching configuration for creating glutin config",
|
||||||
|
);
|
||||||
|
tracing::debug!(
|
||||||
|
"using the first config from config picker closure. config: {:?}",
|
||||||
|
&config
|
||||||
|
);
|
||||||
|
config
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.map_err(|e| crate::Error::NoGlutinConfigs(config_template_builder.build(), e))?;
|
||||||
|
|
||||||
|
let gl_display = gl_config.display();
|
||||||
|
tracing::debug!(
|
||||||
|
"successfully created GL Display with version: {} and supported features: {:?}",
|
||||||
|
gl_display.version_string(),
|
||||||
|
gl_display.supported_features()
|
||||||
|
);
|
||||||
|
let raw_window_handle = window.as_ref().map(|w| w.raw_window_handle());
|
||||||
|
tracing::debug!(
|
||||||
|
"creating gl context using raw window handle: {:?}",
|
||||||
|
raw_window_handle
|
||||||
|
);
|
||||||
|
|
||||||
|
// create gl context. if core context cannot be created, try gl es context as fallback.
|
||||||
let context_attributes =
|
let context_attributes =
|
||||||
glutin::context::ContextAttributesBuilder::new().build(Some(raw_window_handle));
|
glutin::context::ContextAttributesBuilder::new().build(raw_window_handle);
|
||||||
// for surface creation.
|
let fallback_context_attributes = glutin::context::ContextAttributesBuilder::new()
|
||||||
let (width, height): (u32, u32) = winit_window.inner_size().into();
|
.with_context_api(glutin::context::ContextApi::Gles(None))
|
||||||
|
.build(raw_window_handle);
|
||||||
|
let gl_context = match gl_config
|
||||||
|
.display()
|
||||||
|
.create_context(&gl_config, &context_attributes)
|
||||||
|
{
|
||||||
|
Ok(it) => it,
|
||||||
|
Err(err) => {
|
||||||
|
tracing::warn!("failed to create context using default context attributes {context_attributes:?} due to error: {err}");
|
||||||
|
tracing::debug!("retrying with fallback context attributes: {fallback_context_attributes:?}");
|
||||||
|
gl_config
|
||||||
|
.display()
|
||||||
|
.create_context(&gl_config, &fallback_context_attributes)?
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let not_current_gl_context = Some(gl_context);
|
||||||
|
|
||||||
|
// the fun part with opengl gl is that we never know whether there is an error. the context creation might have failed, but
|
||||||
|
// it could keep working until we try to make surface current or swap buffers or something else. future glutin improvements might
|
||||||
|
// help us start from scratch again if we fail context creation and go back to preferEgl or try with different config etc..
|
||||||
|
// https://github.com/emilk/egui/pull/2541#issuecomment-1370767582
|
||||||
|
Ok(GlutinWindowContext {
|
||||||
|
builder: winit_window_builder,
|
||||||
|
swap_interval,
|
||||||
|
gl_config,
|
||||||
|
current_gl_context: None,
|
||||||
|
window,
|
||||||
|
gl_surface: None,
|
||||||
|
not_current_gl_context,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This will be run after `new`. on android, it might be called multiple times over the course of the app's lifetime.
|
||||||
|
/// roughly,
|
||||||
|
/// 1. check if window already exists. otherwise, create one now.
|
||||||
|
/// 2. create attributes for surface creation.
|
||||||
|
/// 3. create surface.
|
||||||
|
/// 4. make surface and context current.
|
||||||
|
///
|
||||||
|
/// we presently assume that we will
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
fn on_resume(&mut self, event_loop: &EventLoopWindowTarget<UserEvent>) -> Result<()> {
|
||||||
|
if self.gl_surface.is_some() {
|
||||||
|
tracing::warn!(
|
||||||
|
"on_resume called even thought we already have a surface. early return"
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
tracing::debug!("running on_resume fn.");
|
||||||
|
// make sure we have a window or create one.
|
||||||
|
let window = self.window.take().unwrap_or_else(|| {
|
||||||
|
tracing::debug!("window doesn't exist yet. creating one now with finalize_window");
|
||||||
|
glutin_winit::finalize_window(event_loop, self.builder.clone(), &self.gl_config)
|
||||||
|
.expect("failed to finalize glutin window")
|
||||||
|
});
|
||||||
|
// surface attributes
|
||||||
|
let (width, height): (u32, u32) = window.inner_size().into();
|
||||||
let width = std::num::NonZeroU32::new(width.at_least(1)).unwrap();
|
let width = std::num::NonZeroU32::new(width.at_least(1)).unwrap();
|
||||||
let height = std::num::NonZeroU32::new(height.at_least(1)).unwrap();
|
let height = std::num::NonZeroU32::new(height.at_least(1)).unwrap();
|
||||||
let surface_attributes =
|
let surface_attributes =
|
||||||
glutin::surface::SurfaceAttributesBuilder::<glutin::surface::WindowSurface>::new()
|
glutin::surface::SurfaceAttributesBuilder::<glutin::surface::WindowSurface>::new()
|
||||||
.build(raw_window_handle, width, height);
|
.build(window.raw_window_handle(), width, height);
|
||||||
// start creating the gl objects
|
tracing::debug!(
|
||||||
let gl_context = gl_display.create_context(&config, &context_attributes)?;
|
"creating surface with attributes: {:?}",
|
||||||
|
&surface_attributes
|
||||||
|
);
|
||||||
|
// create surface
|
||||||
|
let gl_surface = unsafe {
|
||||||
|
self.gl_config
|
||||||
|
.display()
|
||||||
|
.create_window_surface(&self.gl_config, &surface_attributes)?
|
||||||
|
};
|
||||||
|
tracing::debug!("surface created successfully: {gl_surface:?}.making context current");
|
||||||
|
// make surface and context current.
|
||||||
|
let not_current_gl_context = self
|
||||||
|
.not_current_gl_context
|
||||||
|
.take()
|
||||||
|
.expect("failed to get not current context after resume event. impossible!");
|
||||||
|
let current_gl_context = not_current_gl_context.make_current(&gl_surface)?;
|
||||||
|
// try setting swap interval. but its not absolutely necessary, so don't panic on failure.
|
||||||
|
tracing::debug!("made context current. setting swap interval for surface");
|
||||||
|
if let Err(e) = gl_surface.set_swap_interval(¤t_gl_context, self.swap_interval) {
|
||||||
|
tracing::error!("failed to set swap interval due to error: {e:?}");
|
||||||
|
}
|
||||||
|
// we will reach this point only once in most platforms except android.
|
||||||
|
// create window/surface/make context current once and just use them forever.
|
||||||
|
self.gl_surface = Some(gl_surface);
|
||||||
|
self.current_gl_context = Some(current_gl_context);
|
||||||
|
self.window = Some(window);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
let gl_surface = gl_display.create_window_surface(&config, &surface_attributes)?;
|
/// only applies for android. but we basically drop surface + window and make context not current
|
||||||
let gl_context = gl_context.make_current(&gl_surface)?;
|
fn on_suspend(&mut self) -> Result<()> {
|
||||||
gl_surface.set_swap_interval(&gl_context, swap_interval)?;
|
tracing::debug!("received suspend event. dropping window and surface");
|
||||||
Ok(GlutinWindowContext {
|
self.gl_surface.take();
|
||||||
window: winit_window,
|
self.window.take();
|
||||||
gl_context,
|
if let Some(current) = self.current_gl_context.take() {
|
||||||
gl_display,
|
tracing::debug!("context is current, so making it non-current");
|
||||||
gl_surface,
|
self.not_current_gl_context = Some(current.make_not_current()?);
|
||||||
})
|
} else {
|
||||||
|
tracing::debug!(
|
||||||
|
"context is already not current??? could be duplicate suspend event"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn window(&self) -> &winit::window::Window {
|
fn window(&self) -> &winit::window::Window {
|
||||||
&self.window
|
self.window.as_ref().expect("winit window doesn't exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resize(&self, physical_size: winit::dpi::PhysicalSize<u32>) {
|
fn resize(&self, physical_size: winit::dpi::PhysicalSize<u32>) {
|
||||||
use glutin::surface::GlSurface;
|
|
||||||
let width = std::num::NonZeroU32::new(physical_size.width.at_least(1)).unwrap();
|
let width = std::num::NonZeroU32::new(physical_size.width.at_least(1)).unwrap();
|
||||||
let height = std::num::NonZeroU32::new(physical_size.height.at_least(1)).unwrap();
|
let height = std::num::NonZeroU32::new(physical_size.height.at_least(1)).unwrap();
|
||||||
self.gl_surface.resize(&self.gl_context, width, height);
|
self.gl_surface
|
||||||
|
.as_ref()
|
||||||
|
.expect("failed to get surface to resize")
|
||||||
|
.resize(
|
||||||
|
self.current_gl_context
|
||||||
|
.as_ref()
|
||||||
|
.expect("failed to get current context to resize surface"),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn swap_buffers(&self) -> glutin::error::Result<()> {
|
fn swap_buffers(&self) -> glutin::error::Result<()> {
|
||||||
use glutin::surface::GlSurface;
|
self.gl_surface
|
||||||
self.gl_surface.swap_buffers(&self.gl_context)
|
.as_ref()
|
||||||
|
.expect("failed to get surface to swap buffers")
|
||||||
|
.swap_buffers(
|
||||||
|
self.current_gl_context
|
||||||
|
.as_ref()
|
||||||
|
.expect("failed to get current context to swap buffers"),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_proc_address(&self, addr: &std::ffi::CStr) -> *const std::ffi::c_void {
|
fn get_proc_address(&self, addr: &std::ffi::CStr) -> *const std::ffi::c_void {
|
||||||
use glutin::display::GlDisplay;
|
self.gl_config.display().get_proc_address(addr)
|
||||||
self.gl_display.get_proc_address(addr)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -515,12 +637,17 @@ mod glow_integration {
|
||||||
|
|
||||||
let window_settings = epi_integration::load_window_settings(storage);
|
let window_settings = epi_integration::load_window_settings(storage);
|
||||||
|
|
||||||
let winit_window =
|
let winit_window_builder =
|
||||||
epi_integration::window_builder(event_loop, title, native_options, window_settings)
|
epi_integration::window_builder(event_loop, title, native_options, window_settings);
|
||||||
.build(event_loop)?;
|
let mut glutin_window_context = unsafe {
|
||||||
// a lot of the code below has been lifted from glutin example in their repo.
|
GlutinWindowContext::new(winit_window_builder, native_options, event_loop)?
|
||||||
let glutin_window_context =
|
};
|
||||||
unsafe { GlutinWindowContext::new(winit_window, native_options)? };
|
glutin_window_context.on_resume(event_loop)?;
|
||||||
|
|
||||||
|
if let Some(window) = &glutin_window_context.window {
|
||||||
|
epi_integration::apply_native_options_to_window(window, native_options);
|
||||||
|
}
|
||||||
|
|
||||||
let gl = unsafe {
|
let gl = unsafe {
|
||||||
glow::Context::from_loader_function(|s| {
|
glow::Context::from_loader_function(|s| {
|
||||||
let s = std::ffi::CString::new(s)
|
let s = std::ffi::CString::new(s)
|
||||||
|
@ -749,26 +876,24 @@ mod glow_integration {
|
||||||
) -> Result<EventResult> {
|
) -> Result<EventResult> {
|
||||||
Ok(match event {
|
Ok(match event {
|
||||||
winit::event::Event::Resumed => {
|
winit::event::Event::Resumed => {
|
||||||
|
// first resume event.
|
||||||
|
// we can actually move this outside of event loop.
|
||||||
|
// and just run the on_resume fn of gl_window
|
||||||
if self.running.is_none() {
|
if self.running.is_none() {
|
||||||
self.init_run_state(event_loop)?;
|
self.init_run_state(event_loop)?;
|
||||||
|
} else {
|
||||||
|
// not the first resume event. create whatever you need.
|
||||||
|
self.running
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.gl_window
|
||||||
|
.on_resume(event_loop)?;
|
||||||
}
|
}
|
||||||
EventResult::RepaintNow
|
EventResult::RepaintNow
|
||||||
}
|
}
|
||||||
winit::event::Event::Suspended => {
|
winit::event::Event::Suspended => {
|
||||||
#[cfg(target_os = "android")]
|
self.running.as_mut().unwrap().gl_window.on_suspend()?;
|
||||||
{
|
|
||||||
tracing::error!("Suspended app can't destroy Window surface state with current Egui Glow backend (undefined behaviour)");
|
|
||||||
// Instead of destroying everything which we _know_ we can't re-create
|
|
||||||
// we instead currently just try our luck with not destroying anything.
|
|
||||||
//
|
|
||||||
// When the application resumes then it will get a new `SurfaceView` but
|
|
||||||
// we have no practical way currently of creating a new EGL surface
|
|
||||||
// via the Glutin API while keeping the GL context and the rest of
|
|
||||||
// our app state. This will likely result in a black screen or
|
|
||||||
// frozen screen.
|
|
||||||
//
|
|
||||||
//self.running = None;
|
|
||||||
}
|
|
||||||
EventResult::Wait
|
EventResult::Wait
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -863,22 +988,13 @@ mod glow_integration {
|
||||||
app_creator: epi::AppCreator,
|
app_creator: epi::AppCreator,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if native_options.run_and_return {
|
if native_options.run_and_return {
|
||||||
with_event_loop(native_options, |event_loop, mut native_options| {
|
with_event_loop(native_options, |event_loop, native_options| {
|
||||||
if native_options.centered {
|
|
||||||
center_window_pos(event_loop.available_monitors().next(), &mut native_options);
|
|
||||||
}
|
|
||||||
|
|
||||||
let glow_eframe =
|
let glow_eframe =
|
||||||
GlowWinitApp::new(event_loop, app_name, native_options, app_creator);
|
GlowWinitApp::new(event_loop, app_name, native_options, app_creator);
|
||||||
run_and_return(event_loop, glow_eframe)
|
run_and_return(event_loop, glow_eframe)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
let event_loop = create_event_loop_builder(&mut native_options).build();
|
let event_loop = create_event_loop_builder(&mut native_options).build();
|
||||||
|
|
||||||
if native_options.centered {
|
|
||||||
center_window_pos(event_loop.available_monitors().next(), &mut native_options);
|
|
||||||
}
|
|
||||||
|
|
||||||
let glow_eframe = GlowWinitApp::new(&event_loop, app_name, native_options, app_creator);
|
let glow_eframe = GlowWinitApp::new(&event_loop, app_name, native_options, app_creator);
|
||||||
run_and_exit(event_loop, glow_eframe);
|
run_and_exit(event_loop, glow_eframe);
|
||||||
}
|
}
|
||||||
|
@ -946,19 +1062,20 @@ mod wgpu_integration {
|
||||||
storage: Option<&dyn epi::Storage>,
|
storage: Option<&dyn epi::Storage>,
|
||||||
title: &str,
|
title: &str,
|
||||||
native_options: &NativeOptions,
|
native_options: &NativeOptions,
|
||||||
) -> Result<winit::window::Window> {
|
) -> std::result::Result<winit::window::Window, winit::error::OsError> {
|
||||||
let window_settings = epi_integration::load_window_settings(storage);
|
let window_settings = epi_integration::load_window_settings(storage);
|
||||||
Ok(
|
let window_builder =
|
||||||
epi_integration::window_builder(event_loop, title, native_options, window_settings)
|
epi_integration::window_builder(event_loop, title, native_options, window_settings);
|
||||||
.build(event_loop)?,
|
let window = window_builder.build(event_loop)?;
|
||||||
)
|
epi_integration::apply_native_options_to_window(&window, native_options);
|
||||||
|
Ok(window)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn set_window(
|
fn set_window(
|
||||||
&mut self,
|
&mut self,
|
||||||
window: winit::window::Window,
|
window: winit::window::Window,
|
||||||
) -> std::result::Result<(), wgpu::RequestDeviceError> {
|
) -> std::result::Result<(), egui_wgpu::WgpuError> {
|
||||||
self.window = Some(window);
|
self.window = Some(window);
|
||||||
if let Some(running) = &mut self.running {
|
if let Some(running) = &mut self.running {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -970,7 +1087,7 @@ mod wgpu_integration {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
fn drop_window(&mut self) -> std::result::Result<(), wgpu::RequestDeviceError> {
|
fn drop_window(&mut self) -> std::result::Result<(), egui_wgpu::WgpuError> {
|
||||||
self.window = None;
|
self.window = None;
|
||||||
if let Some(running) = &mut self.running {
|
if let Some(running) = &mut self.running {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -985,13 +1102,14 @@ mod wgpu_integration {
|
||||||
event_loop: &EventLoopWindowTarget<UserEvent>,
|
event_loop: &EventLoopWindowTarget<UserEvent>,
|
||||||
storage: Option<Box<dyn epi::Storage>>,
|
storage: Option<Box<dyn epi::Storage>>,
|
||||||
window: winit::window::Window,
|
window: winit::window::Window,
|
||||||
) -> std::result::Result<(), wgpu::RequestDeviceError> {
|
) -> std::result::Result<(), egui_wgpu::WgpuError> {
|
||||||
#[allow(unsafe_code, unused_mut, unused_unsafe)]
|
#[allow(unsafe_code, unused_mut, unused_unsafe)]
|
||||||
let painter = unsafe {
|
let painter = unsafe {
|
||||||
let mut painter = egui_wgpu::winit::Painter::new(
|
let mut painter = egui_wgpu::winit::Painter::new(
|
||||||
self.native_options.wgpu_options.clone(),
|
self.native_options.wgpu_options.clone(),
|
||||||
self.native_options.multisampling.max(1) as _,
|
self.native_options.multisampling.max(1) as _,
|
||||||
self.native_options.depth_buffer,
|
self.native_options.depth_buffer,
|
||||||
|
self.native_options.transparent,
|
||||||
);
|
);
|
||||||
pollster::block_on(painter.set_window(Some(&window)))?;
|
pollster::block_on(painter.set_window(Some(&window)))?;
|
||||||
painter
|
painter
|
||||||
|
@ -1286,22 +1404,13 @@ mod wgpu_integration {
|
||||||
app_creator: epi::AppCreator,
|
app_creator: epi::AppCreator,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if native_options.run_and_return {
|
if native_options.run_and_return {
|
||||||
with_event_loop(native_options, |event_loop, mut native_options| {
|
with_event_loop(native_options, |event_loop, native_options| {
|
||||||
if native_options.centered {
|
|
||||||
center_window_pos(event_loop.available_monitors().next(), &mut native_options);
|
|
||||||
}
|
|
||||||
|
|
||||||
let wgpu_eframe =
|
let wgpu_eframe =
|
||||||
WgpuWinitApp::new(event_loop, app_name, native_options, app_creator);
|
WgpuWinitApp::new(event_loop, app_name, native_options, app_creator);
|
||||||
run_and_return(event_loop, wgpu_eframe)
|
run_and_return(event_loop, wgpu_eframe)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
let event_loop = create_event_loop_builder(&mut native_options).build();
|
let event_loop = create_event_loop_builder(&mut native_options).build();
|
||||||
|
|
||||||
if native_options.centered {
|
|
||||||
center_window_pos(event_loop.available_monitors().next(), &mut native_options);
|
|
||||||
}
|
|
||||||
|
|
||||||
let wgpu_eframe = WgpuWinitApp::new(&event_loop, app_name, native_options, app_creator);
|
let wgpu_eframe = WgpuWinitApp::new(&event_loop, app_name, native_options, app_creator);
|
||||||
run_and_exit(event_loop, wgpu_eframe);
|
run_and_exit(event_loop, wgpu_eframe);
|
||||||
}
|
}
|
||||||
|
|
|
@ -450,8 +450,6 @@ pub enum EventToUnsubscribe {
|
||||||
|
|
||||||
impl EventToUnsubscribe {
|
impl EventToUnsubscribe {
|
||||||
pub fn unsubscribe(self) -> Result<(), JsValue> {
|
pub fn unsubscribe(self) -> Result<(), JsValue> {
|
||||||
use wasm_bindgen::JsCast;
|
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
EventToUnsubscribe::TargetEvent(handle) => {
|
EventToUnsubscribe::TargetEvent(handle) => {
|
||||||
handle.target.remove_event_listener_with_callback(
|
handle.target.remove_event_listener_with_callback(
|
||||||
|
@ -468,6 +466,7 @@ impl EventToUnsubscribe {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppRunnerContainer {
|
pub struct AppRunnerContainer {
|
||||||
pub runner: AppRunnerRef,
|
pub runner: AppRunnerRef,
|
||||||
|
|
||||||
|
@ -486,8 +485,6 @@ impl AppRunnerContainer {
|
||||||
event_name: &'static str,
|
event_name: &'static str,
|
||||||
mut closure: impl FnMut(E, MutexGuard<'_, AppRunner>) + 'static,
|
mut closure: impl FnMut(E, MutexGuard<'_, AppRunner>) + 'static,
|
||||||
) -> Result<(), JsValue> {
|
) -> Result<(), JsValue> {
|
||||||
use wasm_bindgen::JsCast;
|
|
||||||
|
|
||||||
// Create a JS closure based on the FnMut provided
|
// Create a JS closure based on the FnMut provided
|
||||||
let closure = Closure::wrap({
|
let closure = Closure::wrap({
|
||||||
// Clone atomics
|
// Clone atomics
|
||||||
|
|
|
@ -31,7 +31,6 @@ pub fn paint_and_schedule(
|
||||||
runner_ref: AppRunnerRef,
|
runner_ref: AppRunnerRef,
|
||||||
panicked: Arc<AtomicBool>,
|
panicked: Arc<AtomicBool>,
|
||||||
) -> Result<(), JsValue> {
|
) -> Result<(), JsValue> {
|
||||||
use wasm_bindgen::JsCast;
|
|
||||||
let window = web_sys::window().unwrap();
|
let window = web_sys::window().unwrap();
|
||||||
let closure = Closure::once(move || paint_and_schedule(&runner_ref, panicked));
|
let closure = Closure::once(move || paint_and_schedule(&runner_ref, panicked));
|
||||||
window.request_animation_frame(closure.as_ref().unchecked_ref())?;
|
window.request_animation_frame(closure.as_ref().unchecked_ref())?;
|
||||||
|
@ -95,7 +94,12 @@ pub fn install_document_events(runner_container: &mut AppRunnerContainer) -> Res
|
||||||
// egui wants to use tab to move to the next text field.
|
// egui wants to use tab to move to the next text field.
|
||||||
true
|
true
|
||||||
} else if egui_key == Some(Key::P) {
|
} else if egui_key == Some(Key::P) {
|
||||||
|
#[allow(clippy::needless_bool)]
|
||||||
|
if modifiers.ctrl || modifiers.command || modifiers.mac_cmd {
|
||||||
true // Prevent ctrl-P opening the print dialog. Users may want to use it for a command palette.
|
true // Prevent ctrl-P opening the print dialog. Users may want to use it for a command palette.
|
||||||
|
} else {
|
||||||
|
false // let normal P:s through
|
||||||
|
}
|
||||||
} else if egui_wants_keyboard {
|
} else if egui_wants_keyboard {
|
||||||
matches!(
|
matches!(
|
||||||
event.key().as_str(),
|
event.key().as_str(),
|
||||||
|
@ -404,7 +408,7 @@ pub fn install_canvas_events(runner_container: &mut AppRunnerContainer) -> Resul
|
||||||
}
|
}
|
||||||
web_sys::WheelEvent::DOM_DELTA_LINE => {
|
web_sys::WheelEvent::DOM_DELTA_LINE => {
|
||||||
#[allow(clippy::let_and_return)]
|
#[allow(clippy::let_and_return)]
|
||||||
let points_per_scroll_line = 8.0; // Note that this is intentionally different from what we use in egui_glium / winit.
|
let points_per_scroll_line = 8.0; // Note that this is intentionally different from what we use in winit.
|
||||||
points_per_scroll_line
|
points_per_scroll_line
|
||||||
}
|
}
|
||||||
_ => 1.0, // DOM_DELTA_PIXEL
|
_ => 1.0, // DOM_DELTA_PIXEL
|
||||||
|
|
|
@ -83,7 +83,6 @@ pub fn system_theme() -> Option<Theme> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn canvas_element(canvas_id: &str) -> Option<web_sys::HtmlCanvasElement> {
|
pub fn canvas_element(canvas_id: &str) -> Option<web_sys::HtmlCanvasElement> {
|
||||||
use wasm_bindgen::JsCast;
|
|
||||||
let document = web_sys::window()?.document()?;
|
let document = web_sys::window()?.document()?;
|
||||||
let canvas = document.get_element_by_id(canvas_id)?;
|
let canvas = document.get_element_by_id(canvas_id)?;
|
||||||
canvas.dyn_into::<web_sys::HtmlCanvasElement>().ok()
|
canvas.dyn_into::<web_sys::HtmlCanvasElement>().ok()
|
||||||
|
|
|
@ -10,7 +10,6 @@ use wasm_bindgen::prelude::*;
|
||||||
static AGENT_ID: &str = "egui_text_agent";
|
static AGENT_ID: &str = "egui_text_agent";
|
||||||
|
|
||||||
pub fn text_agent() -> web_sys::HtmlInputElement {
|
pub fn text_agent() -> web_sys::HtmlInputElement {
|
||||||
use wasm_bindgen::JsCast;
|
|
||||||
web_sys::window()
|
web_sys::window()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.document()
|
.document()
|
||||||
|
@ -23,7 +22,6 @@ pub fn text_agent() -> web_sys::HtmlInputElement {
|
||||||
|
|
||||||
/// Text event handler,
|
/// Text event handler,
|
||||||
pub fn install_text_agent(runner_container: &mut AppRunnerContainer) -> Result<(), JsValue> {
|
pub fn install_text_agent(runner_container: &mut AppRunnerContainer) -> Result<(), JsValue> {
|
||||||
use wasm_bindgen::JsCast;
|
|
||||||
let window = web_sys::window().unwrap();
|
let window = web_sys::window().unwrap();
|
||||||
let document = window.document().unwrap();
|
let document = window.document().unwrap();
|
||||||
let body = document.body().expect("document should have a body");
|
let body = document.body().expect("document should have a body");
|
||||||
|
@ -129,7 +127,6 @@ pub fn install_text_agent(runner_container: &mut AppRunnerContainer) -> Result<(
|
||||||
|
|
||||||
/// Focus or blur text agent to toggle mobile keyboard.
|
/// Focus or blur text agent to toggle mobile keyboard.
|
||||||
pub fn update_text_agent(runner: MutexGuard<'_, AppRunner>) -> Option<()> {
|
pub fn update_text_agent(runner: MutexGuard<'_, AppRunner>) -> Option<()> {
|
||||||
use wasm_bindgen::JsCast;
|
|
||||||
use web_sys::HtmlInputElement;
|
use web_sys::HtmlInputElement;
|
||||||
let window = web_sys::window()?;
|
let window = web_sys::window()?;
|
||||||
let document = window.document()?;
|
let document = window.document()?;
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use egui::Rgba;
|
|
||||||
use wasm_bindgen::JsValue;
|
use wasm_bindgen::JsValue;
|
||||||
|
|
||||||
/// Renderer for a browser canvas.
|
/// Renderer for a browser canvas.
|
||||||
|
@ -19,7 +18,7 @@ pub(crate) trait WebPainter {
|
||||||
/// Update all internal textures and paint gui.
|
/// Update all internal textures and paint gui.
|
||||||
fn paint_and_update_textures(
|
fn paint_and_update_textures(
|
||||||
&mut self,
|
&mut self,
|
||||||
clear_color: Rgba,
|
clear_color: [f32; 4],
|
||||||
clipped_primitives: &[egui::ClippedPrimitive],
|
clipped_primitives: &[egui::ClippedPrimitive],
|
||||||
pixels_per_point: f32,
|
pixels_per_point: f32,
|
||||||
textures_delta: &egui::TexturesDelta,
|
textures_delta: &egui::TexturesDelta,
|
||||||
|
|
|
@ -2,7 +2,6 @@ use wasm_bindgen::JsCast;
|
||||||
use wasm_bindgen::JsValue;
|
use wasm_bindgen::JsValue;
|
||||||
use web_sys::HtmlCanvasElement;
|
use web_sys::HtmlCanvasElement;
|
||||||
|
|
||||||
use egui::Rgba;
|
|
||||||
use egui_glow::glow;
|
use egui_glow::glow;
|
||||||
|
|
||||||
use crate::{WebGlContextOption, WebOptions};
|
use crate::{WebGlContextOption, WebOptions};
|
||||||
|
@ -49,7 +48,7 @@ impl WebPainter for WebPainterGlow {
|
||||||
|
|
||||||
fn paint_and_update_textures(
|
fn paint_and_update_textures(
|
||||||
&mut self,
|
&mut self,
|
||||||
clear_color: Rgba,
|
clear_color: [f32; 4],
|
||||||
clipped_primitives: &[egui::ClippedPrimitive],
|
clipped_primitives: &[egui::ClippedPrimitive],
|
||||||
pixels_per_point: f32,
|
pixels_per_point: f32,
|
||||||
textures_delta: &egui::TexturesDelta,
|
textures_delta: &egui::TexturesDelta,
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||||
use wasm_bindgen::JsValue;
|
use wasm_bindgen::JsValue;
|
||||||
use web_sys::HtmlCanvasElement;
|
use web_sys::HtmlCanvasElement;
|
||||||
|
|
||||||
use egui::{mutex::RwLock, Rgba};
|
use egui::mutex::RwLock;
|
||||||
use egui_wgpu::{renderer::ScreenDescriptor, RenderState, SurfaceErrorAction};
|
use egui_wgpu::{renderer::ScreenDescriptor, RenderState, SurfaceErrorAction};
|
||||||
|
|
||||||
use crate::WebOptions;
|
use crate::WebOptions;
|
||||||
|
@ -49,6 +49,7 @@ impl WebPainterWgpu {
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format: depth_format,
|
format: depth_format,
|
||||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||||
|
view_formats: &[depth_format],
|
||||||
})
|
})
|
||||||
.create_view(&wgpu::TextureViewDescriptor::default())
|
.create_view(&wgpu::TextureViewDescriptor::default())
|
||||||
})
|
})
|
||||||
|
@ -60,8 +61,13 @@ impl WebPainterWgpu {
|
||||||
|
|
||||||
let canvas = super::canvas_element_or_die(canvas_id);
|
let canvas = super::canvas_element_or_die(canvas_id);
|
||||||
|
|
||||||
let instance = wgpu::Instance::new(options.wgpu_options.backends);
|
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
||||||
let surface = instance.create_surface_from_canvas(&canvas);
|
backends: options.wgpu_options.backends,
|
||||||
|
dx12_shader_compiler: Default::default(),
|
||||||
|
});
|
||||||
|
let surface = instance
|
||||||
|
.create_surface_from_canvas(&canvas)
|
||||||
|
.map_err(|err| format!("failed to create wgpu surface: {err}"))?;
|
||||||
|
|
||||||
let adapter = instance
|
let adapter = instance
|
||||||
.request_adapter(&wgpu::RequestAdapterOptions {
|
.request_adapter(&wgpu::RequestAdapterOptions {
|
||||||
|
@ -81,7 +87,7 @@ impl WebPainterWgpu {
|
||||||
.map_err(|err| format!("Failed to find wgpu device: {}", err))?;
|
.map_err(|err| format!("Failed to find wgpu device: {}", err))?;
|
||||||
|
|
||||||
let target_format =
|
let target_format =
|
||||||
egui_wgpu::preferred_framebuffer_format(&surface.get_supported_formats(&adapter));
|
egui_wgpu::preferred_framebuffer_format(&surface.get_capabilities(&adapter).formats);
|
||||||
|
|
||||||
let depth_format = options.wgpu_options.depth_format;
|
let depth_format = options.wgpu_options.depth_format;
|
||||||
let renderer = egui_wgpu::Renderer::new(&device, target_format, depth_format, 1);
|
let renderer = egui_wgpu::Renderer::new(&device, target_format, depth_format, 1);
|
||||||
|
@ -99,6 +105,7 @@ impl WebPainterWgpu {
|
||||||
height: 0,
|
height: 0,
|
||||||
present_mode: options.wgpu_options.present_mode,
|
present_mode: options.wgpu_options.present_mode,
|
||||||
alpha_mode: wgpu::CompositeAlphaMode::Auto,
|
alpha_mode: wgpu::CompositeAlphaMode::Auto,
|
||||||
|
view_formats: vec![target_format],
|
||||||
};
|
};
|
||||||
|
|
||||||
tracing::debug!("wgpu painter initialized.");
|
tracing::debug!("wgpu painter initialized.");
|
||||||
|
@ -128,7 +135,7 @@ impl WebPainter for WebPainterWgpu {
|
||||||
|
|
||||||
fn paint_and_update_textures(
|
fn paint_and_update_textures(
|
||||||
&mut self,
|
&mut self,
|
||||||
clear_color: Rgba,
|
clear_color: [f32; 4],
|
||||||
clipped_primitives: &[egui::ClippedPrimitive],
|
clipped_primitives: &[egui::ClippedPrimitive],
|
||||||
pixels_per_point: f32,
|
pixels_per_point: f32,
|
||||||
textures_delta: &egui::TexturesDelta,
|
textures_delta: &egui::TexturesDelta,
|
||||||
|
@ -221,10 +228,10 @@ impl WebPainter for WebPainterWgpu {
|
||||||
resolve_target: None,
|
resolve_target: None,
|
||||||
ops: wgpu::Operations {
|
ops: wgpu::Operations {
|
||||||
load: wgpu::LoadOp::Clear(wgpu::Color {
|
load: wgpu::LoadOp::Clear(wgpu::Color {
|
||||||
r: clear_color.r() as f64,
|
r: clear_color[0] as f64,
|
||||||
g: clear_color.g() as f64,
|
g: clear_color[1] as f64,
|
||||||
b: clear_color.b() as f64,
|
b: clear_color[2] as f64,
|
||||||
a: clear_color.a() as f64,
|
a: clear_color[3] as f64,
|
||||||
}),
|
}),
|
||||||
store: true,
|
store: true,
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,9 +3,14 @@ All notable changes to the `egui-wgpu` integration will be noted in this file.
|
||||||
|
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
|
||||||
|
## 0.21.0 - 2023-02-08
|
||||||
|
* Update to `wgpu` 0.15 ([#2629](https://github.com/emilk/egui/pull/2629))
|
||||||
* Return `Err` instead of panic if we can't find a device ([#2428](https://github.com/emilk/egui/pull/2428)).
|
* Return `Err` instead of panic if we can't find a device ([#2428](https://github.com/emilk/egui/pull/2428)).
|
||||||
* `winit::Painter::set_window` is now `async` ([#2434](https://github.com/emilk/egui/pull/2434)).
|
* `winit::Painter::set_window` is now `async` ([#2434](https://github.com/emilk/egui/pull/2434)).
|
||||||
* `egui-wgpu` now only depends on `epaint` instead of the entire `egui` ([#2438](https://github.com/emilk/egui/pull/2438)).
|
* `egui-wgpu` now only depends on `epaint` instead of the entire `egui` ([#2438](https://github.com/emilk/egui/pull/2438)).
|
||||||
|
* `winit::Painter` now supports transparent backbuffer ([#2684](https://github.com/emilk/egui/pull/2684)).
|
||||||
|
|
||||||
|
|
||||||
## 0.20.0 - 2022-12-08 - web support
|
## 0.20.0 - 2022-12-08 - web support
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "egui-wgpu"
|
name = "egui-wgpu"
|
||||||
version = "0.20.0"
|
version = "0.21.0"
|
||||||
description = "Bindings for using egui natively using the wgpu library"
|
description = "Bindings for using egui natively using the wgpu library"
|
||||||
authors = [
|
authors = [
|
||||||
"Nils Hasenbanck <nils@hasenbanck.de>",
|
"Nils Hasenbanck <nils@hasenbanck.de>",
|
||||||
|
@ -36,20 +36,20 @@ winit = ["dep:winit"]
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
epaint = { version = "0.20.0", path = "../epaint", default-features = false, features = [
|
epaint = { version = "0.21.0", path = "../epaint", default-features = false, features = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
] }
|
] }
|
||||||
|
|
||||||
bytemuck = "1.7"
|
bytemuck = "1.7"
|
||||||
tracing = { version = "0.1", default-features = false, features = ["std"] }
|
tracing = { version = "0.1", default-features = false, features = ["std"] }
|
||||||
type-map = "0.5.0"
|
type-map = "0.5.0"
|
||||||
wgpu = "0.14"
|
wgpu = "0.15.0"
|
||||||
|
|
||||||
#! ### Optional dependencies
|
#! ### Optional dependencies
|
||||||
## Enable this when generating docs.
|
## Enable this when generating docs.
|
||||||
document-features = { version = "0.2", optional = true }
|
document-features = { version = "0.2", optional = true }
|
||||||
|
|
||||||
winit = { version = "0.27.2", optional = true }
|
winit = { version = "0.28", optional = true }
|
||||||
|
|
||||||
# Native:
|
# Native:
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
|
|
|
@ -99,7 +99,39 @@ pub fn preferred_framebuffer_format(formats: &[wgpu::TextureFormat]) -> wgpu::Te
|
||||||
}
|
}
|
||||||
formats[0] // take the first
|
formats[0] // take the first
|
||||||
}
|
}
|
||||||
|
// maybe use this-error?
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum WgpuError {
|
||||||
|
DeviceError(wgpu::RequestDeviceError),
|
||||||
|
SurfaceError(wgpu::CreateSurfaceError),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for WgpuError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
std::fmt::Debug::fmt(self, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for WgpuError {
|
||||||
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
|
match self {
|
||||||
|
WgpuError::DeviceError(e) => e.source(),
|
||||||
|
WgpuError::SurfaceError(e) => e.source(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<wgpu::RequestDeviceError> for WgpuError {
|
||||||
|
fn from(e: wgpu::RequestDeviceError) -> Self {
|
||||||
|
Self::DeviceError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<wgpu::CreateSurfaceError> for WgpuError {
|
||||||
|
fn from(e: wgpu::CreateSurfaceError) -> Self {
|
||||||
|
Self::SurfaceError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
/// Profiling macro for feature "puffin"
|
/// Profiling macro for feature "puffin"
|
||||||
|
|
|
@ -554,6 +554,7 @@ impl Renderer {
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format: wgpu::TextureFormat::Rgba8UnormSrgb, // Minspec for wgpu WebGL emulation is WebGL2, so this should always be supported.
|
format: wgpu::TextureFormat::Rgba8UnormSrgb, // Minspec for wgpu WebGL emulation is WebGL2, so this should always be supported.
|
||||||
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
||||||
|
view_formats: &[wgpu::TextureFormat::Rgba8UnormSrgb],
|
||||||
});
|
});
|
||||||
let sampler = self
|
let sampler = self
|
||||||
.samplers
|
.samplers
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use tracing::error;
|
|
||||||
use wgpu::{Adapter, Instance, Surface};
|
|
||||||
|
|
||||||
use epaint::mutex::RwLock;
|
use epaint::mutex::RwLock;
|
||||||
|
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
use crate::{renderer, RenderState, Renderer, SurfaceErrorAction, WgpuConfiguration};
|
use crate::{renderer, RenderState, Renderer, SurfaceErrorAction, WgpuConfiguration};
|
||||||
|
|
||||||
struct SurfaceState {
|
struct SurfaceState {
|
||||||
surface: Surface,
|
surface: wgpu::Surface,
|
||||||
|
alpha_mode: wgpu::CompositeAlphaMode,
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,12 @@ struct SurfaceState {
|
||||||
pub struct Painter {
|
pub struct Painter {
|
||||||
configuration: WgpuConfiguration,
|
configuration: WgpuConfiguration,
|
||||||
msaa_samples: u32,
|
msaa_samples: u32,
|
||||||
|
support_transparent_backbuffer: bool,
|
||||||
depth_format: Option<wgpu::TextureFormat>,
|
depth_format: Option<wgpu::TextureFormat>,
|
||||||
depth_texture_view: Option<wgpu::TextureView>,
|
depth_texture_view: Option<wgpu::TextureView>,
|
||||||
|
|
||||||
instance: Instance,
|
instance: wgpu::Instance,
|
||||||
adapter: Option<Adapter>,
|
adapter: Option<wgpu::Adapter>,
|
||||||
render_state: Option<RenderState>,
|
render_state: Option<RenderState>,
|
||||||
surface_state: Option<SurfaceState>,
|
surface_state: Option<SurfaceState>,
|
||||||
}
|
}
|
||||||
|
@ -41,12 +42,21 @@ impl Painter {
|
||||||
/// [`set_window()`](Self::set_window) once you have
|
/// [`set_window()`](Self::set_window) once you have
|
||||||
/// a [`winit::window::Window`] with a valid `.raw_window_handle()`
|
/// a [`winit::window::Window`] with a valid `.raw_window_handle()`
|
||||||
/// associated.
|
/// associated.
|
||||||
pub fn new(configuration: WgpuConfiguration, msaa_samples: u32, depth_bits: u8) -> Self {
|
pub fn new(
|
||||||
let instance = wgpu::Instance::new(configuration.backends);
|
configuration: WgpuConfiguration,
|
||||||
|
msaa_samples: u32,
|
||||||
|
depth_bits: u8,
|
||||||
|
support_transparent_backbuffer: bool,
|
||||||
|
) -> Self {
|
||||||
|
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
||||||
|
backends: configuration.backends,
|
||||||
|
dx12_shader_compiler: Default::default(), //
|
||||||
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
configuration,
|
configuration,
|
||||||
msaa_samples,
|
msaa_samples,
|
||||||
|
support_transparent_backbuffer,
|
||||||
depth_format: (depth_bits > 0).then_some(wgpu::TextureFormat::Depth32Float),
|
depth_format: (depth_bits > 0).then_some(wgpu::TextureFormat::Depth32Float),
|
||||||
depth_texture_view: None,
|
depth_texture_view: None,
|
||||||
|
|
||||||
|
@ -66,7 +76,7 @@ impl Painter {
|
||||||
|
|
||||||
async fn init_render_state(
|
async fn init_render_state(
|
||||||
&self,
|
&self,
|
||||||
adapter: &Adapter,
|
adapter: &wgpu::Adapter,
|
||||||
target_format: wgpu::TextureFormat,
|
target_format: wgpu::TextureFormat,
|
||||||
) -> Result<RenderState, wgpu::RequestDeviceError> {
|
) -> Result<RenderState, wgpu::RequestDeviceError> {
|
||||||
adapter
|
adapter
|
||||||
|
@ -91,7 +101,7 @@ impl Painter {
|
||||||
// will have the same format and so this render state will remain valid.
|
// will have the same format and so this render state will remain valid.
|
||||||
async fn ensure_render_state_for_surface(
|
async fn ensure_render_state_for_surface(
|
||||||
&mut self,
|
&mut self,
|
||||||
surface: &Surface,
|
surface: &wgpu::Surface,
|
||||||
) -> Result<(), wgpu::RequestDeviceError> {
|
) -> Result<(), wgpu::RequestDeviceError> {
|
||||||
if self.adapter.is_none() {
|
if self.adapter.is_none() {
|
||||||
self.adapter = self
|
self.adapter = self
|
||||||
|
@ -107,7 +117,7 @@ impl Painter {
|
||||||
match &self.adapter {
|
match &self.adapter {
|
||||||
Some(adapter) => {
|
Some(adapter) => {
|
||||||
let swapchain_format = crate::preferred_framebuffer_format(
|
let swapchain_format = crate::preferred_framebuffer_format(
|
||||||
&surface.get_supported_formats(adapter),
|
&surface.get_capabilities(adapter).formats,
|
||||||
);
|
);
|
||||||
let rs = self.init_render_state(adapter, swapchain_format).await?;
|
let rs = self.init_render_state(adapter, swapchain_format).await?;
|
||||||
self.render_state = Some(rs);
|
self.render_state = Some(rs);
|
||||||
|
@ -118,33 +128,23 @@ impl Painter {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_surface(&mut self, width_in_pixels: u32, height_in_pixels: u32) {
|
fn configure_surface(
|
||||||
crate::profile_function!();
|
surface_state: &SurfaceState,
|
||||||
|
render_state: &RenderState,
|
||||||
let render_state = self
|
present_mode: wgpu::PresentMode,
|
||||||
.render_state
|
) {
|
||||||
.as_ref()
|
surface_state.surface.configure(
|
||||||
.expect("Render state should exist before surface configuration");
|
&render_state.device,
|
||||||
let format = render_state.target_format;
|
&wgpu::SurfaceConfiguration {
|
||||||
|
|
||||||
let config = wgpu::SurfaceConfiguration {
|
|
||||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||||
format,
|
format: render_state.target_format,
|
||||||
width: width_in_pixels,
|
width: surface_state.width,
|
||||||
height: height_in_pixels,
|
height: surface_state.height,
|
||||||
present_mode: self.configuration.present_mode,
|
present_mode,
|
||||||
alpha_mode: wgpu::CompositeAlphaMode::Auto,
|
alpha_mode: surface_state.alpha_mode,
|
||||||
};
|
view_formats: vec![render_state.target_format],
|
||||||
|
},
|
||||||
let surface_state = self
|
);
|
||||||
.surface_state
|
|
||||||
.as_mut()
|
|
||||||
.expect("Surface state should exist before surface configuration");
|
|
||||||
surface_state
|
|
||||||
.surface
|
|
||||||
.configure(&render_state.device, &config);
|
|
||||||
surface_state.width = width_in_pixels;
|
|
||||||
surface_state.height = height_in_pixels;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates (or clears) the [`winit::window::Window`] associated with the [`Painter`]
|
/// Updates (or clears) the [`winit::window::Window`] associated with the [`Painter`]
|
||||||
|
@ -177,22 +177,41 @@ impl Painter {
|
||||||
pub async unsafe fn set_window(
|
pub async unsafe fn set_window(
|
||||||
&mut self,
|
&mut self,
|
||||||
window: Option<&winit::window::Window>,
|
window: Option<&winit::window::Window>,
|
||||||
) -> Result<(), wgpu::RequestDeviceError> {
|
) -> Result<(), crate::WgpuError> {
|
||||||
match window {
|
match window {
|
||||||
Some(window) => {
|
Some(window) => {
|
||||||
let surface = self.instance.create_surface(&window);
|
let surface = self.instance.create_surface(&window)?;
|
||||||
|
|
||||||
self.ensure_render_state_for_surface(&surface).await?;
|
self.ensure_render_state_for_surface(&surface).await?;
|
||||||
|
|
||||||
|
let alpha_mode = if self.support_transparent_backbuffer {
|
||||||
|
let supported_alpha_modes = surface
|
||||||
|
.get_capabilities(self.adapter.as_ref().unwrap())
|
||||||
|
.alpha_modes;
|
||||||
|
|
||||||
|
// Prefer pre multiplied over post multiplied!
|
||||||
|
if supported_alpha_modes.contains(&wgpu::CompositeAlphaMode::PreMultiplied) {
|
||||||
|
wgpu::CompositeAlphaMode::PreMultiplied
|
||||||
|
} else if supported_alpha_modes
|
||||||
|
.contains(&wgpu::CompositeAlphaMode::PostMultiplied)
|
||||||
|
{
|
||||||
|
wgpu::CompositeAlphaMode::PostMultiplied
|
||||||
|
} else {
|
||||||
|
tracing::warn!("Transparent window was requested, but the active wgpu surface does not support a `CompositeAlphaMode` with transparency.");
|
||||||
|
wgpu::CompositeAlphaMode::Auto
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wgpu::CompositeAlphaMode::Auto
|
||||||
|
};
|
||||||
|
|
||||||
let size = window.inner_size();
|
let size = window.inner_size();
|
||||||
let width = size.width;
|
|
||||||
let height = size.height;
|
|
||||||
self.surface_state = Some(SurfaceState {
|
self.surface_state = Some(SurfaceState {
|
||||||
surface,
|
surface,
|
||||||
width,
|
width: size.width,
|
||||||
height,
|
height: size.height,
|
||||||
|
alpha_mode,
|
||||||
});
|
});
|
||||||
self.resize_and_generate_depth_texture_view(width, height);
|
self.resize_and_generate_depth_texture_view(size.width, size.height);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
self.surface_state = None;
|
self.surface_state = None;
|
||||||
|
@ -217,10 +236,17 @@ impl Painter {
|
||||||
width_in_pixels: u32,
|
width_in_pixels: u32,
|
||||||
height_in_pixels: u32,
|
height_in_pixels: u32,
|
||||||
) {
|
) {
|
||||||
self.configure_surface(width_in_pixels, height_in_pixels);
|
let render_state = self.render_state.as_ref().unwrap();
|
||||||
let device = &self.render_state.as_ref().unwrap().device;
|
let surface_state = self.surface_state.as_mut().unwrap();
|
||||||
|
|
||||||
|
surface_state.width = width_in_pixels;
|
||||||
|
surface_state.height = height_in_pixels;
|
||||||
|
|
||||||
|
Self::configure_surface(surface_state, render_state, self.configuration.present_mode);
|
||||||
|
|
||||||
self.depth_texture_view = self.depth_format.map(|depth_format| {
|
self.depth_texture_view = self.depth_format.map(|depth_format| {
|
||||||
device
|
render_state
|
||||||
|
.device
|
||||||
.create_texture(&wgpu::TextureDescriptor {
|
.create_texture(&wgpu::TextureDescriptor {
|
||||||
label: Some("egui_depth_texture"),
|
label: Some("egui_depth_texture"),
|
||||||
size: wgpu::Extent3d {
|
size: wgpu::Extent3d {
|
||||||
|
@ -234,6 +260,7 @@ impl Painter {
|
||||||
format: depth_format,
|
format: depth_format,
|
||||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
|
||||||
| wgpu::TextureUsages::TEXTURE_BINDING,
|
| wgpu::TextureUsages::TEXTURE_BINDING,
|
||||||
|
view_formats: &[depth_format],
|
||||||
})
|
})
|
||||||
.create_view(&wgpu::TextureViewDescriptor::default())
|
.create_view(&wgpu::TextureViewDescriptor::default())
|
||||||
});
|
});
|
||||||
|
@ -250,7 +277,7 @@ impl Painter {
|
||||||
pub fn paint_and_update_textures(
|
pub fn paint_and_update_textures(
|
||||||
&mut self,
|
&mut self,
|
||||||
pixels_per_point: f32,
|
pixels_per_point: f32,
|
||||||
clear_color: epaint::Rgba,
|
clear_color: [f32; 4],
|
||||||
clipped_primitives: &[epaint::ClippedPrimitive],
|
clipped_primitives: &[epaint::ClippedPrimitive],
|
||||||
textures_delta: &epaint::textures::TexturesDelta,
|
textures_delta: &epaint::textures::TexturesDelta,
|
||||||
) {
|
) {
|
||||||
|
@ -264,7 +291,6 @@ impl Painter {
|
||||||
Some(rs) => rs,
|
Some(rs) => rs,
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
let (width, height) = (surface_state.width, surface_state.height);
|
|
||||||
|
|
||||||
let output_frame = {
|
let output_frame = {
|
||||||
crate::profile_scope!("get_current_texture");
|
crate::profile_scope!("get_current_texture");
|
||||||
|
@ -277,7 +303,11 @@ impl Painter {
|
||||||
#[allow(clippy::single_match_else)]
|
#[allow(clippy::single_match_else)]
|
||||||
Err(e) => match (*self.configuration.on_surface_error)(e) {
|
Err(e) => match (*self.configuration.on_surface_error)(e) {
|
||||||
SurfaceErrorAction::RecreateSurface => {
|
SurfaceErrorAction::RecreateSurface => {
|
||||||
self.configure_surface(width, height);
|
Self::configure_surface(
|
||||||
|
surface_state,
|
||||||
|
render_state,
|
||||||
|
self.configuration.present_mode,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SurfaceErrorAction::SkipFrame => {
|
SurfaceErrorAction::SkipFrame => {
|
||||||
|
@ -295,7 +325,7 @@ impl Painter {
|
||||||
|
|
||||||
// Upload all resources for the GPU.
|
// Upload all resources for the GPU.
|
||||||
let screen_descriptor = renderer::ScreenDescriptor {
|
let screen_descriptor = renderer::ScreenDescriptor {
|
||||||
size_in_pixels: [width, height],
|
size_in_pixels: [surface_state.width, surface_state.height],
|
||||||
pixels_per_point,
|
pixels_per_point,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -330,10 +360,10 @@ impl Painter {
|
||||||
resolve_target: None,
|
resolve_target: None,
|
||||||
ops: wgpu::Operations {
|
ops: wgpu::Operations {
|
||||||
load: wgpu::LoadOp::Clear(wgpu::Color {
|
load: wgpu::LoadOp::Clear(wgpu::Color {
|
||||||
r: clear_color.r() as f64,
|
r: clear_color[0] as f64,
|
||||||
g: clear_color.g() as f64,
|
g: clear_color[1] as f64,
|
||||||
b: clear_color.b() as f64,
|
b: clear_color[2] as f64,
|
||||||
a: clear_color.a() as f64,
|
a: clear_color[3] as f64,
|
||||||
}),
|
}),
|
||||||
store: true,
|
store: true,
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,8 +5,19 @@ All notable changes to the `egui-winit` integration will be noted in this file.
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
|
||||||
|
## 0.21.1 - 2023-02-12
|
||||||
|
* Fixed crash when window position is in an invalid state, which could happen e.g. due to changes in monitor size or DPI ([#2722](https://github.com/emilk/egui/issues/2722)).
|
||||||
|
|
||||||
|
|
||||||
|
## 0.21.0 - 2023-02-08
|
||||||
|
* Fixed persistence of native window position on Windows OS ([#2583](https://github.com/emilk/egui/issues/2583)).
|
||||||
|
* Update to `winit` 0.28, adding support for mac trackpad zoom ([#2654](https://github.com/emilk/egui/pull/2654)).
|
||||||
|
* Remove the `screen_reader` feature. Use the `accesskit` feature flag instead ([#2669](https://github.com/emilk/egui/pull/2669)).
|
||||||
|
* Fix bug where the cursor could get stuck using the wrong icon.
|
||||||
|
|
||||||
|
|
||||||
## 0.20.1 - 2022-12-11
|
## 0.20.1 - 2022-12-11
|
||||||
* Fix docs.rs build ([#2420](https://github.com/emilk/egui/pull/2420)).
|
* Fix [docs.rs](https://docs.rs/egui-winit) build ([#2420](https://github.com/emilk/egui/pull/2420)).
|
||||||
|
|
||||||
|
|
||||||
## 0.20.0 - 2022-12-08
|
## 0.20.0 - 2022-12-08
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "egui-winit"
|
name = "egui-winit"
|
||||||
version = "0.20.1"
|
version = "0.21.1"
|
||||||
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||||
description = "Bindings for using egui with winit"
|
description = "Bindings for using egui with winit"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
@ -14,8 +14,7 @@ keywords = ["winit", "egui", "gui", "gamedev"]
|
||||||
include = ["../LICENSE-APACHE", "../LICENSE-MIT", "**/*.rs", "Cargo.toml"]
|
include = ["../LICENSE-APACHE", "../LICENSE-MIT", "**/*.rs", "Cargo.toml"]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
# Avoid speech-dispatcher dependencies - see https://docs.rs/crate/egui-winit/0.20.0/builds/695196
|
all-features = true
|
||||||
features = ["document-features"]
|
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -37,9 +36,6 @@ links = ["webbrowser"]
|
||||||
## Enable profiling with the [`puffin`](https://docs.rs/puffin) crate.
|
## Enable profiling with the [`puffin`](https://docs.rs/puffin) crate.
|
||||||
puffin = ["dep:puffin"]
|
puffin = ["dep:puffin"]
|
||||||
|
|
||||||
## Experimental support for a screen reader.
|
|
||||||
screen_reader = ["tts"]
|
|
||||||
|
|
||||||
## Allow serialization of [`WindowSettings`] using [`serde`](https://docs.rs/serde).
|
## Allow serialization of [`WindowSettings`] using [`serde`](https://docs.rs/serde).
|
||||||
serde = ["egui/serde", "dep:serde"]
|
serde = ["egui/serde", "dep:serde"]
|
||||||
|
|
||||||
|
@ -47,33 +43,34 @@ serde = ["egui/serde", "dep:serde"]
|
||||||
wayland = ["winit/wayland"]
|
wayland = ["winit/wayland"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { version = "0.20.0", path = "../egui", default-features = false, features = [
|
egui = { version = "0.21.0", path = "../egui", default-features = false, features = [
|
||||||
"tracing",
|
"tracing",
|
||||||
] }
|
] }
|
||||||
instant = { version = "0.1", features = [
|
instant = { version = "0.1", features = [
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
] } # We use instant so we can (maybe) compile for web
|
] } # We use instant so we can (maybe) compile for web
|
||||||
tracing = { version = "0.1", default-features = false, features = ["std"] }
|
tracing = { version = "0.1", default-features = false, features = ["std"] }
|
||||||
winit = { version = "0.27.2", default-features = false }
|
winit = { version = "0.28", default-features = false }
|
||||||
|
|
||||||
#! ### Optional dependencies
|
#! ### Optional dependencies
|
||||||
|
|
||||||
|
# feature accesskit
|
||||||
|
accesskit_winit = { version = "0.10.0", optional = true }
|
||||||
|
|
||||||
## Enable this when generating docs.
|
## Enable this when generating docs.
|
||||||
document-features = { version = "0.2", optional = true }
|
document-features = { version = "0.2", optional = true }
|
||||||
|
|
||||||
# feature accesskit
|
|
||||||
accesskit_winit = { version = "0.7.1", optional = true }
|
|
||||||
|
|
||||||
puffin = { version = "0.14", optional = true }
|
puffin = { version = "0.14", optional = true }
|
||||||
serde = { version = "1.0", optional = true, features = ["derive"] }
|
serde = { version = "1.0", optional = true, features = ["derive"] }
|
||||||
|
|
||||||
# feature screen_reader
|
webbrowser = { version = "0.8.3", optional = true }
|
||||||
tts = { version = "0.24", optional = true }
|
|
||||||
|
|
||||||
webbrowser = { version = "0.8", optional = true }
|
|
||||||
|
|
||||||
[target.'cfg(any(target_os="linux", target_os="dragonfly", target_os="freebsd", target_os="netbsd", target_os="openbsd"))'.dependencies]
|
[target.'cfg(any(target_os="linux", target_os="dragonfly", target_os="freebsd", target_os="netbsd", target_os="openbsd"))'.dependencies]
|
||||||
smithay-clipboard = { version = "0.6.3", optional = true }
|
smithay-clipboard = { version = "0.6.3", optional = true }
|
||||||
|
|
||||||
[target.'cfg(not(target_os = "android"))'.dependencies]
|
[target.'cfg(not(target_os = "android"))'.dependencies]
|
||||||
arboard = { version = "3.2", optional = true, default-features = false }
|
arboard = { version = "3.2", optional = true, default-features = false }
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "android")'.dependencies]
|
||||||
|
# TODO(emilk): this is probably not the right place for specifying native-activity, but we need to do it somewhere for the CI
|
||||||
|
android-activity = { version = "0.4", features = ["native-activity"] }
|
||||||
|
|
|
@ -19,23 +19,12 @@ use egui::accesskit;
|
||||||
pub use winit;
|
pub use winit;
|
||||||
|
|
||||||
pub mod clipboard;
|
pub mod clipboard;
|
||||||
pub mod screen_reader;
|
|
||||||
mod window_settings;
|
mod window_settings;
|
||||||
|
|
||||||
pub use window_settings::WindowSettings;
|
pub use window_settings::WindowSettings;
|
||||||
|
|
||||||
use winit::event_loop::EventLoopWindowTarget;
|
use winit::event_loop::EventLoopWindowTarget;
|
||||||
|
|
||||||
#[cfg(feature = "wayland")]
|
|
||||||
#[cfg(any(
|
|
||||||
target_os = "linux",
|
|
||||||
target_os = "dragonfly",
|
|
||||||
target_os = "freebsd",
|
|
||||||
target_os = "netbsd",
|
|
||||||
target_os = "openbsd"
|
|
||||||
))]
|
|
||||||
use winit::platform::unix::EventLoopWindowTargetExtUnix;
|
|
||||||
|
|
||||||
pub fn native_pixels_per_point(window: &winit::window::Window) -> f32 {
|
pub fn native_pixels_per_point(window: &winit::window::Window) -> f32 {
|
||||||
window.scale_factor() as f32
|
window.scale_factor() as f32
|
||||||
}
|
}
|
||||||
|
@ -70,12 +59,12 @@ pub struct State {
|
||||||
egui_input: egui::RawInput,
|
egui_input: egui::RawInput,
|
||||||
pointer_pos_in_points: Option<egui::Pos2>,
|
pointer_pos_in_points: Option<egui::Pos2>,
|
||||||
any_pointer_button_down: bool,
|
any_pointer_button_down: bool,
|
||||||
current_cursor_icon: egui::CursorIcon,
|
current_cursor_icon: Option<egui::CursorIcon>,
|
||||||
|
|
||||||
/// What egui uses.
|
/// What egui uses.
|
||||||
current_pixels_per_point: f32,
|
current_pixels_per_point: f32,
|
||||||
|
|
||||||
clipboard: clipboard::Clipboard,
|
clipboard: clipboard::Clipboard,
|
||||||
screen_reader: screen_reader::ScreenReader,
|
|
||||||
|
|
||||||
/// If `true`, mouse inputs will be treated as touches.
|
/// If `true`, mouse inputs will be treated as touches.
|
||||||
/// Useful for debugging touch support in egui.
|
/// Useful for debugging touch support in egui.
|
||||||
|
@ -111,11 +100,10 @@ impl State {
|
||||||
egui_input,
|
egui_input,
|
||||||
pointer_pos_in_points: None,
|
pointer_pos_in_points: None,
|
||||||
any_pointer_button_down: false,
|
any_pointer_button_down: false,
|
||||||
current_cursor_icon: egui::CursorIcon::Default,
|
current_cursor_icon: None,
|
||||||
current_pixels_per_point: 1.0,
|
current_pixels_per_point: 1.0,
|
||||||
|
|
||||||
clipboard: clipboard::Clipboard::new(wayland_display),
|
clipboard: clipboard::Clipboard::new(wayland_display),
|
||||||
screen_reader: screen_reader::ScreenReader::default(),
|
|
||||||
|
|
||||||
simulate_touch_screen: false,
|
simulate_touch_screen: false,
|
||||||
pointer_touch_id: None,
|
pointer_touch_id: None,
|
||||||
|
@ -380,8 +368,9 @@ impl State {
|
||||||
consumed: false,
|
consumed: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowEvent::AxisMotion { .. }
|
|
||||||
| WindowEvent::CloseRequested
|
// Things that may require repaint:
|
||||||
|
WindowEvent::CloseRequested
|
||||||
| WindowEvent::CursorEntered { .. }
|
| WindowEvent::CursorEntered { .. }
|
||||||
| WindowEvent::Destroyed
|
| WindowEvent::Destroyed
|
||||||
| WindowEvent::Occluded(_)
|
| WindowEvent::Occluded(_)
|
||||||
|
@ -391,10 +380,26 @@ impl State {
|
||||||
repaint: true,
|
repaint: true,
|
||||||
consumed: false,
|
consumed: false,
|
||||||
},
|
},
|
||||||
WindowEvent::Moved(_) => EventResponse {
|
|
||||||
repaint: false, // moving a window doesn't warrant a repaint
|
// Things we completely ignore:
|
||||||
|
WindowEvent::AxisMotion { .. }
|
||||||
|
| WindowEvent::Moved(_)
|
||||||
|
| WindowEvent::SmartMagnify { .. }
|
||||||
|
| WindowEvent::TouchpadRotate { .. } => EventResponse {
|
||||||
|
repaint: false,
|
||||||
consumed: false,
|
consumed: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
WindowEvent::TouchpadMagnify { delta, .. } => {
|
||||||
|
// Positive delta values indicate magnification (zooming in).
|
||||||
|
// Negative delta values indicate shrinking (zooming out).
|
||||||
|
let zoom_factor = (*delta as f32).exp();
|
||||||
|
self.egui_input.events.push(egui::Event::Zoom(zoom_factor));
|
||||||
|
EventResponse {
|
||||||
|
repaint: true,
|
||||||
|
consumed: egui_ctx.wants_pointer_input(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -615,11 +620,6 @@ impl State {
|
||||||
egui_ctx: &egui::Context,
|
egui_ctx: &egui::Context,
|
||||||
platform_output: egui::PlatformOutput,
|
platform_output: egui::PlatformOutput,
|
||||||
) {
|
) {
|
||||||
if egui_ctx.options(|o| o.screen_reader) {
|
|
||||||
self.screen_reader
|
|
||||||
.speak(&platform_output.events_description());
|
|
||||||
}
|
|
||||||
|
|
||||||
let egui::PlatformOutput {
|
let egui::PlatformOutput {
|
||||||
cursor_icon,
|
cursor_icon,
|
||||||
open_url,
|
open_url,
|
||||||
|
@ -655,23 +655,26 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_cursor_icon(&mut self, window: &winit::window::Window, cursor_icon: egui::CursorIcon) {
|
fn set_cursor_icon(&mut self, window: &winit::window::Window, cursor_icon: egui::CursorIcon) {
|
||||||
|
if self.current_cursor_icon == Some(cursor_icon) {
|
||||||
// Prevent flickering near frame boundary when Windows OS tries to control cursor icon for window resizing.
|
// Prevent flickering near frame boundary when Windows OS tries to control cursor icon for window resizing.
|
||||||
// On other platforms: just early-out to save CPU.
|
// On other platforms: just early-out to save CPU.
|
||||||
if self.current_cursor_icon == cursor_icon {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.current_cursor_icon = cursor_icon;
|
|
||||||
|
|
||||||
if let Some(cursor_icon) = translate_cursor(cursor_icon) {
|
|
||||||
window.set_cursor_visible(true);
|
|
||||||
|
|
||||||
let is_pointer_in_window = self.pointer_pos_in_points.is_some();
|
let is_pointer_in_window = self.pointer_pos_in_points.is_some();
|
||||||
if is_pointer_in_window {
|
if is_pointer_in_window {
|
||||||
window.set_cursor_icon(cursor_icon);
|
self.current_cursor_icon = Some(cursor_icon);
|
||||||
}
|
|
||||||
|
if let Some(winit_cursor_icon) = translate_cursor(cursor_icon) {
|
||||||
|
window.set_cursor_visible(true);
|
||||||
|
window.set_cursor_icon(winit_cursor_icon);
|
||||||
} else {
|
} else {
|
||||||
window.set_cursor_visible(false);
|
window.set_cursor_visible(false);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Remember to set the cursor again once the cursor returns to the screen:
|
||||||
|
self.current_cursor_icon = None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -879,6 +882,7 @@ fn wayland_display<T>(_event_loop: &EventLoopWindowTarget<T>) -> Option<*mut c_v
|
||||||
target_os = "openbsd"
|
target_os = "openbsd"
|
||||||
))]
|
))]
|
||||||
{
|
{
|
||||||
|
use winit::platform::wayland::EventLoopWindowTargetExtWayland as _;
|
||||||
return _event_loop.wayland_display();
|
return _event_loop.wayland_display();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
pub struct ScreenReader {
|
|
||||||
#[cfg(feature = "tts")]
|
|
||||||
tts: Option<tts::Tts>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "tts"))]
|
|
||||||
#[allow(clippy::derivable_impls)] // False positive
|
|
||||||
impl Default for ScreenReader {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "tts")]
|
|
||||||
impl Default for ScreenReader {
|
|
||||||
fn default() -> Self {
|
|
||||||
let tts = match tts::Tts::default() {
|
|
||||||
Ok(screen_reader) => {
|
|
||||||
tracing::debug!("Initialized screen reader.");
|
|
||||||
Some(screen_reader)
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
tracing::warn!("Failed to load screen reader: {}", err);
|
|
||||||
None
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Self { tts }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ScreenReader {
|
|
||||||
#[cfg(not(feature = "tts"))]
|
|
||||||
#[allow(clippy::unused_self)]
|
|
||||||
pub fn speak(&mut self, _text: &str) {}
|
|
||||||
|
|
||||||
#[cfg(feature = "tts")]
|
|
||||||
pub fn speak(&mut self, text: &str) {
|
|
||||||
if text.is_empty() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if let Some(tts) = &mut self.tts {
|
|
||||||
tracing::debug!("Speaking: {:?}", text);
|
|
||||||
let interrupt = true;
|
|
||||||
if let Err(err) = tts.speak(text, interrupt) {
|
|
||||||
tracing::warn!("Failed to read: {}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -42,6 +42,10 @@ impl WindowSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn inner_size_points(&self) -> Option<egui::Vec2> {
|
||||||
|
self.inner_size_points
|
||||||
|
}
|
||||||
|
|
||||||
pub fn initialize_window(
|
pub fn initialize_window(
|
||||||
&self,
|
&self,
|
||||||
mut window: winit::window::WindowBuilder,
|
mut window: winit::window::WindowBuilder,
|
||||||
|
@ -49,17 +53,14 @@ impl WindowSettings {
|
||||||
// If the app last ran on two monitors and only one is now connected, then
|
// If the app last ran on two monitors and only one is now connected, then
|
||||||
// the given position is invalid.
|
// the given position is invalid.
|
||||||
// If this happens on Mac, the window is clamped into valid area.
|
// If this happens on Mac, the window is clamped into valid area.
|
||||||
// If this happens on Windows, the window is hidden and very difficult to find.
|
// If this happens on Windows, the clamping behavior is managed by the function
|
||||||
// So we don't restore window positions on Windows.
|
// clamp_window_to_sane_position.
|
||||||
let try_restore_position = !cfg!(target_os = "windows");
|
|
||||||
if try_restore_position {
|
|
||||||
if let Some(pos) = self.position {
|
if let Some(pos) = self.position {
|
||||||
window = window.with_position(winit::dpi::PhysicalPosition {
|
window = window.with_position(winit::dpi::PhysicalPosition {
|
||||||
x: pos.x as f64,
|
x: pos.x as f64,
|
||||||
y: pos.y as f64,
|
y: pos.y as f64,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(inner_size_points) = self.inner_size_points {
|
if let Some(inner_size_points) = self.inner_size_points {
|
||||||
window
|
window
|
||||||
|
@ -86,4 +87,58 @@ impl WindowSettings {
|
||||||
*size = size.at_most(max_size);
|
*size = size.at_most(max_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clamp_window_to_sane_position<E>(
|
||||||
|
&mut self,
|
||||||
|
event_loop: &winit::event_loop::EventLoopWindowTarget<E>,
|
||||||
|
) {
|
||||||
|
if let (Some(position), Some(inner_size_points)) =
|
||||||
|
(&mut self.position, &self.inner_size_points)
|
||||||
|
{
|
||||||
|
let monitors = event_loop.available_monitors();
|
||||||
|
// default to primary monitor, in case the correct monitor was disconnected.
|
||||||
|
let mut active_monitor = if let Some(active_monitor) = event_loop
|
||||||
|
.primary_monitor()
|
||||||
|
.or_else(|| event_loop.available_monitors().next())
|
||||||
|
{
|
||||||
|
active_monitor
|
||||||
|
} else {
|
||||||
|
return; // no monitors 🤷
|
||||||
|
};
|
||||||
|
for monitor in monitors {
|
||||||
|
let monitor_x_range = (monitor.position().x - inner_size_points.x as i32)
|
||||||
|
..(monitor.position().x + monitor.size().width as i32);
|
||||||
|
let monitor_y_range = (monitor.position().y - inner_size_points.y as i32)
|
||||||
|
..(monitor.position().y + monitor.size().height as i32);
|
||||||
|
|
||||||
|
if monitor_x_range.contains(&(position.x as i32))
|
||||||
|
&& monitor_y_range.contains(&(position.y as i32))
|
||||||
|
{
|
||||||
|
active_monitor = monitor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut inner_size_pixels = *inner_size_points * (active_monitor.scale_factor() as f32);
|
||||||
|
// Add size of title bar. This is 32 px by default in Win 10/11.
|
||||||
|
if cfg!(target_os = "windows") {
|
||||||
|
inner_size_pixels +=
|
||||||
|
egui::Vec2::new(0.0, 32.0 * active_monitor.scale_factor() as f32);
|
||||||
|
}
|
||||||
|
let monitor_position = egui::Pos2::new(
|
||||||
|
active_monitor.position().x as f32,
|
||||||
|
active_monitor.position().y as f32,
|
||||||
|
);
|
||||||
|
let monitor_size = egui::Vec2::new(
|
||||||
|
active_monitor.size().width as f32,
|
||||||
|
active_monitor.size().height as f32,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Window size cannot be negative or the subsequent `clamp` will panic.
|
||||||
|
let window_size = (monitor_size - inner_size_pixels).max(egui::Vec2::ZERO);
|
||||||
|
// To get the maximum position, we get the rightmost corner of the display, then
|
||||||
|
// subtract the size of the window to get the bottom right most value window.position
|
||||||
|
// can have.
|
||||||
|
*position = position.clamp(monitor_position, monitor_position + window_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "egui"
|
name = "egui"
|
||||||
version = "0.20.1"
|
version = "0.21.0"
|
||||||
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||||
description = "An easy-to-use immediate mode GUI that runs on both web and native"
|
description = "An easy-to-use immediate mode GUI that runs on both web and native"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
@ -54,8 +54,12 @@ persistence = ["serde", "epaint/serde", "ron"]
|
||||||
## Allow serialization using [`serde`](https://docs.rs/serde).
|
## Allow serialization using [`serde`](https://docs.rs/serde).
|
||||||
serde = ["dep:serde", "epaint/serde", "accesskit?/serde"]
|
serde = ["dep:serde", "epaint/serde", "accesskit?/serde"]
|
||||||
|
|
||||||
|
## Change Vertex layout to be compatible with unity
|
||||||
|
unity = ["epaint/unity"]
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
epaint = { version = "0.20.0", path = "../epaint", default-features = false }
|
epaint = { version = "0.21.0", path = "../epaint", default-features = false }
|
||||||
|
|
||||||
ahash = { version = "0.8.1", default-features = false, features = [
|
ahash = { version = "0.8.1", default-features = false, features = [
|
||||||
"no-rng", # we don't need DOS-protection, so we let users opt-in to it instead
|
"no-rng", # we don't need DOS-protection, so we let users opt-in to it instead
|
||||||
|
@ -66,7 +70,7 @@ nohash-hasher = "0.2"
|
||||||
#! ### Optional dependencies
|
#! ### Optional dependencies
|
||||||
## Exposes detailed accessibility implementation required by platform
|
## Exposes detailed accessibility implementation required by platform
|
||||||
## accessibility APIs. Also requires support in the egui integration.
|
## accessibility APIs. Also requires support in the egui integration.
|
||||||
accesskit = { version = "0.8.1", optional = true }
|
accesskit = { version = "0.9.0", optional = true }
|
||||||
|
|
||||||
## Enable this when generating docs.
|
## Enable this when generating docs.
|
||||||
document-features = { version = "0.2", optional = true }
|
document-features = { version = "0.2", optional = true }
|
||||||
|
|
|
@ -9,6 +9,7 @@ pub(crate) struct AnimationManager {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct BoolAnim {
|
struct BoolAnim {
|
||||||
value: bool,
|
value: bool,
|
||||||
|
|
||||||
/// when did `value` last toggle?
|
/// when did `value` last toggle?
|
||||||
toggle_time: f64,
|
toggle_time: f64,
|
||||||
}
|
}
|
||||||
|
@ -16,7 +17,9 @@ struct BoolAnim {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct ValueAnim {
|
struct ValueAnim {
|
||||||
from_value: f32,
|
from_value: f32,
|
||||||
|
|
||||||
to_value: f32,
|
to_value: f32,
|
||||||
|
|
||||||
/// when did `value` last toggle?
|
/// when did `value` last toggle?
|
||||||
toggle_time: f64,
|
toggle_time: f64,
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,10 @@ use crate::*;
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
pub(crate) struct State {
|
pub(crate) struct State {
|
||||||
/// Last known pos
|
/// Last known pos of the pivot
|
||||||
pub pos: Pos2,
|
pub pivot_pos: Pos2,
|
||||||
|
|
||||||
|
pub pivot: Align2,
|
||||||
|
|
||||||
/// Last know size. Used for catching clicks.
|
/// Last know size. Used for catching clicks.
|
||||||
pub size: Vec2,
|
pub size: Vec2,
|
||||||
|
@ -21,8 +23,22 @@ pub(crate) struct State {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
|
pub fn left_top_pos(&self) -> Pos2 {
|
||||||
|
pos2(
|
||||||
|
self.pivot_pos.x - self.pivot.x().to_factor() * self.size.x,
|
||||||
|
self.pivot_pos.y - self.pivot.y().to_factor() * self.size.y,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_left_top_pos(&mut self, pos: Pos2) {
|
||||||
|
self.pivot_pos = pos2(
|
||||||
|
pos.x + self.pivot.x().to_factor() * self.size.x,
|
||||||
|
pos.y + self.pivot.y().to_factor() * self.size.y,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn rect(&self) -> Rect {
|
pub fn rect(&self) -> Rect {
|
||||||
Rect::from_min_size(self.pos, self.size)
|
Rect::from_min_size(self.left_top_pos(), self.size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,21 +253,19 @@ impl Area {
|
||||||
ctx.request_repaint(); // if we don't know the previous size we are likely drawing the area in the wrong place
|
ctx.request_repaint(); // if we don't know the previous size we are likely drawing the area in the wrong place
|
||||||
}
|
}
|
||||||
let mut state = state.unwrap_or_else(|| State {
|
let mut state = state.unwrap_or_else(|| State {
|
||||||
pos: default_pos.unwrap_or_else(|| automatic_area_position(ctx)),
|
pivot_pos: default_pos.unwrap_or_else(|| automatic_area_position(ctx)),
|
||||||
|
pivot,
|
||||||
size: Vec2::ZERO,
|
size: Vec2::ZERO,
|
||||||
interactable,
|
interactable,
|
||||||
});
|
});
|
||||||
state.pos = new_pos.unwrap_or(state.pos);
|
state.pivot_pos = new_pos.unwrap_or(state.pivot_pos);
|
||||||
state.interactable = interactable;
|
state.interactable = interactable;
|
||||||
|
|
||||||
if pivot != Align2::LEFT_TOP {
|
|
||||||
state.pos.x -= pivot.x().to_factor() * state.size.x;
|
|
||||||
state.pos.y -= pivot.y().to_factor() * state.size.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some((anchor, offset)) = anchor {
|
if let Some((anchor, offset)) = anchor {
|
||||||
let screen = ctx.available_rect();
|
let screen = ctx.available_rect();
|
||||||
state.pos = anchor.align_size_within_rect(state.size, screen).min + offset;
|
state.set_left_top_pos(
|
||||||
|
anchor.align_size_within_rect(state.size, screen).left_top() + offset,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// interact right away to prevent frame-delay
|
// interact right away to prevent frame-delay
|
||||||
|
@ -278,12 +292,13 @@ impl Area {
|
||||||
// Important check - don't try to move e.g. a combobox popup!
|
// Important check - don't try to move e.g. a combobox popup!
|
||||||
if movable {
|
if movable {
|
||||||
if move_response.dragged() {
|
if move_response.dragged() {
|
||||||
state.pos += ctx.input(|i| i.pointer.delta());
|
state.pivot_pos += ctx.input(|i| i.pointer.delta());
|
||||||
}
|
}
|
||||||
|
|
||||||
state.pos = ctx
|
state.set_left_top_pos(
|
||||||
.constrain_window_rect_to_area(state.rect(), drag_bounds)
|
ctx.constrain_window_rect_to_area(state.rect(), drag_bounds)
|
||||||
.min;
|
.min,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (move_response.dragged() || move_response.clicked())
|
if (move_response.dragged() || move_response.clicked())
|
||||||
|
@ -297,12 +312,13 @@ impl Area {
|
||||||
move_response
|
move_response
|
||||||
};
|
};
|
||||||
|
|
||||||
state.pos = ctx.round_pos_to_pixels(state.pos);
|
state.set_left_top_pos(ctx.round_pos_to_pixels(state.left_top_pos()));
|
||||||
|
|
||||||
if constrain {
|
if constrain {
|
||||||
state.pos = ctx
|
state.set_left_top_pos(
|
||||||
.constrain_window_rect_to_area(state.rect(), drag_bounds)
|
ctx.constrain_window_rect_to_area(state.rect(), drag_bounds)
|
||||||
.min;
|
.left_top(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Prepared {
|
Prepared {
|
||||||
|
@ -374,14 +390,16 @@ impl Prepared {
|
||||||
};
|
};
|
||||||
|
|
||||||
let max_rect = Rect::from_min_max(
|
let max_rect = Rect::from_min_max(
|
||||||
self.state.pos,
|
self.state.left_top_pos(),
|
||||||
bounds.max.at_least(self.state.pos + Vec2::splat(32.0)),
|
bounds
|
||||||
|
.max
|
||||||
|
.at_least(self.state.left_top_pos() + Vec2::splat(32.0)),
|
||||||
);
|
);
|
||||||
|
|
||||||
let shadow_radius = ctx.style().visuals.window_shadow.extrusion; // hacky
|
let shadow_radius = ctx.style().visuals.window_shadow.extrusion; // hacky
|
||||||
let clip_rect_margin = ctx.style().visuals.clip_rect_margin.max(shadow_radius);
|
let clip_rect_margin = ctx.style().visuals.clip_rect_margin.max(shadow_radius);
|
||||||
|
|
||||||
let clip_rect = Rect::from_min_max(self.state.pos, bounds.max)
|
let clip_rect = Rect::from_min_max(self.state.left_top_pos(), bounds.max)
|
||||||
.expand(clip_rect_margin)
|
.expand(clip_rect_margin)
|
||||||
.intersect(bounds);
|
.intersect(bounds);
|
||||||
|
|
||||||
|
|
|
@ -112,10 +112,7 @@ impl CollapsingState {
|
||||||
response.rect.center().y,
|
response.rect.center().y,
|
||||||
));
|
));
|
||||||
let openness = self.openness(ui.ctx());
|
let openness = self.openness(ui.ctx());
|
||||||
let small_icon_response = Response {
|
let small_icon_response = response.clone().with_new_rect(icon_rect);
|
||||||
rect: icon_rect,
|
|
||||||
..response.clone()
|
|
||||||
};
|
|
||||||
icon_fn(ui, openness, &small_icon_response);
|
icon_fn(ui, openness, &small_icon_response);
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
|
@ -144,9 +141,10 @@ impl CollapsingState {
|
||||||
add_header: impl FnOnce(&mut Ui) -> HeaderRet,
|
add_header: impl FnOnce(&mut Ui) -> HeaderRet,
|
||||||
) -> HeaderResponse<'_, HeaderRet> {
|
) -> HeaderResponse<'_, HeaderRet> {
|
||||||
let header_response = ui.horizontal(|ui| {
|
let header_response = ui.horizontal(|ui| {
|
||||||
|
let prev_item_spacing = ui.spacing_mut().item_spacing;
|
||||||
ui.spacing_mut().item_spacing.x = 0.0; // the toggler button uses the full indent width
|
ui.spacing_mut().item_spacing.x = 0.0; // the toggler button uses the full indent width
|
||||||
let collapser = self.show_default_button_indented(ui);
|
let collapser = self.show_default_button_indented(ui);
|
||||||
ui.spacing_mut().item_spacing.x = ui.spacing_mut().icon_spacing; // Restore spacing
|
ui.spacing_mut().item_spacing = prev_item_spacing;
|
||||||
(collapser, add_header(ui))
|
(collapser, add_header(ui))
|
||||||
});
|
});
|
||||||
HeaderResponse {
|
HeaderResponse {
|
||||||
|
@ -576,10 +574,7 @@ impl CollapsingHeader {
|
||||||
header_response.rect.left() + ui.spacing().indent / 2.0,
|
header_response.rect.left() + ui.spacing().indent / 2.0,
|
||||||
header_response.rect.center().y,
|
header_response.rect.center().y,
|
||||||
));
|
));
|
||||||
let icon_response = Response {
|
let icon_response = header_response.clone().with_new_rect(icon_rect);
|
||||||
rect: icon_rect,
|
|
||||||
..header_response.clone()
|
|
||||||
};
|
|
||||||
if let Some(icon) = icon {
|
if let Some(icon) = icon {
|
||||||
icon(ui, openness, &icon_response);
|
icon(ui, openness, &icon_response);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -19,11 +19,16 @@ use epaint::*;
|
||||||
pub struct Frame {
|
pub struct Frame {
|
||||||
/// Margin within the painted frame.
|
/// Margin within the painted frame.
|
||||||
pub inner_margin: Margin,
|
pub inner_margin: Margin,
|
||||||
|
|
||||||
/// Margin outside the painted frame.
|
/// Margin outside the painted frame.
|
||||||
pub outer_margin: Margin,
|
pub outer_margin: Margin,
|
||||||
|
|
||||||
pub rounding: Rounding,
|
pub rounding: Rounding,
|
||||||
|
|
||||||
pub shadow: Shadow,
|
pub shadow: Shadow,
|
||||||
|
|
||||||
pub fill: Color32,
|
pub fill: Color32,
|
||||||
|
|
||||||
pub stroke: Stroke,
|
pub stroke: Stroke,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -297,12 +297,12 @@ impl SidePanel {
|
||||||
|
|
||||||
{
|
{
|
||||||
let stroke = if is_resizing {
|
let stroke = if is_resizing {
|
||||||
ui.style().visuals.widgets.active.bg_stroke
|
ui.style().visuals.widgets.active.fg_stroke // highly visible
|
||||||
} else if resize_hover {
|
} else if resize_hover {
|
||||||
ui.style().visuals.widgets.hovered.bg_stroke
|
ui.style().visuals.widgets.hovered.fg_stroke // highly visible
|
||||||
} else if show_separator_line {
|
} else if show_separator_line {
|
||||||
// TOOD(emilk): distinguish resizable from non-resizable
|
// TOOD(emilk): distinguish resizable from non-resizable
|
||||||
ui.style().visuals.widgets.noninteractive.bg_stroke
|
ui.style().visuals.widgets.noninteractive.bg_stroke // dim
|
||||||
} else {
|
} else {
|
||||||
Stroke::NONE
|
Stroke::NONE
|
||||||
};
|
};
|
||||||
|
@ -748,12 +748,12 @@ impl TopBottomPanel {
|
||||||
|
|
||||||
{
|
{
|
||||||
let stroke = if is_resizing {
|
let stroke = if is_resizing {
|
||||||
ui.style().visuals.widgets.active.bg_stroke
|
ui.style().visuals.widgets.active.fg_stroke // highly visible
|
||||||
} else if resize_hover {
|
} else if resize_hover {
|
||||||
ui.style().visuals.widgets.hovered.bg_stroke
|
ui.style().visuals.widgets.hovered.fg_stroke // highly visible
|
||||||
} else if show_separator_line {
|
} else if show_separator_line {
|
||||||
// TOOD(emilk): distinguish resizable from non-resizable
|
// TOOD(emilk): distinguish resizable from non-resizable
|
||||||
ui.style().visuals.widgets.noninteractive.bg_stroke
|
ui.style().visuals.widgets.noninteractive.bg_stroke // dim
|
||||||
} else {
|
} else {
|
||||||
Stroke::NONE
|
Stroke::NONE
|
||||||
};
|
};
|
||||||
|
|
|
@ -260,8 +260,9 @@ fn show_tooltip_area_dyn<'c, R>(
|
||||||
Area::new(area_id)
|
Area::new(area_id)
|
||||||
.order(Order::Tooltip)
|
.order(Order::Tooltip)
|
||||||
.fixed_pos(window_pos)
|
.fixed_pos(window_pos)
|
||||||
|
.constrain(true)
|
||||||
.interactable(false)
|
.interactable(false)
|
||||||
.drag_bounds(Rect::EVERYTHING) // disable clip rect
|
.drag_bounds(ctx.screen_rect())
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
Frame::popup(&ctx.style())
|
Frame::popup(&ctx.style())
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
|
|
|
@ -426,15 +426,34 @@ impl ScrollArea {
|
||||||
|
|
||||||
let content_max_rect = Rect::from_min_size(inner_rect.min - state.offset, content_max_size);
|
let content_max_rect = Rect::from_min_size(inner_rect.min - state.offset, content_max_size);
|
||||||
let mut content_ui = ui.child_ui(content_max_rect, *ui.layout());
|
let mut content_ui = ui.child_ui(content_max_rect, *ui.layout());
|
||||||
let mut content_clip_rect = inner_rect.expand(ui.visuals().clip_rect_margin);
|
|
||||||
content_clip_rect = content_clip_rect.intersect(ui.clip_rect());
|
{
|
||||||
// Nice handling of forced resizing beyond the possible:
|
// Clip the content, but only when we really need to:
|
||||||
|
let clip_rect_margin = ui.visuals().clip_rect_margin;
|
||||||
|
let scroll_bar_inner_margin = ui.spacing().scroll_bar_inner_margin;
|
||||||
|
let mut content_clip_rect = ui.clip_rect();
|
||||||
for d in 0..2 {
|
for d in 0..2 {
|
||||||
if !has_bar[d] {
|
if has_bar[d] {
|
||||||
|
if state.content_is_too_large[d] {
|
||||||
|
content_clip_rect.min[d] = inner_rect.min[d] - clip_rect_margin;
|
||||||
|
content_clip_rect.max[d] = inner_rect.max[d] + clip_rect_margin;
|
||||||
|
}
|
||||||
|
|
||||||
|
if state.show_scroll[d] {
|
||||||
|
// Make sure content doesn't cover scroll bars
|
||||||
|
let tiny_gap = 1.0;
|
||||||
|
content_clip_rect.max[1 - d] =
|
||||||
|
inner_rect.max[1 - d] + scroll_bar_inner_margin - tiny_gap;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Nice handling of forced resizing beyond the possible:
|
||||||
content_clip_rect.max[d] = ui.clip_rect().max[d] - current_bar_use[d];
|
content_clip_rect.max[d] = ui.clip_rect().max[d] - current_bar_use[d];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Make sure we din't accidentally expand the clip rect
|
||||||
|
content_clip_rect = content_clip_rect.intersect(ui.clip_rect());
|
||||||
content_ui.set_clip_rect(content_clip_rect);
|
content_ui.set_clip_rect(content_clip_rect);
|
||||||
|
}
|
||||||
|
|
||||||
let viewport = Rect::from_min_size(Pos2::ZERO + state.offset, inner_size);
|
let viewport = Rect::from_min_size(Pos2::ZERO + state.offset, inner_size);
|
||||||
|
|
||||||
|
@ -822,7 +841,7 @@ impl Prepared {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
let min_handle_size = ui.spacing().scroll_bar_width;
|
let min_handle_size = ui.spacing().scroll_handle_min_length;
|
||||||
if handle_rect.size()[d] < min_handle_size {
|
if handle_rect.size()[d] < min_handle_size {
|
||||||
handle_rect = Rect::from_center_size(
|
handle_rect = Rect::from_center_size(
|
||||||
handle_rect.center(),
|
handle_rect.center(),
|
||||||
|
|
|
@ -438,9 +438,12 @@ impl<'open> Window<'open> {
|
||||||
content_inner
|
content_inner
|
||||||
};
|
};
|
||||||
|
|
||||||
area.state_mut().pos = ctx
|
{
|
||||||
|
let pos = ctx
|
||||||
.constrain_window_rect_to_area(area.state().rect(), area.drag_bounds())
|
.constrain_window_rect_to_area(area.state().rect(), area.drag_bounds())
|
||||||
.min;
|
.left_top();
|
||||||
|
area.state_mut().set_left_top_pos(pos);
|
||||||
|
}
|
||||||
|
|
||||||
let full_response = area.end(ctx, area_content_ui);
|
let full_response = area.end(ctx, area_content_ui);
|
||||||
|
|
||||||
|
@ -550,7 +553,7 @@ fn interact(
|
||||||
let new_rect = ctx.constrain_window_rect_to_area(new_rect, area.drag_bounds());
|
let new_rect = ctx.constrain_window_rect_to_area(new_rect, area.drag_bounds());
|
||||||
|
|
||||||
// TODO(emilk): add this to a Window state instead as a command "move here next frame"
|
// TODO(emilk): add this to a Window state instead as a command "move here next frame"
|
||||||
area.state_mut().pos = new_rect.min;
|
area.state_mut().set_left_top_pos(new_rect.left_top());
|
||||||
|
|
||||||
if window_interaction.is_resize() {
|
if window_interaction.is_resize() {
|
||||||
if let Some(mut state) = resize::State::load(ctx, resize_id) {
|
if let Some(mut state) = resize::State::load(ctx, resize_id) {
|
||||||
|
|
|
@ -65,11 +65,14 @@ struct ContextImpl {
|
||||||
|
|
||||||
/// Written to during the frame.
|
/// Written to during the frame.
|
||||||
layer_rects_this_frame: ahash::HashMap<LayerId, Vec<(Id, Rect)>>,
|
layer_rects_this_frame: ahash::HashMap<LayerId, Vec<(Id, Rect)>>,
|
||||||
|
|
||||||
/// Read
|
/// Read
|
||||||
layer_rects_prev_frame: ahash::HashMap<LayerId, Vec<(Id, Rect)>>,
|
layer_rects_prev_frame: ahash::HashMap<LayerId, Vec<(Id, Rect)>>,
|
||||||
|
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
is_accesskit_enabled: bool,
|
is_accesskit_enabled: bool,
|
||||||
|
#[cfg(feature = "accesskit")]
|
||||||
|
accesskit_node_classes: accesskit::NodeClassSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ContextImpl {
|
impl ContextImpl {
|
||||||
|
@ -103,7 +106,8 @@ impl ContextImpl {
|
||||||
self.memory.areas.set_state(
|
self.memory.areas.set_state(
|
||||||
LayerId::background(),
|
LayerId::background(),
|
||||||
containers::area::State {
|
containers::area::State {
|
||||||
pos: screen_rect.min,
|
pivot_pos: screen_rect.left_top(),
|
||||||
|
pivot: Align2::LEFT_TOP,
|
||||||
size: screen_rect.size(),
|
size: screen_rect.size(),
|
||||||
interactable: true,
|
interactable: true,
|
||||||
},
|
},
|
||||||
|
@ -113,17 +117,14 @@ impl ContextImpl {
|
||||||
if self.is_accesskit_enabled {
|
if self.is_accesskit_enabled {
|
||||||
use crate::frame_state::AccessKitFrameState;
|
use crate::frame_state::AccessKitFrameState;
|
||||||
let id = crate::accesskit_root_id();
|
let id = crate::accesskit_root_id();
|
||||||
let node = Box::new(accesskit::Node {
|
let mut builder = accesskit::NodeBuilder::new(accesskit::Role::Window);
|
||||||
role: accesskit::Role::Window,
|
builder.set_transform(accesskit::Affine::scale(
|
||||||
transform: Some(
|
self.input.pixels_per_point().into(),
|
||||||
accesskit::kurbo::Affine::scale(self.input.pixels_per_point().into()).into(),
|
));
|
||||||
),
|
let mut node_builders = IdMap::default();
|
||||||
..Default::default()
|
node_builders.insert(id, builder);
|
||||||
});
|
|
||||||
let mut nodes = IdMap::default();
|
|
||||||
nodes.insert(id, node);
|
|
||||||
self.frame_state.accesskit_state = Some(AccessKitFrameState {
|
self.frame_state.accesskit_state = Some(AccessKitFrameState {
|
||||||
nodes,
|
node_builders,
|
||||||
parent_stack: vec![id],
|
parent_stack: vec![id],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -156,16 +157,16 @@ impl ContextImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
fn accesskit_node(&mut self, id: Id) -> &mut accesskit::Node {
|
fn accesskit_node_builder(&mut self, id: Id) -> &mut accesskit::NodeBuilder {
|
||||||
let state = self.frame_state.accesskit_state.as_mut().unwrap();
|
let state = self.frame_state.accesskit_state.as_mut().unwrap();
|
||||||
let nodes = &mut state.nodes;
|
let builders = &mut state.node_builders;
|
||||||
if let std::collections::hash_map::Entry::Vacant(entry) = nodes.entry(id) {
|
if let std::collections::hash_map::Entry::Vacant(entry) = builders.entry(id) {
|
||||||
entry.insert(Default::default());
|
entry.insert(Default::default());
|
||||||
let parent_id = state.parent_stack.last().unwrap();
|
let parent_id = state.parent_stack.last().unwrap();
|
||||||
let parent = nodes.get_mut(parent_id).unwrap();
|
let parent_builder = builders.get_mut(parent_id).unwrap();
|
||||||
parent.children.push(id.accesskit_id());
|
parent_builder.push_child(id.accesskit_id());
|
||||||
}
|
}
|
||||||
nodes.get_mut(&id).unwrap()
|
builders.get_mut(&id).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,6 +622,8 @@ impl Context {
|
||||||
) -> Response {
|
) -> Response {
|
||||||
let hovered = hovered && enabled; // can't even hover disabled widgets
|
let hovered = hovered && enabled; // can't even hover disabled widgets
|
||||||
|
|
||||||
|
let highlighted = self.frame_state(|fs| fs.highlight_this_frame.contains(&id));
|
||||||
|
|
||||||
let mut response = Response {
|
let mut response = Response {
|
||||||
ctx: self.clone(),
|
ctx: self.clone(),
|
||||||
layer_id,
|
layer_id,
|
||||||
|
@ -629,6 +632,7 @@ impl Context {
|
||||||
sense,
|
sense,
|
||||||
enabled,
|
enabled,
|
||||||
hovered,
|
hovered,
|
||||||
|
highlighted,
|
||||||
clicked: Default::default(),
|
clicked: Default::default(),
|
||||||
double_clicked: Default::default(),
|
double_clicked: Default::default(),
|
||||||
triple_clicked: Default::default(),
|
triple_clicked: Default::default(),
|
||||||
|
@ -652,7 +656,7 @@ impl Context {
|
||||||
// Make sure anything that can receive focus has an AccessKit node.
|
// Make sure anything that can receive focus has an AccessKit node.
|
||||||
// TODO(mwcampbell): For nodes that are filled from widget info,
|
// TODO(mwcampbell): For nodes that are filled from widget info,
|
||||||
// some information is written to the node twice.
|
// some information is written to the node twice.
|
||||||
self.accesskit_node(id, |node| response.fill_accesskit_node_common(node));
|
self.accesskit_node_builder(id, |builder| response.fill_accesskit_node_common(builder));
|
||||||
}
|
}
|
||||||
|
|
||||||
let clicked_elsewhere = response.clicked_elsewhere();
|
let clicked_elsewhere = response.clicked_elsewhere();
|
||||||
|
@ -1125,12 +1129,20 @@ impl Context {
|
||||||
if let Some(state) = state {
|
if let Some(state) = state {
|
||||||
let has_focus = self.input(|i| i.raw.has_focus);
|
let has_focus = self.input(|i| i.raw.has_focus);
|
||||||
let root_id = crate::accesskit_root_id().accesskit_id();
|
let root_id = crate::accesskit_root_id().accesskit_id();
|
||||||
platform_output.accesskit_update = Some(accesskit::TreeUpdate {
|
let nodes = self.write(|ctx| {
|
||||||
nodes: state
|
state
|
||||||
.nodes
|
.node_builders
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(id, node)| (id.accesskit_id(), Arc::from(node)))
|
.map(|(id, builder)| {
|
||||||
.collect(),
|
(
|
||||||
|
id.accesskit_id(),
|
||||||
|
builder.build(&mut ctx.accesskit_node_classes),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
});
|
||||||
|
platform_output.accesskit_update = Some(accesskit::TreeUpdate {
|
||||||
|
nodes,
|
||||||
tree: Some(accesskit::Tree::new(root_id)),
|
tree: Some(accesskit::Tree::new(root_id)),
|
||||||
focus: has_focus.then(|| {
|
focus: has_focus.then(|| {
|
||||||
let focus_id = self.memory(|mem| mem.interaction.focus.id);
|
let focus_id = self.memory(|mem| mem.interaction.focus.id);
|
||||||
|
@ -1284,6 +1296,15 @@ impl Context {
|
||||||
pub fn wants_keyboard_input(&self) -> bool {
|
pub fn wants_keyboard_input(&self) -> bool {
|
||||||
self.memory(|m| m.interaction.focus.focused().is_some())
|
self.memory(|m| m.interaction.focus.focused().is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Highlight this widget, to make it look like it is hovered, even if it isn't.
|
||||||
|
///
|
||||||
|
/// The highlight takes on frame to take effect if you call this after the widget has been fully rendered.
|
||||||
|
///
|
||||||
|
/// See also [`Response::highlight`].
|
||||||
|
pub fn highlight_widget(&self, id: Id) {
|
||||||
|
self.frame_state_mut(|fs| fs.highlight_next_frame.insert(id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ergonomic methods to forward some calls often used in 'if let' without holding the borrow
|
// Ergonomic methods to forward some calls often used in 'if let' without holding the borrow
|
||||||
|
@ -1708,8 +1729,8 @@ impl Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If AccessKit support is active for the current frame, get or create
|
/// If AccessKit support is active for the current frame, get or create
|
||||||
/// a node with the specified ID and return a mutable reference to it.
|
/// a node builder with the specified ID and return a mutable reference to it.
|
||||||
/// For newly crated nodes, the parent is the node with the ID at the top
|
/// For newly created nodes, the parent is the node with the ID at the top
|
||||||
/// of the stack managed by [`Context::with_accessibility_parent`].
|
/// of the stack managed by [`Context::with_accessibility_parent`].
|
||||||
///
|
///
|
||||||
/// The `Context` lock is held while the given closure is called!
|
/// The `Context` lock is held while the given closure is called!
|
||||||
|
@ -1717,16 +1738,16 @@ impl Context {
|
||||||
/// Returns `None` if acesskit is off.
|
/// Returns `None` if acesskit is off.
|
||||||
// TODO: consider making both RO and RW versions
|
// TODO: consider making both RO and RW versions
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
pub fn accesskit_node<R>(
|
pub fn accesskit_node_builder<R>(
|
||||||
&self,
|
&self,
|
||||||
id: Id,
|
id: Id,
|
||||||
writer: impl FnOnce(&mut accesskit::Node) -> R,
|
writer: impl FnOnce(&mut accesskit::NodeBuilder) -> R,
|
||||||
) -> Option<R> {
|
) -> Option<R> {
|
||||||
self.write(|ctx| {
|
self.write(|ctx| {
|
||||||
ctx.frame_state
|
ctx.frame_state
|
||||||
.accesskit_state
|
.accesskit_state
|
||||||
.is_some()
|
.is_some()
|
||||||
.then(|| ctx.accesskit_node(id))
|
.then(|| ctx.accesskit_node_builder(id))
|
||||||
.map(writer)
|
.map(writer)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1738,12 +1759,30 @@ impl Context {
|
||||||
/// being called by the AccessKit adapter to provide the initial tree update,
|
/// being called by the AccessKit adapter to provide the initial tree update,
|
||||||
/// then it should do so, to provide a complete AccessKit tree to the adapter
|
/// then it should do so, to provide a complete AccessKit tree to the adapter
|
||||||
/// immediately. Otherwise, it should enqueue a repaint and use the
|
/// immediately. Otherwise, it should enqueue a repaint and use the
|
||||||
/// placeholder tree update from [`crate::accesskit_placeholder_tree_update`]
|
/// placeholder tree update from [`Context::accesskit_placeholder_tree_update`]
|
||||||
/// in the meantime.
|
/// in the meantime.
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
pub fn enable_accesskit(&self) {
|
pub fn enable_accesskit(&self) {
|
||||||
self.write(|ctx| ctx.is_accesskit_enabled = true);
|
self.write(|ctx| ctx.is_accesskit_enabled = true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return a tree update that the egui integration should provide to the
|
||||||
|
/// AccessKit adapter if it cannot immediately run the egui application
|
||||||
|
/// to get a full tree update after running [`Context::enable_accesskit`].
|
||||||
|
#[cfg(feature = "accesskit")]
|
||||||
|
pub fn accesskit_placeholder_tree_update(&self) -> accesskit::TreeUpdate {
|
||||||
|
use accesskit::{NodeBuilder, Role, Tree, TreeUpdate};
|
||||||
|
|
||||||
|
let root_id = crate::accesskit_root_id().accesskit_id();
|
||||||
|
self.write(|ctx| TreeUpdate {
|
||||||
|
nodes: vec![(
|
||||||
|
root_id,
|
||||||
|
NodeBuilder::new(Role::Window).build(&mut ctx.accesskit_node_classes),
|
||||||
|
)],
|
||||||
|
tree: Some(Tree::new(root_id)),
|
||||||
|
focus: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::ops::RangeInclusive;
|
use std::ops::RangeInclusive;
|
||||||
|
|
||||||
use crate::*;
|
use crate::{id::IdSet, *};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub(crate) struct TooltipFrameState {
|
pub(crate) struct TooltipFrameState {
|
||||||
|
@ -12,7 +12,7 @@ pub(crate) struct TooltipFrameState {
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct AccessKitFrameState {
|
pub(crate) struct AccessKitFrameState {
|
||||||
pub(crate) nodes: IdMap<Box<accesskit::Node>>,
|
pub(crate) node_builders: IdMap<accesskit::NodeBuilder>,
|
||||||
pub(crate) parent_stack: Vec<Id>,
|
pub(crate) parent_stack: Vec<Id>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,12 @@ pub(crate) struct FrameState {
|
||||||
|
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
pub(crate) accesskit_state: Option<AccessKitFrameState>,
|
pub(crate) accesskit_state: Option<AccessKitFrameState>,
|
||||||
|
|
||||||
|
/// Highlight these widgets this next frame. Read from this.
|
||||||
|
pub(crate) highlight_this_frame: IdSet,
|
||||||
|
|
||||||
|
/// Highlight these widgets the next frame. Write to this.
|
||||||
|
pub(crate) highlight_next_frame: IdSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for FrameState {
|
impl Default for FrameState {
|
||||||
|
@ -65,6 +71,8 @@ impl Default for FrameState {
|
||||||
scroll_target: [None, None],
|
scroll_target: [None, None],
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
accesskit_state: None,
|
accesskit_state: None,
|
||||||
|
highlight_this_frame: Default::default(),
|
||||||
|
highlight_next_frame: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,6 +89,8 @@ impl FrameState {
|
||||||
scroll_target,
|
scroll_target,
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
accesskit_state,
|
accesskit_state,
|
||||||
|
highlight_this_frame,
|
||||||
|
highlight_next_frame,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
used_ids.clear();
|
used_ids.clear();
|
||||||
|
@ -90,10 +100,13 @@ impl FrameState {
|
||||||
*tooltip_state = None;
|
*tooltip_state = None;
|
||||||
*scroll_delta = input.scroll_delta;
|
*scroll_delta = input.scroll_delta;
|
||||||
*scroll_target = [None, None];
|
*scroll_target = [None, None];
|
||||||
|
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
{
|
{
|
||||||
*accesskit_state = None;
|
*accesskit_state = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*highlight_this_frame = std::mem::take(highlight_next_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// How much space is still available after panels has been added.
|
/// How much space is still available after panels has been added.
|
||||||
|
|
|
@ -168,5 +168,8 @@ impl std::hash::BuildHasher for BuilIdHasher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `IdSet` is a `HashSet<Id>` optimized by knowing that [`Id`] has good entropy, and doesn't need more hashing.
|
||||||
|
pub type IdSet = std::collections::HashSet<Id, BuilIdHasher>;
|
||||||
|
|
||||||
/// `IdMap<V>` is a `HashMap<Id, V>` optimized by knowing that [`Id`] has good entropy, and doesn't need more hashing.
|
/// `IdMap<V>` is a `HashMap<Id, V>` optimized by knowing that [`Id`] has good entropy, and doesn't need more hashing.
|
||||||
pub type IdMap<V> = std::collections::HashMap<Id, V, BuilIdHasher>;
|
pub type IdMap<V> = std::collections::HashMap<Id, V, BuilIdHasher>;
|
||||||
|
|
|
@ -447,8 +447,10 @@ impl InputState {
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub(crate) struct Click {
|
pub(crate) struct Click {
|
||||||
pub pos: Pos2,
|
pub pos: Pos2,
|
||||||
|
|
||||||
/// 1 or 2 (double-click) or 3 (triple-click)
|
/// 1 or 2 (double-click) or 3 (triple-click)
|
||||||
pub count: u32,
|
pub count: u32,
|
||||||
|
|
||||||
/// Allows you to check for e.g. shift-click
|
/// Allows you to check for e.g. shift-click
|
||||||
pub modifiers: Modifiers,
|
pub modifiers: Modifiers,
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,10 +96,14 @@ struct GestureState {
|
||||||
struct DynGestureState {
|
struct DynGestureState {
|
||||||
/// used for proportional zooming
|
/// used for proportional zooming
|
||||||
avg_distance: f32,
|
avg_distance: f32,
|
||||||
|
|
||||||
/// used for non-proportional zooming
|
/// used for non-proportional zooming
|
||||||
avg_abs_distance2: Vec2,
|
avg_abs_distance2: Vec2,
|
||||||
|
|
||||||
avg_pos: Pos2,
|
avg_pos: Pos2,
|
||||||
|
|
||||||
avg_force: f32,
|
avg_force: f32,
|
||||||
|
|
||||||
heading: f32,
|
heading: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ impl Order {
|
||||||
Self::Tooltip,
|
Self::Tooltip,
|
||||||
Self::Debug,
|
Self::Debug,
|
||||||
];
|
];
|
||||||
|
pub const TOP: Self = Self::Debug;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn allow_interaction(&self) -> bool {
|
pub fn allow_interaction(&self) -> bool {
|
||||||
|
|
|
@ -367,7 +367,7 @@ pub use {
|
||||||
painter::Painter,
|
painter::Painter,
|
||||||
response::{InnerResponse, Response},
|
response::{InnerResponse, Response},
|
||||||
sense::Sense,
|
sense::Sense,
|
||||||
style::{FontSelection, Style, TextStyle, Visuals},
|
style::{FontSelection, Margin, Style, TextStyle, Visuals},
|
||||||
text::{Galley, TextFormat},
|
text::{Galley, TextFormat},
|
||||||
ui::Ui,
|
ui::Ui,
|
||||||
widget_text::{RichText, WidgetText},
|
widget_text::{RichText, WidgetText},
|
||||||
|
@ -513,18 +513,30 @@ pub mod special_emojis {
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
pub enum WidgetType {
|
pub enum WidgetType {
|
||||||
Label, // TODO(emilk): emit Label events
|
Label, // TODO(emilk): emit Label events
|
||||||
|
|
||||||
/// e.g. a hyperlink
|
/// e.g. a hyperlink
|
||||||
Link,
|
Link,
|
||||||
|
|
||||||
TextEdit,
|
TextEdit,
|
||||||
|
|
||||||
Button,
|
Button,
|
||||||
|
|
||||||
Checkbox,
|
Checkbox,
|
||||||
|
|
||||||
RadioButton,
|
RadioButton,
|
||||||
|
|
||||||
SelectableLabel,
|
SelectableLabel,
|
||||||
|
|
||||||
ComboBox,
|
ComboBox,
|
||||||
|
|
||||||
Slider,
|
Slider,
|
||||||
|
|
||||||
DragValue,
|
DragValue,
|
||||||
|
|
||||||
ColorButton,
|
ColorButton,
|
||||||
|
|
||||||
ImageButton,
|
ImageButton,
|
||||||
|
|
||||||
CollapsingHeader,
|
CollapsingHeader,
|
||||||
|
|
||||||
/// If you cannot fit any of the above slots.
|
/// If you cannot fit any of the above slots.
|
||||||
|
@ -559,25 +571,3 @@ pub fn __run_test_ui(mut add_contents: impl FnMut(&mut Ui)) {
|
||||||
pub fn accesskit_root_id() -> Id {
|
pub fn accesskit_root_id() -> Id {
|
||||||
Id::new("accesskit_root")
|
Id::new("accesskit_root")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return a tree update that the egui integration should provide to the
|
|
||||||
/// AccessKit adapter if it cannot immediately run the egui application
|
|
||||||
/// to get a full tree update after running [`Context::enable_accesskit`].
|
|
||||||
#[cfg(feature = "accesskit")]
|
|
||||||
pub fn accesskit_placeholder_tree_update() -> accesskit::TreeUpdate {
|
|
||||||
use accesskit::{Node, Role, Tree, TreeUpdate};
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
let root_id = accesskit_root_id().accesskit_id();
|
|
||||||
TreeUpdate {
|
|
||||||
nodes: vec![(
|
|
||||||
root_id,
|
|
||||||
Arc::new(Node {
|
|
||||||
role: Role::Window,
|
|
||||||
..Default::default()
|
|
||||||
}),
|
|
||||||
)],
|
|
||||||
tree: Some(Tree::new(root_id)),
|
|
||||||
focus: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -103,9 +103,15 @@ pub struct Options {
|
||||||
/// Controls the tessellator.
|
/// Controls the tessellator.
|
||||||
pub tessellation_options: epaint::TessellationOptions,
|
pub tessellation_options: epaint::TessellationOptions,
|
||||||
|
|
||||||
/// This does not at all change the behavior of egui,
|
/// This is a signal to any backend that we want the [`crate::PlatformOutput::events`] read out loud.
|
||||||
/// but is a signal to any backend that we want the [`crate::PlatformOutput::events`] read out loud.
|
///
|
||||||
|
/// The only change to egui is that labels can be focused by pressing tab.
|
||||||
|
///
|
||||||
/// Screen readers is an experimental feature of egui, and not supported on all platforms.
|
/// Screen readers is an experimental feature of egui, and not supported on all platforms.
|
||||||
|
///
|
||||||
|
/// `eframe` supports it only on web, using the `web_screen_reader` feature flag,
|
||||||
|
/// but you should consider using [AccessKit](https://github.com/AccessKit/accesskit) instead,
|
||||||
|
/// which `eframe` supports.
|
||||||
pub screen_reader: bool,
|
pub screen_reader: bool,
|
||||||
|
|
||||||
/// If true, the most common glyphs (ASCII) are pre-rendered to the texture atlas.
|
/// If true, the most common glyphs (ASCII) are pre-rendered to the texture atlas.
|
||||||
|
|
|
@ -143,9 +143,10 @@ pub(crate) fn menu_ui<'c, R>(
|
||||||
|
|
||||||
let area = Area::new(menu_id)
|
let area = Area::new(menu_id)
|
||||||
.order(Order::Foreground)
|
.order(Order::Foreground)
|
||||||
|
.constrain(true)
|
||||||
.fixed_pos(pos)
|
.fixed_pos(pos)
|
||||||
.interactable(true)
|
.interactable(true)
|
||||||
.drag_bounds(Rect::EVERYTHING);
|
.drag_bounds(ctx.screen_rect());
|
||||||
let inner_response = area.show(ctx, |ui| {
|
let inner_response = area.show(ctx, |ui| {
|
||||||
set_menu_style(ui.style_mut());
|
set_menu_style(ui.style_mut());
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ use crate::{
|
||||||
///
|
///
|
||||||
/// Whenever something gets added to a [`Ui`], a [`Response`] object is returned.
|
/// Whenever something gets added to a [`Ui`], a [`Response`] object is returned.
|
||||||
/// [`ui.add`] returns a [`Response`], as does [`ui.button`], and all similar shortcuts.
|
/// [`ui.add`] returns a [`Response`], as does [`ui.button`], and all similar shortcuts.
|
||||||
|
// TODO(emilk): we should be using bit sets instead of so many bools
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
// CONTEXT:
|
// CONTEXT:
|
||||||
|
@ -42,6 +43,10 @@ pub struct Response {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub hovered: bool,
|
pub hovered: bool,
|
||||||
|
|
||||||
|
/// The widget is highlighted via a call to [`Self::highlight`] or [`Context::highlight_widget`].
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub highlighted: bool,
|
||||||
|
|
||||||
/// The pointer clicked this thing this frame.
|
/// The pointer clicked this thing this frame.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub clicked: [bool; NUM_POINTER_BUTTONS],
|
pub clicked: [bool; NUM_POINTER_BUTTONS],
|
||||||
|
@ -52,7 +57,7 @@ pub struct Response {
|
||||||
pub double_clicked: [bool; NUM_POINTER_BUTTONS],
|
pub double_clicked: [bool; NUM_POINTER_BUTTONS],
|
||||||
|
|
||||||
/// The thing was triple-clicked.
|
/// The thing was triple-clicked.
|
||||||
pub(crate) triple_clicked: [bool; NUM_POINTER_BUTTONS],
|
pub triple_clicked: [bool; NUM_POINTER_BUTTONS],
|
||||||
|
|
||||||
/// The widgets is being dragged
|
/// The widgets is being dragged
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
@ -90,6 +95,7 @@ impl std::fmt::Debug for Response {
|
||||||
sense,
|
sense,
|
||||||
enabled,
|
enabled,
|
||||||
hovered,
|
hovered,
|
||||||
|
highlighted,
|
||||||
clicked,
|
clicked,
|
||||||
double_clicked,
|
double_clicked,
|
||||||
triple_clicked,
|
triple_clicked,
|
||||||
|
@ -106,6 +112,7 @@ impl std::fmt::Debug for Response {
|
||||||
.field("sense", sense)
|
.field("sense", sense)
|
||||||
.field("enabled", enabled)
|
.field("enabled", enabled)
|
||||||
.field("hovered", hovered)
|
.field("hovered", hovered)
|
||||||
|
.field("highlighted", highlighted)
|
||||||
.field("clicked", clicked)
|
.field("clicked", clicked)
|
||||||
.field("double_clicked", double_clicked)
|
.field("double_clicked", double_clicked)
|
||||||
.field("triple_clicked", triple_clicked)
|
.field("triple_clicked", triple_clicked)
|
||||||
|
@ -213,6 +220,12 @@ impl Response {
|
||||||
self.hovered
|
self.hovered
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The widget is highlighted via a call to [`Self::highlight`] or [`Context::highlight_widget`].
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub fn highlighted(&self) -> bool {
|
||||||
|
self.highlighted
|
||||||
|
}
|
||||||
|
|
||||||
/// This widget has the keyboard focus (i.e. is receiving key presses).
|
/// This widget has the keyboard focus (i.e. is receiving key presses).
|
||||||
///
|
///
|
||||||
/// This function only returns true if the UI as a whole (e.g. window)
|
/// This function only returns true if the UI as a whole (e.g. window)
|
||||||
|
@ -454,6 +467,17 @@ impl Response {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Highlight this widget, to make it look like it is hovered, even if it isn't.
|
||||||
|
///
|
||||||
|
/// The highlight takes on frame to take effect if you call this after the widget has been fully rendered.
|
||||||
|
///
|
||||||
|
/// See also [`Context::highlight_widget`].
|
||||||
|
pub fn highlight(mut self) -> Self {
|
||||||
|
self.ctx.highlight_widget(self.id);
|
||||||
|
self.highlighted = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Show this text when hovering if the widget is disabled.
|
/// Show this text when hovering if the widget is disabled.
|
||||||
pub fn on_disabled_hover_text(self, text: impl Into<WidgetText>) -> Self {
|
pub fn on_disabled_hover_text(self, text: impl Into<WidgetText>) -> Self {
|
||||||
self.on_disabled_hover_ui(|ui| {
|
self.on_disabled_hover_ui(|ui| {
|
||||||
|
@ -549,47 +573,47 @@ impl Response {
|
||||||
self.output_event(event);
|
self.output_event(event);
|
||||||
} else {
|
} else {
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
self.ctx.accesskit_node(self.id, |node| {
|
self.ctx.accesskit_node_builder(self.id, |builder| {
|
||||||
self.fill_accesskit_node_from_widget_info(node, make_info());
|
self.fill_accesskit_node_from_widget_info(builder, make_info());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn output_event(&self, event: crate::output::OutputEvent) {
|
pub fn output_event(&self, event: crate::output::OutputEvent) {
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
self.ctx.accesskit_node(self.id, |node| {
|
self.ctx.accesskit_node_builder(self.id, |builder| {
|
||||||
self.fill_accesskit_node_from_widget_info(node, event.widget_info().clone());
|
self.fill_accesskit_node_from_widget_info(builder, event.widget_info().clone());
|
||||||
});
|
});
|
||||||
self.ctx.output_mut(|o| o.events.push(event));
|
self.ctx.output_mut(|o| o.events.push(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
pub(crate) fn fill_accesskit_node_common(&self, node: &mut accesskit::Node) {
|
pub(crate) fn fill_accesskit_node_common(&self, builder: &mut accesskit::NodeBuilder) {
|
||||||
node.bounds = Some(accesskit::kurbo::Rect {
|
builder.set_bounds(accesskit::Rect {
|
||||||
x0: self.rect.min.x.into(),
|
x0: self.rect.min.x.into(),
|
||||||
y0: self.rect.min.y.into(),
|
y0: self.rect.min.y.into(),
|
||||||
x1: self.rect.max.x.into(),
|
x1: self.rect.max.x.into(),
|
||||||
y1: self.rect.max.y.into(),
|
y1: self.rect.max.y.into(),
|
||||||
});
|
});
|
||||||
if self.sense.focusable {
|
if self.sense.focusable {
|
||||||
node.focusable = true;
|
builder.add_action(accesskit::Action::Focus);
|
||||||
}
|
}
|
||||||
if self.sense.click && node.default_action_verb.is_none() {
|
if self.sense.click && builder.default_action_verb().is_none() {
|
||||||
node.default_action_verb = Some(accesskit::DefaultActionVerb::Click);
|
builder.set_default_action_verb(accesskit::DefaultActionVerb::Click);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
fn fill_accesskit_node_from_widget_info(
|
fn fill_accesskit_node_from_widget_info(
|
||||||
&self,
|
&self,
|
||||||
node: &mut accesskit::Node,
|
builder: &mut accesskit::NodeBuilder,
|
||||||
info: crate::WidgetInfo,
|
info: crate::WidgetInfo,
|
||||||
) {
|
) {
|
||||||
use crate::WidgetType;
|
use crate::WidgetType;
|
||||||
use accesskit::{CheckedState, Role};
|
use accesskit::{CheckedState, Role};
|
||||||
|
|
||||||
self.fill_accesskit_node_common(node);
|
self.fill_accesskit_node_common(builder);
|
||||||
node.role = match info.typ {
|
builder.set_role(match info.typ {
|
||||||
WidgetType::Label => Role::StaticText,
|
WidgetType::Label => Role::StaticText,
|
||||||
WidgetType::Link => Role::Link,
|
WidgetType::Link => Role::Link,
|
||||||
WidgetType::TextEdit => Role::TextField,
|
WidgetType::TextEdit => Role::TextField,
|
||||||
|
@ -604,18 +628,18 @@ impl Response {
|
||||||
WidgetType::DragValue => Role::SpinButton,
|
WidgetType::DragValue => Role::SpinButton,
|
||||||
WidgetType::ColorButton => Role::ColorWell,
|
WidgetType::ColorButton => Role::ColorWell,
|
||||||
WidgetType::Other => Role::Unknown,
|
WidgetType::Other => Role::Unknown,
|
||||||
};
|
});
|
||||||
if let Some(label) = info.label {
|
if let Some(label) = info.label {
|
||||||
node.name = Some(label.into());
|
builder.set_name(label);
|
||||||
}
|
}
|
||||||
if let Some(value) = info.current_text_value {
|
if let Some(value) = info.current_text_value {
|
||||||
node.value = Some(value.into());
|
builder.set_value(value);
|
||||||
}
|
}
|
||||||
if let Some(value) = info.value {
|
if let Some(value) = info.value {
|
||||||
node.numeric_value = Some(value);
|
builder.set_numeric_value(value);
|
||||||
}
|
}
|
||||||
if let Some(selected) = info.selected {
|
if let Some(selected) = info.selected {
|
||||||
node.checked_state = Some(if selected {
|
builder.set_checked_state(if selected {
|
||||||
CheckedState::True
|
CheckedState::True
|
||||||
} else {
|
} else {
|
||||||
CheckedState::False
|
CheckedState::False
|
||||||
|
@ -638,8 +662,9 @@ impl Response {
|
||||||
/// ```
|
/// ```
|
||||||
pub fn labelled_by(self, id: Id) -> Self {
|
pub fn labelled_by(self, id: Id) -> Self {
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
self.ctx
|
self.ctx.accesskit_node_builder(self.id, |builder| {
|
||||||
.accesskit_node(self.id, |node| node.labelled_by.push(id.accesskit_id()));
|
builder.push_labelled_by(id.accesskit_id());
|
||||||
|
});
|
||||||
#[cfg(not(feature = "accesskit"))]
|
#[cfg(not(feature = "accesskit"))]
|
||||||
{
|
{
|
||||||
let _ = id;
|
let _ = id;
|
||||||
|
@ -688,6 +713,7 @@ impl Response {
|
||||||
sense: self.sense.union(other.sense),
|
sense: self.sense.union(other.sense),
|
||||||
enabled: self.enabled || other.enabled,
|
enabled: self.enabled || other.enabled,
|
||||||
hovered: self.hovered || other.hovered,
|
hovered: self.hovered || other.hovered,
|
||||||
|
highlighted: self.highlighted || other.highlighted,
|
||||||
clicked: [
|
clicked: [
|
||||||
self.clicked[0] || other.clicked[0],
|
self.clicked[0] || other.clicked[0],
|
||||||
self.clicked[1] || other.clicked[1],
|
self.clicked[1] || other.clicked[1],
|
||||||
|
@ -719,6 +745,13 @@ impl Response {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Response {
|
||||||
|
/// Returns a response with a modified [`Self::rect`].
|
||||||
|
pub fn with_new_rect(self, rect: Rect) -> Self {
|
||||||
|
Self { rect, ..self }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// To summarize the response from many widgets you can use this pattern:
|
/// To summarize the response from many widgets you can use this pattern:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
@ -174,6 +174,9 @@ pub struct Style {
|
||||||
/// ```
|
/// ```
|
||||||
pub text_styles: BTreeMap<TextStyle, FontId>,
|
pub text_styles: BTreeMap<TextStyle, FontId>,
|
||||||
|
|
||||||
|
/// The style to use for [`DragValue`] text.
|
||||||
|
pub drag_value_text_style: TextStyle,
|
||||||
|
|
||||||
/// If set, labels buttons wtc will use this to determine whether or not
|
/// If set, labels buttons wtc will use this to determine whether or not
|
||||||
/// to wrap the text at the right edge of the [`Ui`] they are in.
|
/// to wrap the text at the right edge of the [`Ui`] they are in.
|
||||||
/// By default this is `None`.
|
/// By default this is `None`.
|
||||||
|
@ -297,8 +300,12 @@ pub struct Spacing {
|
||||||
|
|
||||||
pub scroll_bar_width: f32,
|
pub scroll_bar_width: f32,
|
||||||
|
|
||||||
|
/// Make sure the scroll handle is at least this big
|
||||||
|
pub scroll_handle_min_length: f32,
|
||||||
|
|
||||||
/// Margin between contents and scroll bar.
|
/// Margin between contents and scroll bar.
|
||||||
pub scroll_bar_inner_margin: f32,
|
pub scroll_bar_inner_margin: f32,
|
||||||
|
|
||||||
/// Margin between scroll bar and the outer container (e.g. right of a vertical scroll bar).
|
/// Margin between scroll bar and the outer container (e.g. right of a vertical scroll bar).
|
||||||
pub scroll_bar_outer_margin: f32,
|
pub scroll_bar_outer_margin: f32,
|
||||||
}
|
}
|
||||||
|
@ -485,6 +492,7 @@ pub struct Visuals {
|
||||||
pub resize_corner_size: f32,
|
pub resize_corner_size: f32,
|
||||||
|
|
||||||
pub text_cursor_width: f32,
|
pub text_cursor_width: f32,
|
||||||
|
|
||||||
/// show where the text cursor would be if you clicked
|
/// show where the text cursor would be if you clicked
|
||||||
pub text_cursor_preview: bool,
|
pub text_cursor_preview: bool,
|
||||||
|
|
||||||
|
@ -497,9 +505,17 @@ pub struct Visuals {
|
||||||
/// Show a background behind collapsing headers.
|
/// Show a background behind collapsing headers.
|
||||||
pub collapsing_header_frame: bool,
|
pub collapsing_header_frame: bool,
|
||||||
|
|
||||||
|
/// Draw a vertical lien left of indented region, in e.g. [`crate::CollapsingHeader`].
|
||||||
|
pub indent_has_left_vline: bool,
|
||||||
|
|
||||||
/// Wether or not Grids and Tables should be striped by default
|
/// Wether or not Grids and Tables should be striped by default
|
||||||
/// (have alternating rows differently colored).
|
/// (have alternating rows differently colored).
|
||||||
pub striped: bool,
|
pub striped: bool,
|
||||||
|
|
||||||
|
/// Show trailing color behind the circle of a [`Slider`]. Default is OFF.
|
||||||
|
///
|
||||||
|
/// Enabling this will affect ALL sliders, and can be enabled/disabled per slider with [`Slider::trailing_fill`].
|
||||||
|
pub slider_trailing_fill: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Visuals {
|
impl Visuals {
|
||||||
|
@ -570,7 +586,9 @@ pub struct Widgets {
|
||||||
/// The style of an interactive widget, such as a button, at rest.
|
/// The style of an interactive widget, such as a button, at rest.
|
||||||
pub inactive: WidgetVisuals,
|
pub inactive: WidgetVisuals,
|
||||||
|
|
||||||
/// The style of an interactive widget while you hover it.
|
/// The style of an interactive widget while you hover it, or when it is highlighted.
|
||||||
|
///
|
||||||
|
/// See [`Response::hovered`], [`Response::highlighted`] and [`Response::highlight`].
|
||||||
pub hovered: WidgetVisuals,
|
pub hovered: WidgetVisuals,
|
||||||
|
|
||||||
/// The style of an interactive widget as you are clicking or dragging it.
|
/// The style of an interactive widget as you are clicking or dragging it.
|
||||||
|
@ -586,7 +604,7 @@ impl Widgets {
|
||||||
&self.noninteractive
|
&self.noninteractive
|
||||||
} else if response.is_pointer_button_down_on() || response.has_focus() {
|
} else if response.is_pointer_button_down_on() || response.has_focus() {
|
||||||
&self.active
|
&self.active
|
||||||
} else if response.hovered() {
|
} else if response.hovered() || response.highlighted() {
|
||||||
&self.hovered
|
&self.hovered
|
||||||
} else {
|
} else {
|
||||||
&self.inactive
|
&self.inactive
|
||||||
|
@ -675,6 +693,7 @@ impl Default for Style {
|
||||||
override_font_id: None,
|
override_font_id: None,
|
||||||
override_text_style: None,
|
override_text_style: None,
|
||||||
text_styles: default_text_styles(),
|
text_styles: default_text_styles(),
|
||||||
|
drag_value_text_style: TextStyle::Button,
|
||||||
wrap: None,
|
wrap: None,
|
||||||
spacing: Spacing::default(),
|
spacing: Spacing::default(),
|
||||||
interaction: Interaction::default(),
|
interaction: Interaction::default(),
|
||||||
|
@ -704,6 +723,7 @@ impl Default for Spacing {
|
||||||
tooltip_width: 600.0,
|
tooltip_width: 600.0,
|
||||||
combo_height: 200.0,
|
combo_height: 200.0,
|
||||||
scroll_bar_width: 8.0,
|
scroll_bar_width: 8.0,
|
||||||
|
scroll_handle_min_length: 12.0,
|
||||||
scroll_bar_inner_margin: 4.0,
|
scroll_bar_inner_margin: 4.0,
|
||||||
scroll_bar_outer_margin: 0.0,
|
scroll_bar_outer_margin: 0.0,
|
||||||
indent_ends_with_horizontal_line: false,
|
indent_ends_with_horizontal_line: false,
|
||||||
|
@ -752,8 +772,11 @@ impl Visuals {
|
||||||
clip_rect_margin: 3.0, // should be at least half the size of the widest frame stroke + max WidgetVisuals::expansion
|
clip_rect_margin: 3.0, // should be at least half the size of the widest frame stroke + max WidgetVisuals::expansion
|
||||||
button_frame: true,
|
button_frame: true,
|
||||||
collapsing_header_frame: false,
|
collapsing_header_frame: false,
|
||||||
|
indent_has_left_vline: true,
|
||||||
|
|
||||||
striped: false,
|
striped: false,
|
||||||
|
|
||||||
|
slider_trailing_fill: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -918,6 +941,7 @@ impl Style {
|
||||||
override_font_id,
|
override_font_id,
|
||||||
override_text_style,
|
override_text_style,
|
||||||
text_styles,
|
text_styles,
|
||||||
|
drag_value_text_style,
|
||||||
wrap: _,
|
wrap: _,
|
||||||
spacing,
|
spacing,
|
||||||
interaction,
|
interaction,
|
||||||
|
@ -959,6 +983,19 @@ impl Style {
|
||||||
});
|
});
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
|
ui.label("Text style of DragValue:");
|
||||||
|
crate::ComboBox::from_id_source("drag_value_text_style")
|
||||||
|
.selected_text(drag_value_text_style.to_string())
|
||||||
|
.show_ui(ui, |ui| {
|
||||||
|
let all_text_styles = ui.style().text_styles();
|
||||||
|
for style in all_text_styles {
|
||||||
|
let text =
|
||||||
|
crate::RichText::new(style.to_string()).text_style(style.clone());
|
||||||
|
ui.selectable_value(drag_value_text_style, style, text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Animation duration:");
|
ui.label("Animation duration:");
|
||||||
ui.add(
|
ui.add(
|
||||||
Slider::new(animation_time, 0.0..=1.0)
|
Slider::new(animation_time, 0.0..=1.0)
|
||||||
|
@ -1016,6 +1053,7 @@ impl Spacing {
|
||||||
indent_ends_with_horizontal_line,
|
indent_ends_with_horizontal_line,
|
||||||
combo_height,
|
combo_height,
|
||||||
scroll_bar_width,
|
scroll_bar_width,
|
||||||
|
scroll_handle_min_length,
|
||||||
scroll_bar_inner_margin,
|
scroll_bar_inner_margin,
|
||||||
scroll_bar_outer_margin,
|
scroll_bar_outer_margin,
|
||||||
} = self;
|
} = self;
|
||||||
|
@ -1048,6 +1086,10 @@ impl Spacing {
|
||||||
ui.add(DragValue::new(scroll_bar_width).clamp_range(0.0..=32.0));
|
ui.add(DragValue::new(scroll_bar_width).clamp_range(0.0..=32.0));
|
||||||
ui.label("Scroll-bar width");
|
ui.label("Scroll-bar width");
|
||||||
});
|
});
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.add(DragValue::new(scroll_handle_min_length).clamp_range(0.0..=32.0));
|
||||||
|
ui.label("Scroll-bar handle min length");
|
||||||
|
});
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.add(DragValue::new(scroll_bar_inner_margin).clamp_range(0.0..=32.0));
|
ui.add(DragValue::new(scroll_bar_inner_margin).clamp_range(0.0..=32.0));
|
||||||
ui.label("Scroll-bar inner margin");
|
ui.label("Scroll-bar inner margin");
|
||||||
|
@ -1297,8 +1339,11 @@ impl Visuals {
|
||||||
clip_rect_margin,
|
clip_rect_margin,
|
||||||
button_frame,
|
button_frame,
|
||||||
collapsing_header_frame,
|
collapsing_header_frame,
|
||||||
|
indent_has_left_vline,
|
||||||
|
|
||||||
striped,
|
striped,
|
||||||
|
|
||||||
|
slider_trailing_fill,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
ui.collapsing("Background Colors", |ui| {
|
ui.collapsing("Background Colors", |ui| {
|
||||||
|
@ -1354,9 +1399,15 @@ impl Visuals {
|
||||||
|
|
||||||
ui.checkbox(button_frame, "Button has a frame");
|
ui.checkbox(button_frame, "Button has a frame");
|
||||||
ui.checkbox(collapsing_header_frame, "Collapsing header has a frame");
|
ui.checkbox(collapsing_header_frame, "Collapsing header has a frame");
|
||||||
|
ui.checkbox(
|
||||||
|
indent_has_left_vline,
|
||||||
|
"Paint a vertical line to the left of indented regions",
|
||||||
|
);
|
||||||
|
|
||||||
ui.checkbox(striped, "By default, add stripes to grids and tables?");
|
ui.checkbox(striped, "By default, add stripes to grids and tables?");
|
||||||
|
|
||||||
|
ui.checkbox(slider_trailing_fill, "Add trailing color to sliders");
|
||||||
|
|
||||||
ui.vertical_centered(|ui| reset_button(ui, self));
|
ui.vertical_centered(|ui| reset_button(ui, self));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1572,7 +1572,7 @@ impl Ui {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Se also [`crate::Image`] and [`crate::ImageButton`].
|
/// See also [`crate::Image`] and [`crate::ImageButton`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn image(&mut self, texture_id: impl Into<TextureId>, size: impl Into<Vec2>) -> Response {
|
pub fn image(&mut self, texture_id: impl Into<TextureId>, size: impl Into<Vec2>) -> Response {
|
||||||
Image::new(texture_id, size).ui(self)
|
Image::new(texture_id, size).ui(self)
|
||||||
|
@ -1789,25 +1789,32 @@ impl Ui {
|
||||||
};
|
};
|
||||||
let ret = add_contents(&mut child_ui);
|
let ret = add_contents(&mut child_ui);
|
||||||
|
|
||||||
|
let left_vline = self.visuals().indent_has_left_vline;
|
||||||
let end_with_horizontal_line = self.spacing().indent_ends_with_horizontal_line;
|
let end_with_horizontal_line = self.spacing().indent_ends_with_horizontal_line;
|
||||||
|
|
||||||
|
if left_vline || end_with_horizontal_line {
|
||||||
if end_with_horizontal_line {
|
if end_with_horizontal_line {
|
||||||
child_ui.add_space(4.0);
|
child_ui.add_space(4.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw a faint line on the left to mark the indented section
|
|
||||||
let stroke = self.visuals().widgets.noninteractive.bg_stroke;
|
let stroke = self.visuals().widgets.noninteractive.bg_stroke;
|
||||||
let left_top = child_rect.min - 0.5 * indent * Vec2::X;
|
let left_top = child_rect.min - 0.5 * indent * Vec2::X;
|
||||||
let left_top = self.painter().round_pos_to_pixels(left_top);
|
let left_top = self.painter().round_pos_to_pixels(left_top);
|
||||||
let left_bottom = pos2(left_top.x, child_ui.min_rect().bottom() - 2.0);
|
let left_bottom = pos2(left_top.x, child_ui.min_rect().bottom() - 2.0);
|
||||||
let left_bottom = self.painter().round_pos_to_pixels(left_bottom);
|
let left_bottom = self.painter().round_pos_to_pixels(left_bottom);
|
||||||
|
|
||||||
|
if left_vline {
|
||||||
|
// draw a faint line on the left to mark the indented section
|
||||||
self.painter.line_segment([left_top, left_bottom], stroke);
|
self.painter.line_segment([left_top, left_bottom], stroke);
|
||||||
|
}
|
||||||
|
|
||||||
if end_with_horizontal_line {
|
if end_with_horizontal_line {
|
||||||
let fudge = 2.0; // looks nicer with button rounding in collapsing headers
|
let fudge = 2.0; // looks nicer with button rounding in collapsing headers
|
||||||
let right_bottom = pos2(child_ui.min_rect().right() - fudge, left_bottom.y);
|
let right_bottom = pos2(child_ui.min_rect().right() - fudge, left_bottom.y);
|
||||||
self.painter
|
self.painter
|
||||||
.line_segment([left_bottom, right_bottom], stroke);
|
.line_segment([left_bottom, right_bottom], stroke);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let response = self.allocate_rect(child_ui.min_rect(), Sense::hover());
|
let response = self.allocate_rect(child_ui.min_rect(), Sense::hover());
|
||||||
InnerResponse::new(ret, response)
|
InnerResponse::new(ret, response)
|
||||||
|
@ -2167,7 +2174,6 @@ impl Ui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
/// Create a menu button with an image that when clicked will show the given menu.
|
/// Create a menu button with an image that when clicked will show the given menu.
|
||||||
///
|
///
|
||||||
/// If called from within a menu this will instead create a button for a sub-menu.
|
/// If called from within a menu this will instead create a button for a sub-menu.
|
||||||
|
@ -2191,6 +2197,7 @@ impl Ui {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// See also: [`Self::close_menu`] and [`Response::context_menu`].
|
/// See also: [`Self::close_menu`] and [`Response::context_menu`].
|
||||||
|
#[inline]
|
||||||
pub fn menu_image_button<R>(
|
pub fn menu_image_button<R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
texture_id: TextureId,
|
texture_id: TextureId,
|
||||||
|
|
|
@ -269,6 +269,10 @@ impl<'a> Checkbox<'a> {
|
||||||
text: text.into(),
|
text: text.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn without_text(checked: &'a mut bool) -> Self {
|
||||||
|
Self::new(checked, WidgetText::default())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Widget for Checkbox<'a> {
|
impl<'a> Widget for Checkbox<'a> {
|
||||||
|
|
|
@ -456,19 +456,28 @@ impl<'a> Widget for DragValue<'a> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let text_style = ui.style().drag_value_text_style.clone();
|
||||||
|
|
||||||
// some clones below are redundant if AccessKit is disabled
|
// some clones below are redundant if AccessKit is disabled
|
||||||
#[allow(clippy::redundant_clone)]
|
#[allow(clippy::redundant_clone)]
|
||||||
let mut response = if is_kb_editing {
|
let mut response = if is_kb_editing {
|
||||||
let button_width = ui.spacing().interact_size.x;
|
|
||||||
let mut value_text = ui
|
let mut value_text = ui
|
||||||
.memory_mut(|mem| mem.drag_value.edit_string.take())
|
.memory_mut(|mem| mem.drag_value.edit_string.take())
|
||||||
.unwrap_or_else(|| value_text.clone());
|
.unwrap_or_else(|| value_text.clone());
|
||||||
let response = ui.add(
|
let response = ui.add(
|
||||||
TextEdit::singleline(&mut value_text)
|
TextEdit::singleline(&mut value_text)
|
||||||
|
.clip_text(false)
|
||||||
|
.horizontal_align(ui.layout().horizontal_align())
|
||||||
|
.vertical_align(ui.layout().vertical_align())
|
||||||
|
.margin(ui.spacing().button_padding)
|
||||||
|
.min_size(ui.spacing().interact_size)
|
||||||
.id(id)
|
.id(id)
|
||||||
.desired_width(button_width)
|
.desired_width(ui.spacing().interact_size.x)
|
||||||
.font(TextStyle::Monospace),
|
.font(text_style),
|
||||||
);
|
);
|
||||||
|
// Only update the value when the user presses enter, or clicks elsewhere. NOT every frame.
|
||||||
|
// See https://github.com/emilk/egui/issues/2687
|
||||||
|
if response.lost_focus() {
|
||||||
let parsed_value = match custom_parser {
|
let parsed_value = match custom_parser {
|
||||||
Some(parser) => parser(&value_text),
|
Some(parser) => parser(&value_text),
|
||||||
None => value_text.parse().ok(),
|
None => value_text.parse().ok(),
|
||||||
|
@ -477,11 +486,13 @@ impl<'a> Widget for DragValue<'a> {
|
||||||
let parsed_value = clamp_to_range(parsed_value, clamp_range.clone());
|
let parsed_value = clamp_to_range(parsed_value, clamp_range.clone());
|
||||||
set(&mut get_set_value, parsed_value);
|
set(&mut get_set_value, parsed_value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ui.memory_mut(|mem| mem.drag_value.edit_string = Some(value_text));
|
ui.memory_mut(|mem| mem.drag_value.edit_string = Some(value_text));
|
||||||
response
|
response
|
||||||
} else {
|
} else {
|
||||||
let button = Button::new(
|
let button = Button::new(
|
||||||
RichText::new(format!("{}{}{}", prefix, value_text.clone(), suffix)).monospace(),
|
RichText::new(format!("{}{}{}", prefix, value_text.clone(), suffix))
|
||||||
|
.text_style(text_style),
|
||||||
)
|
)
|
||||||
.wrap(false)
|
.wrap(false)
|
||||||
.sense(Sense::click_and_drag())
|
.sense(Sense::click_and_drag())
|
||||||
|
@ -504,6 +515,12 @@ impl<'a> Widget for DragValue<'a> {
|
||||||
mem.drag_value.edit_string = None;
|
mem.drag_value.edit_string = None;
|
||||||
mem.request_focus(id);
|
mem.request_focus(id);
|
||||||
});
|
});
|
||||||
|
let mut state = TextEdit::load_state(ui.ctx(), id).unwrap_or_default();
|
||||||
|
state.set_ccursor_range(Some(text::CCursorRange::two(
|
||||||
|
epaint::text::cursor::CCursor::default(),
|
||||||
|
epaint::text::cursor::CCursor::new(value_text.chars().count()),
|
||||||
|
)));
|
||||||
|
state.store(ui.ctx(), response.id);
|
||||||
} else if response.dragged() {
|
} else if response.dragged() {
|
||||||
ui.ctx().set_cursor_icon(CursorIcon::ResizeHorizontal);
|
ui.ctx().set_cursor_icon(CursorIcon::ResizeHorizontal);
|
||||||
|
|
||||||
|
@ -548,28 +565,28 @@ impl<'a> Widget for DragValue<'a> {
|
||||||
response.widget_info(|| WidgetInfo::drag_value(value));
|
response.widget_info(|| WidgetInfo::drag_value(value));
|
||||||
|
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
ui.ctx().accesskit_node(response.id, |node| {
|
ui.ctx().accesskit_node_builder(response.id, |builder| {
|
||||||
use accesskit::Action;
|
use accesskit::Action;
|
||||||
// If either end of the range is unbounded, it's better
|
// If either end of the range is unbounded, it's better
|
||||||
// to leave the corresponding AccessKit field set to None,
|
// to leave the corresponding AccessKit field set to None,
|
||||||
// to allow for platform-specific default behavior.
|
// to allow for platform-specific default behavior.
|
||||||
if clamp_range.start().is_finite() {
|
if clamp_range.start().is_finite() {
|
||||||
node.min_numeric_value = Some(*clamp_range.start());
|
builder.set_min_numeric_value(*clamp_range.start());
|
||||||
}
|
}
|
||||||
if clamp_range.end().is_finite() {
|
if clamp_range.end().is_finite() {
|
||||||
node.max_numeric_value = Some(*clamp_range.end());
|
builder.set_max_numeric_value(*clamp_range.end());
|
||||||
}
|
}
|
||||||
node.numeric_value_step = Some(speed);
|
builder.set_numeric_value_step(speed);
|
||||||
node.actions |= Action::SetValue;
|
builder.add_action(Action::SetValue);
|
||||||
if value < *clamp_range.end() {
|
if value < *clamp_range.end() {
|
||||||
node.actions |= Action::Increment;
|
builder.add_action(Action::Increment);
|
||||||
}
|
}
|
||||||
if value > *clamp_range.start() {
|
if value > *clamp_range.start() {
|
||||||
node.actions |= Action::Decrement;
|
builder.add_action(Action::Decrement);
|
||||||
}
|
}
|
||||||
// The name field is set to the current value by the button,
|
// The name field is set to the current value by the button,
|
||||||
// but we don't want it set that way on this widget type.
|
// but we don't want it set that way on this widget type.
|
||||||
node.name = None;
|
builder.clear_name();
|
||||||
// Always expose the value as a string. This makes the widget
|
// Always expose the value as a string. This makes the widget
|
||||||
// more stable to accessibility users as it switches
|
// more stable to accessibility users as it switches
|
||||||
// between edit and button modes. This is particularly important
|
// between edit and button modes. This is particularly important
|
||||||
|
@ -590,7 +607,7 @@ impl<'a> Widget for DragValue<'a> {
|
||||||
// when in edit mode.
|
// when in edit mode.
|
||||||
if !is_kb_editing {
|
if !is_kb_editing {
|
||||||
let value_text = format!("{}{}{}", prefix, value_text, suffix);
|
let value_text = format!("{}{}{}", prefix, value_text, suffix);
|
||||||
node.value = Some(value_text.into());
|
builder.set_value(value_text);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,7 @@ impl Widget for Label {
|
||||||
if ui.is_rect_visible(response.rect) {
|
if ui.is_rect_visible(response.rect) {
|
||||||
let response_color = ui.style().interact(&response).text_color();
|
let response_color = ui.style().interact(&response).text_color();
|
||||||
|
|
||||||
let underline = if response.has_focus() {
|
let underline = if response.has_focus() || response.highlighted() {
|
||||||
Stroke::new(1.0, response_color)
|
Stroke::new(1.0, response_color)
|
||||||
} else {
|
} else {
|
||||||
Stroke::NONE
|
Stroke::NONE
|
||||||
|
|
|
@ -742,7 +742,7 @@ impl Plot {
|
||||||
});
|
});
|
||||||
|
|
||||||
let PlotMemory {
|
let PlotMemory {
|
||||||
mut bounds_modified,
|
bounds_modified,
|
||||||
mut hovered_entry,
|
mut hovered_entry,
|
||||||
mut hidden_items,
|
mut hidden_items,
|
||||||
last_screen_transform,
|
last_screen_transform,
|
||||||
|
@ -754,6 +754,7 @@ impl Plot {
|
||||||
items: Vec::new(),
|
items: Vec::new(),
|
||||||
next_auto_color_idx: 0,
|
next_auto_color_idx: 0,
|
||||||
last_screen_transform,
|
last_screen_transform,
|
||||||
|
bounds_modified,
|
||||||
response,
|
response,
|
||||||
ctx: ui.ctx().clone(),
|
ctx: ui.ctx().clone(),
|
||||||
};
|
};
|
||||||
|
@ -762,6 +763,7 @@ impl Plot {
|
||||||
mut items,
|
mut items,
|
||||||
mut response,
|
mut response,
|
||||||
last_screen_transform,
|
last_screen_transform,
|
||||||
|
mut bounds_modified,
|
||||||
..
|
..
|
||||||
} = plot_ui;
|
} = plot_ui;
|
||||||
|
|
||||||
|
@ -1042,6 +1044,7 @@ pub struct PlotUi {
|
||||||
items: Vec<Box<dyn PlotItem>>,
|
items: Vec<Box<dyn PlotItem>>,
|
||||||
next_auto_color_idx: usize,
|
next_auto_color_idx: usize,
|
||||||
last_screen_transform: ScreenTransform,
|
last_screen_transform: ScreenTransform,
|
||||||
|
bounds_modified: AxisBools,
|
||||||
response: Response,
|
response: Response,
|
||||||
ctx: Context,
|
ctx: Context,
|
||||||
}
|
}
|
||||||
|
@ -1069,11 +1072,13 @@ impl PlotUi {
|
||||||
/// Set the plot bounds. Can be useful for implementing alternative plot navigation methods.
|
/// Set the plot bounds. Can be useful for implementing alternative plot navigation methods.
|
||||||
pub fn set_plot_bounds(&mut self, plot_bounds: PlotBounds) {
|
pub fn set_plot_bounds(&mut self, plot_bounds: PlotBounds) {
|
||||||
self.last_screen_transform.set_bounds(plot_bounds);
|
self.last_screen_transform.set_bounds(plot_bounds);
|
||||||
|
self.bounds_modified = true.into();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Move the plot bounds. Can be useful for implementing alternative plot navigation methods.
|
/// Move the plot bounds. Can be useful for implementing alternative plot navigation methods.
|
||||||
pub fn translate_bounds(&mut self, delta_pos: Vec2) {
|
pub fn translate_bounds(&mut self, delta_pos: Vec2) {
|
||||||
self.last_screen_transform.translate_bounds(delta_pos);
|
self.last_screen_transform.translate_bounds(delta_pos);
|
||||||
|
self.bounds_modified = true.into();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the plot area is currently hovered.
|
/// Returns `true` if the plot area is currently hovered.
|
||||||
|
|
|
@ -61,7 +61,7 @@ impl Widget for SelectableLabel {
|
||||||
|
|
||||||
let visuals = ui.style().interact_selectable(&response, selected);
|
let visuals = ui.style().interact_selectable(&response, selected);
|
||||||
|
|
||||||
if selected || response.hovered() || response.has_focus() {
|
if selected || response.hovered() || response.highlighted() || response.has_focus() {
|
||||||
let rect = rect.expand(visuals.expansion);
|
let rect = rect.expand(visuals.expansion);
|
||||||
|
|
||||||
ui.painter().rect(
|
ui.painter().rect(
|
||||||
|
|
|
@ -14,6 +14,7 @@ use crate::*;
|
||||||
#[must_use = "You should put this widget in an ui with `ui.add(widget);`"]
|
#[must_use = "You should put this widget in an ui with `ui.add(widget);`"]
|
||||||
pub struct Separator {
|
pub struct Separator {
|
||||||
spacing: f32,
|
spacing: f32,
|
||||||
|
grow: f32,
|
||||||
is_horizontal_line: Option<bool>,
|
is_horizontal_line: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ impl Default for Separator {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
spacing: 6.0,
|
spacing: 6.0,
|
||||||
|
grow: 0.0,
|
||||||
is_horizontal_line: None,
|
is_horizontal_line: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,12 +30,19 @@ impl Default for Separator {
|
||||||
|
|
||||||
impl Separator {
|
impl Separator {
|
||||||
/// How much space we take up. The line is painted in the middle of this.
|
/// How much space we take up. The line is painted in the middle of this.
|
||||||
|
///
|
||||||
|
/// In a vertical layout, with a horizontal Separator,
|
||||||
|
/// this is the height of the separator widget.
|
||||||
|
///
|
||||||
|
/// In a horizontal layout, with a vertical Separator,
|
||||||
|
/// this is the width of the separator widget.
|
||||||
pub fn spacing(mut self, spacing: f32) -> Self {
|
pub fn spacing(mut self, spacing: f32) -> Self {
|
||||||
self.spacing = spacing;
|
self.spacing = spacing;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Explicitly ask for a horizontal line.
|
/// Explicitly ask for a horizontal line.
|
||||||
|
///
|
||||||
/// By default you will get a horizontal line in vertical layouts,
|
/// By default you will get a horizontal line in vertical layouts,
|
||||||
/// and a vertical line in horizontal layouts.
|
/// and a vertical line in horizontal layouts.
|
||||||
pub fn horizontal(mut self) -> Self {
|
pub fn horizontal(mut self) -> Self {
|
||||||
|
@ -42,18 +51,40 @@ impl Separator {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Explicitly ask for a vertical line.
|
/// Explicitly ask for a vertical line.
|
||||||
|
///
|
||||||
/// By default you will get a horizontal line in vertical layouts,
|
/// By default you will get a horizontal line in vertical layouts,
|
||||||
/// and a vertical line in horizontal layouts.
|
/// and a vertical line in horizontal layouts.
|
||||||
pub fn vertical(mut self) -> Self {
|
pub fn vertical(mut self) -> Self {
|
||||||
self.is_horizontal_line = Some(false);
|
self.is_horizontal_line = Some(false);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Extend each end of the separator line by this much.
|
||||||
|
///
|
||||||
|
/// The default is to take up the available width/height of the parent.
|
||||||
|
///
|
||||||
|
/// This will make the line extend outside the parent ui.
|
||||||
|
pub fn grow(mut self, extra: f32) -> Self {
|
||||||
|
self.grow += extra;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Contract each end of the separator line by this much.
|
||||||
|
///
|
||||||
|
/// The default is to take up the available width/height of the parent.
|
||||||
|
///
|
||||||
|
/// This effectively adds margins to the line.
|
||||||
|
pub fn shrink(mut self, shrink: f32) -> Self {
|
||||||
|
self.grow -= shrink;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget for Separator {
|
impl Widget for Separator {
|
||||||
fn ui(self, ui: &mut Ui) -> Response {
|
fn ui(self, ui: &mut Ui) -> Response {
|
||||||
let Separator {
|
let Separator {
|
||||||
spacing,
|
spacing,
|
||||||
|
grow,
|
||||||
is_horizontal_line,
|
is_horizontal_line,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
|
@ -75,14 +106,14 @@ impl Widget for Separator {
|
||||||
let painter = ui.painter();
|
let painter = ui.painter();
|
||||||
if is_horizontal_line {
|
if is_horizontal_line {
|
||||||
painter.hline(
|
painter.hline(
|
||||||
rect.x_range(),
|
(rect.left() - grow)..=(rect.right() + grow),
|
||||||
painter.round_to_pixel(rect.center().y),
|
painter.round_to_pixel(rect.center().y),
|
||||||
stroke,
|
stroke,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
painter.vline(
|
painter.vline(
|
||||||
painter.round_to_pixel(rect.center().x),
|
painter.round_to_pixel(rect.center().x),
|
||||||
rect.y_range(),
|
(rect.top() - grow)..=(rect.bottom() + grow),
|
||||||
stroke,
|
stroke,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,7 @@ pub struct Slider<'a> {
|
||||||
max_decimals: Option<usize>,
|
max_decimals: Option<usize>,
|
||||||
custom_formatter: Option<NumFormatter<'a>>,
|
custom_formatter: Option<NumFormatter<'a>>,
|
||||||
custom_parser: Option<NumParser<'a>>,
|
custom_parser: Option<NumParser<'a>>,
|
||||||
|
trailing_fill: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Slider<'a> {
|
impl<'a> Slider<'a> {
|
||||||
|
@ -129,6 +130,7 @@ impl<'a> Slider<'a> {
|
||||||
max_decimals: None,
|
max_decimals: None,
|
||||||
custom_formatter: None,
|
custom_formatter: None,
|
||||||
custom_parser: None,
|
custom_parser: None,
|
||||||
|
trailing_fill: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,6 +271,17 @@ impl<'a> Slider<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Display trailing color behind the slider's circle. Default is OFF.
|
||||||
|
///
|
||||||
|
/// This setting can be enabled globally for all sliders with [`Visuals::slider_trailing_fill`].
|
||||||
|
/// Toggling it here will override the above setting ONLY for this individual slider.
|
||||||
|
///
|
||||||
|
/// The fill color will be taken from `selection.bg_fill` in your [`Visuals`], the same as a [`ProgressBar`].
|
||||||
|
pub fn trailing_fill(mut self, trailing_fill: bool) -> Self {
|
||||||
|
self.trailing_fill = Some(trailing_fill);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Set custom formatter defining how numbers are converted into text.
|
/// Set custom formatter defining how numbers are converted into text.
|
||||||
///
|
///
|
||||||
/// A custom formatter takes a `f64` for the numeric value and a `RangeInclusive<usize>` representing
|
/// A custom formatter takes a `f64` for the numeric value and a `RangeInclusive<usize>` representing
|
||||||
|
@ -616,18 +629,40 @@ impl<'a> Slider<'a> {
|
||||||
let rail_radius = ui.painter().round_to_pixel(self.rail_radius_limit(rect));
|
let rail_radius = ui.painter().round_to_pixel(self.rail_radius_limit(rect));
|
||||||
let rail_rect = self.rail_rect(rect, rail_radius);
|
let rail_rect = self.rail_rect(rect, rail_radius);
|
||||||
|
|
||||||
let position_1d = self.position_from_value(value, position_range);
|
|
||||||
|
|
||||||
let visuals = ui.style().interact(response);
|
let visuals = ui.style().interact(response);
|
||||||
ui.painter().add(epaint::RectShape {
|
let widget_visuals = &ui.visuals().widgets;
|
||||||
rect: rail_rect,
|
|
||||||
rounding: ui.visuals().widgets.inactive.rounding,
|
|
||||||
fill: ui.visuals().widgets.inactive.bg_fill,
|
|
||||||
stroke: Default::default(),
|
|
||||||
});
|
|
||||||
|
|
||||||
|
ui.painter().rect_filled(
|
||||||
|
rail_rect,
|
||||||
|
widget_visuals.inactive.rounding,
|
||||||
|
widget_visuals.inactive.bg_fill,
|
||||||
|
);
|
||||||
|
|
||||||
|
let position_1d = self.position_from_value(value, position_range);
|
||||||
let center = self.marker_center(position_1d, &rail_rect);
|
let center = self.marker_center(position_1d, &rail_rect);
|
||||||
|
|
||||||
|
// Decide if we should add trailing fill.
|
||||||
|
let trailing_fill = self
|
||||||
|
.trailing_fill
|
||||||
|
.unwrap_or_else(|| ui.visuals().slider_trailing_fill);
|
||||||
|
|
||||||
|
// Paint trailing fill.
|
||||||
|
if trailing_fill {
|
||||||
|
let mut trailing_rail_rect = rail_rect;
|
||||||
|
|
||||||
|
// The trailing rect has to be drawn differently depending on the orientation.
|
||||||
|
match self.orientation {
|
||||||
|
SliderOrientation::Vertical => trailing_rail_rect.min.y = center.y,
|
||||||
|
SliderOrientation::Horizontal => trailing_rail_rect.max.x = center.x,
|
||||||
|
};
|
||||||
|
|
||||||
|
ui.painter().rect_filled(
|
||||||
|
trailing_rail_rect,
|
||||||
|
widget_visuals.inactive.rounding,
|
||||||
|
ui.visuals().selection.bg_fill,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
ui.painter().add(epaint::CircleShape {
|
ui.painter().add(epaint::CircleShape {
|
||||||
center,
|
center,
|
||||||
radius: self.handle_radius(rect) + visuals.expansion,
|
radius: self.handle_radius(rect) + visuals.expansion,
|
||||||
|
@ -757,18 +792,20 @@ impl<'a> Slider<'a> {
|
||||||
response.widget_info(|| WidgetInfo::slider(value, self.text.text()));
|
response.widget_info(|| WidgetInfo::slider(value, self.text.text()));
|
||||||
|
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
ui.ctx().accesskit_node(response.id, |node| {
|
ui.ctx().accesskit_node_builder(response.id, |builder| {
|
||||||
use accesskit::Action;
|
use accesskit::Action;
|
||||||
node.min_numeric_value = Some(*self.range.start());
|
builder.set_min_numeric_value(*self.range.start());
|
||||||
node.max_numeric_value = Some(*self.range.end());
|
builder.set_max_numeric_value(*self.range.end());
|
||||||
node.numeric_value_step = self.step;
|
if let Some(step) = self.step {
|
||||||
node.actions |= Action::SetValue;
|
builder.set_numeric_value_step(step);
|
||||||
|
}
|
||||||
|
builder.add_action(Action::SetValue);
|
||||||
let clamp_range = self.clamp_range();
|
let clamp_range = self.clamp_range();
|
||||||
if value < *clamp_range.end() {
|
if value < *clamp_range.end() {
|
||||||
node.actions |= Action::Increment;
|
builder.add_action(Action::Increment);
|
||||||
}
|
}
|
||||||
if value > *clamp_range.start() {
|
if value > *clamp_range.start() {
|
||||||
node.actions |= Action::Decrement;
|
builder.add_action(Action::Decrement);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,9 @@ pub struct TextEdit<'t> {
|
||||||
desired_height_rows: usize,
|
desired_height_rows: usize,
|
||||||
lock_focus: bool,
|
lock_focus: bool,
|
||||||
cursor_at_end: bool,
|
cursor_at_end: bool,
|
||||||
|
min_size: Vec2,
|
||||||
|
align: Align2,
|
||||||
|
clip_text: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'t> WidgetWithState for TextEdit<'t> {
|
impl<'t> WidgetWithState for TextEdit<'t> {
|
||||||
|
@ -89,6 +92,7 @@ impl<'t> TextEdit<'t> {
|
||||||
Self {
|
Self {
|
||||||
desired_height_rows: 1,
|
desired_height_rows: 1,
|
||||||
multiline: false,
|
multiline: false,
|
||||||
|
clip_text: true,
|
||||||
..Self::multiline(text)
|
..Self::multiline(text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,6 +116,9 @@ impl<'t> TextEdit<'t> {
|
||||||
desired_height_rows: 4,
|
desired_height_rows: 4,
|
||||||
lock_focus: false,
|
lock_focus: false,
|
||||||
cursor_at_end: true,
|
cursor_at_end: true,
|
||||||
|
min_size: Vec2::ZERO,
|
||||||
|
align: Align2::LEFT_TOP,
|
||||||
|
clip_text: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,6 +276,37 @@ impl<'t> TextEdit<'t> {
|
||||||
self.cursor_at_end = b;
|
self.cursor_at_end = b;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// When `true` (default), overflowing text will be clipped.
|
||||||
|
///
|
||||||
|
/// When `false`, widget width will expand to make all text visible.
|
||||||
|
///
|
||||||
|
/// This only works for singleline [`TextEdit`].
|
||||||
|
pub fn clip_text(mut self, b: bool) -> Self {
|
||||||
|
// always show everything in multiline
|
||||||
|
if !self.multiline {
|
||||||
|
self.clip_text = b;
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the horizontal align of the inner text.
|
||||||
|
pub fn horizontal_align(mut self, align: Align) -> Self {
|
||||||
|
self.align.0[0] = align;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the vertical align of the inner text.
|
||||||
|
pub fn vertical_align(mut self, align: Align) -> Self {
|
||||||
|
self.align.0[1] = align;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the minimum size of the [`TextEdit`].
|
||||||
|
pub fn min_size(mut self, min_size: Vec2) -> Self {
|
||||||
|
self.min_size = min_size;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -364,13 +402,16 @@ impl<'t> TextEdit<'t> {
|
||||||
layouter,
|
layouter,
|
||||||
password,
|
password,
|
||||||
frame: _,
|
frame: _,
|
||||||
margin: _,
|
margin,
|
||||||
multiline,
|
multiline,
|
||||||
interactive,
|
interactive,
|
||||||
desired_width,
|
desired_width,
|
||||||
desired_height_rows,
|
desired_height_rows,
|
||||||
lock_focus,
|
lock_focus,
|
||||||
cursor_at_end,
|
cursor_at_end,
|
||||||
|
min_size,
|
||||||
|
align,
|
||||||
|
clip_text,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let text_color = text_color
|
let text_color = text_color
|
||||||
|
@ -389,7 +430,7 @@ impl<'t> TextEdit<'t> {
|
||||||
available_width
|
available_width
|
||||||
} else {
|
} else {
|
||||||
desired_width.min(available_width)
|
desired_width.min(available_width)
|
||||||
};
|
} - margin.x * 2.0;
|
||||||
|
|
||||||
let font_id_clone = font_id.clone();
|
let font_id_clone = font_id.clone();
|
||||||
let mut default_layouter = move |ui: &Ui, text: &str, wrap_width: f32| {
|
let mut default_layouter = move |ui: &Ui, text: &str, wrap_width: f32| {
|
||||||
|
@ -406,13 +447,14 @@ impl<'t> TextEdit<'t> {
|
||||||
|
|
||||||
let mut galley = layouter(ui, text.as_str(), wrap_width);
|
let mut galley = layouter(ui, text.as_str(), wrap_width);
|
||||||
|
|
||||||
let desired_width = if multiline {
|
let desired_width = if clip_text {
|
||||||
galley.size().x.max(wrap_width) // always show everything in multiline
|
wrap_width // visual clipping with scroll in singleline input.
|
||||||
} else {
|
} else {
|
||||||
wrap_width // visual clipping with scroll in singleline input. TODO(emilk): opt-in/out?
|
galley.size().x.max(wrap_width)
|
||||||
};
|
};
|
||||||
let desired_height = (desired_height_rows.at_least(1) as f32) * row_height;
|
let desired_height = (desired_height_rows.at_least(1) as f32) * row_height;
|
||||||
let desired_size = vec2(desired_width, galley.size().y.max(desired_height));
|
let desired_size = vec2(desired_width, galley.size().y.max(desired_height))
|
||||||
|
.at_least(min_size - margin * 2.0);
|
||||||
|
|
||||||
let (auto_id, rect) = ui.allocate_space(desired_size);
|
let (auto_id, rect) = ui.allocate_space(desired_size);
|
||||||
|
|
||||||
|
@ -547,10 +589,14 @@ impl<'t> TextEdit<'t> {
|
||||||
cursor_range = Some(new_cursor_range);
|
cursor_range = Some(new_cursor_range);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut text_draw_pos = response.rect.min;
|
let mut text_draw_pos = align
|
||||||
|
.align_size_within_rect(galley.size(), response.rect)
|
||||||
|
.intersect(response.rect) // limit pos to the response rect area
|
||||||
|
.min;
|
||||||
|
let align_offset = response.rect.left() - text_draw_pos.x;
|
||||||
|
|
||||||
// Visual clipping for singleline text editor with text larger than width
|
// Visual clipping for singleline text editor with text larger than width
|
||||||
if !multiline {
|
if clip_text && align_offset == 0.0 {
|
||||||
let cursor_pos = match (cursor_range, ui.memory(|mem| mem.has_focus(id))) {
|
let cursor_pos = match (cursor_range, ui.memory(|mem| mem.has_focus(id))) {
|
||||||
(Some(cursor_range), true) => galley.pos_from_cursor(&cursor_range.primary).min.x,
|
(Some(cursor_range), true) => galley.pos_from_cursor(&cursor_range.primary).min.x,
|
||||||
_ => 0.0,
|
_ => 0.0,
|
||||||
|
@ -573,6 +619,8 @@ impl<'t> TextEdit<'t> {
|
||||||
|
|
||||||
state.singleline_offset = offset_x;
|
state.singleline_offset = offset_x;
|
||||||
text_draw_pos -= vec2(offset_x, 0.0);
|
text_draw_pos -= vec2(offset_x, 0.0);
|
||||||
|
} else {
|
||||||
|
state.singleline_offset = align_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
let selection_changed = if let (Some(cursor_range), Some(prev_cursor_range)) =
|
let selection_changed = if let (Some(cursor_range), Some(prev_cursor_range)) =
|
||||||
|
@ -666,7 +714,7 @@ impl<'t> TextEdit<'t> {
|
||||||
|
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
{
|
{
|
||||||
let parent_id = ui.ctx().accesskit_node(response.id, |node| {
|
let parent_id = ui.ctx().accesskit_node_builder(response.id, |builder| {
|
||||||
use accesskit::{TextPosition, TextSelection};
|
use accesskit::{TextPosition, TextSelection};
|
||||||
|
|
||||||
let parent_id = response.id;
|
let parent_id = response.id;
|
||||||
|
@ -674,7 +722,7 @@ impl<'t> TextEdit<'t> {
|
||||||
if let Some(cursor_range) = &cursor_range {
|
if let Some(cursor_range) = &cursor_range {
|
||||||
let anchor = &cursor_range.secondary.rcursor;
|
let anchor = &cursor_range.secondary.rcursor;
|
||||||
let focus = &cursor_range.primary.rcursor;
|
let focus = &cursor_range.primary.rcursor;
|
||||||
node.text_selection = Some(TextSelection {
|
builder.set_text_selection(TextSelection {
|
||||||
anchor: TextPosition {
|
anchor: TextPosition {
|
||||||
node: parent_id.with(anchor.row).accesskit_id(),
|
node: parent_id.with(anchor.row).accesskit_id(),
|
||||||
character_index: anchor.column,
|
character_index: anchor.column,
|
||||||
|
@ -686,8 +734,10 @@ impl<'t> TextEdit<'t> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
node.default_action_verb = Some(accesskit::DefaultActionVerb::Focus);
|
builder.set_default_action_verb(accesskit::DefaultActionVerb::Focus);
|
||||||
node.multiline = self.multiline;
|
if self.multiline {
|
||||||
|
builder.set_multiline();
|
||||||
|
}
|
||||||
|
|
||||||
parent_id
|
parent_id
|
||||||
});
|
});
|
||||||
|
@ -699,16 +749,16 @@ impl<'t> TextEdit<'t> {
|
||||||
ui.ctx().with_accessibility_parent(parent_id, || {
|
ui.ctx().with_accessibility_parent(parent_id, || {
|
||||||
for (i, row) in galley.rows.iter().enumerate() {
|
for (i, row) in galley.rows.iter().enumerate() {
|
||||||
let id = parent_id.with(i);
|
let id = parent_id.with(i);
|
||||||
ui.ctx().accesskit_node(id, |node| {
|
ui.ctx().accesskit_node_builder(id, |builder| {
|
||||||
node.role = Role::InlineTextBox;
|
builder.set_role(Role::InlineTextBox);
|
||||||
let rect = row.rect.translate(text_draw_pos.to_vec2());
|
let rect = row.rect.translate(text_draw_pos.to_vec2());
|
||||||
node.bounds = Some(accesskit::kurbo::Rect {
|
builder.set_bounds(accesskit::Rect {
|
||||||
x0: rect.min.x.into(),
|
x0: rect.min.x.into(),
|
||||||
y0: rect.min.y.into(),
|
y0: rect.min.y.into(),
|
||||||
x1: rect.max.x.into(),
|
x1: rect.max.x.into(),
|
||||||
y1: rect.max.y.into(),
|
y1: rect.max.y.into(),
|
||||||
});
|
});
|
||||||
node.text_direction = Some(TextDirection::LeftToRight);
|
builder.set_text_direction(TextDirection::LeftToRight);
|
||||||
// TODO(mwcampbell): Set more node fields for the row
|
// TODO(mwcampbell): Set more node fields for the row
|
||||||
// once AccessKit adapters expose text formatting info.
|
// once AccessKit adapters expose text formatting info.
|
||||||
|
|
||||||
|
@ -748,11 +798,11 @@ impl<'t> TextEdit<'t> {
|
||||||
}
|
}
|
||||||
word_lengths.push((character_lengths.len() - last_word_start) as _);
|
word_lengths.push((character_lengths.len() - last_word_start) as _);
|
||||||
|
|
||||||
node.value = Some(value.into());
|
builder.set_value(value);
|
||||||
node.character_lengths = character_lengths.into();
|
builder.set_character_lengths(character_lengths);
|
||||||
node.character_positions = Some(character_positions.into());
|
builder.set_character_positions(character_positions);
|
||||||
node.character_widths = Some(character_widths.into());
|
builder.set_character_widths(character_widths);
|
||||||
node.word_lengths = word_lengths.into();
|
builder.set_word_lengths(word_lengths);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "egui_demo_app"
|
name = "egui_demo_app"
|
||||||
version = "0.20.0"
|
version = "0.21.0"
|
||||||
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
@ -20,7 +20,7 @@ default = ["glow", "persistence"]
|
||||||
|
|
||||||
http = ["ehttp", "image", "poll-promise", "egui_extras/image"]
|
http = ["ehttp", "image", "poll-promise", "egui_extras/image"]
|
||||||
persistence = ["eframe/persistence", "egui/persistence", "serde"]
|
persistence = ["eframe/persistence", "egui/persistence", "serde"]
|
||||||
screen_reader = ["eframe/screen_reader"] # experimental
|
web_screen_reader = ["eframe/web_screen_reader"] # experimental
|
||||||
serde = ["dep:serde", "egui_demo_lib/serde", "egui/serde"]
|
serde = ["dep:serde", "egui_demo_lib/serde", "egui/serde"]
|
||||||
syntax_highlighting = ["egui_demo_lib/syntax_highlighting"]
|
syntax_highlighting = ["egui_demo_lib/syntax_highlighting"]
|
||||||
|
|
||||||
|
@ -30,11 +30,11 @@ wgpu = ["eframe/wgpu", "bytemuck"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = { version = "0.4", features = ["js-sys", "wasmbind"] }
|
chrono = { version = "0.4", features = ["js-sys", "wasmbind"] }
|
||||||
eframe = { version = "0.20.0", path = "../eframe", default-features = false }
|
eframe = { version = "0.21.0", path = "../eframe", default-features = false }
|
||||||
egui = { version = "0.20.0", path = "../egui", features = [
|
egui = { version = "0.21.0", path = "../egui", features = [
|
||||||
"extra_debug_asserts",
|
"extra_debug_asserts",
|
||||||
] }
|
] }
|
||||||
egui_demo_lib = { version = "0.20.0", path = "../egui_demo_lib", features = [
|
egui_demo_lib = { version = "0.21.0", path = "../egui_demo_lib", features = [
|
||||||
"chrono",
|
"chrono",
|
||||||
] }
|
] }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
|
@ -42,7 +42,7 @@ tracing = "0.1"
|
||||||
# Optional dependencies:
|
# Optional dependencies:
|
||||||
|
|
||||||
bytemuck = { version = "1.7.1", optional = true }
|
bytemuck = { version = "1.7.1", optional = true }
|
||||||
egui_extras = { version = "0.20.0", optional = true, path = "../egui_extras" }
|
egui_extras = { version = "0.21.0", optional = true, path = "../egui_extras" }
|
||||||
|
|
||||||
# feature "http":
|
# feature "http":
|
||||||
ehttp = { version = "0.2.0", optional = true }
|
ehttp = { version = "0.2.0", optional = true }
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use std::{num::NonZeroU64, sync::Arc};
|
use std::{num::NonZeroU64, sync::Arc};
|
||||||
|
|
||||||
use eframe::{
|
use eframe::{
|
||||||
|
egui_wgpu::wgpu::util::DeviceExt,
|
||||||
egui_wgpu::{self, wgpu},
|
egui_wgpu::{self, wgpu},
|
||||||
wgpu::util::DeviceExt,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Custom3d {
|
pub struct Custom3d {
|
||||||
|
|
|
@ -130,6 +130,8 @@ impl BackendPanel {
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
#[cfg(feature = "web_screen-reader")]
|
||||||
{
|
{
|
||||||
let mut screen_reader = ui.ctx().options(|o| o.screen_reader);
|
let mut screen_reader = ui.ctx().options(|o| o.screen_reader);
|
||||||
ui.checkbox(&mut screen_reader, "🔈 Screen reader").on_hover_text("Experimental feature: checking this will turn on the screen reader on supported platforms");
|
ui.checkbox(&mut screen_reader, "🔈 Screen reader").on_hover_text("Experimental feature: checking this will turn on the screen reader on supported platforms");
|
||||||
|
|
|
@ -175,8 +175,8 @@ impl eframe::App for WrapApp {
|
||||||
eframe::set_value(storage, eframe::APP_KEY, &self.state);
|
eframe::set_value(storage, eframe::APP_KEY, &self.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_color(&self, visuals: &egui::Visuals) -> egui::Rgba {
|
fn clear_color(&self, visuals: &egui::Visuals) -> [f32; 4] {
|
||||||
visuals.panel_fill.into()
|
visuals.panel_fill.to_normalized_gamma_f32()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "egui_demo_lib"
|
name = "egui_demo_lib"
|
||||||
version = "0.20.0"
|
version = "0.21.0"
|
||||||
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||||
description = "Example library for egui"
|
description = "Example library for egui"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
@ -30,8 +30,8 @@ syntax_highlighting = ["syntect"]
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { version = "0.20.0", path = "../egui", default-features = false }
|
egui = { version = "0.21.0", path = "../egui", default-features = false }
|
||||||
egui_extras = { version = "0.20.0", path = "../egui_extras" }
|
egui_extras = { version = "0.21.0", path = "../egui_extras" }
|
||||||
enum-map = { version = "2", features = ["serde"] }
|
enum-map = { version = "2", features = ["serde"] }
|
||||||
tracing = { version = "0.1", default-features = false, features = ["std"] }
|
tracing = { version = "0.1", default-features = false, features = ["std"] }
|
||||||
unicode_names2 = { version = "0.6.0", default-features = false }
|
unicode_names2 = { version = "0.6.0", default-features = false }
|
||||||
|
|
|
@ -90,6 +90,7 @@ impl Default for Tests {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::from_demos(vec![
|
Self::from_demos(vec![
|
||||||
Box::new(super::tests::CursorTest::default()),
|
Box::new(super::tests::CursorTest::default()),
|
||||||
|
Box::new(super::highlighting::Highlighting::default()),
|
||||||
Box::new(super::tests::IdTest::default()),
|
Box::new(super::tests::IdTest::default()),
|
||||||
Box::new(super::tests::InputTest::default()),
|
Box::new(super::tests::InputTest::default()),
|
||||||
Box::new(super::layout_test::LayoutTest::default()),
|
Box::new(super::layout_test::LayoutTest::default()),
|
||||||
|
|
37
crates/egui_demo_lib/src/demo/highlighting.rs
Normal file
37
crates/egui_demo_lib/src/demo/highlighting.rs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#[derive(Default)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
|
pub struct Highlighting {}
|
||||||
|
|
||||||
|
impl super::Demo for Highlighting {
|
||||||
|
fn name(&self) -> &'static str {
|
||||||
|
"Highlighting"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
||||||
|
egui::Window::new(self.name())
|
||||||
|
.default_width(320.0)
|
||||||
|
.open(open)
|
||||||
|
.show(ctx, |ui| {
|
||||||
|
use super::View as _;
|
||||||
|
self.ui(ui);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl super::View for Highlighting {
|
||||||
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||||
|
ui.label("This demo demonstrates highlighting a widget.");
|
||||||
|
ui.add_space(4.0);
|
||||||
|
let label_response = ui.label("Hover me to highlight the button!");
|
||||||
|
ui.add_space(4.0);
|
||||||
|
let mut button_response = ui.button("Hover the button to highlight the label!");
|
||||||
|
|
||||||
|
if label_response.hovered() {
|
||||||
|
button_response = button_response.highlight();
|
||||||
|
}
|
||||||
|
if button_response.hovered() {
|
||||||
|
label_response.highlight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ pub mod dancing_strings;
|
||||||
pub mod demo_app_windows;
|
pub mod demo_app_windows;
|
||||||
pub mod drag_and_drop;
|
pub mod drag_and_drop;
|
||||||
pub mod font_book;
|
pub mod font_book;
|
||||||
|
pub mod highlighting;
|
||||||
pub mod layout_test;
|
pub mod layout_test;
|
||||||
pub mod misc_demo_window;
|
pub mod misc_demo_window;
|
||||||
pub mod multi_touch;
|
pub mod multi_touch;
|
||||||
|
|
|
@ -16,6 +16,7 @@ pub struct Sliders {
|
||||||
pub integer: bool,
|
pub integer: bool,
|
||||||
pub vertical: bool,
|
pub vertical: bool,
|
||||||
pub value: f64,
|
pub value: f64,
|
||||||
|
pub trailing_fill: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Sliders {
|
impl Default for Sliders {
|
||||||
|
@ -31,6 +32,7 @@ impl Default for Sliders {
|
||||||
integer: false,
|
integer: false,
|
||||||
vertical: false,
|
vertical: false,
|
||||||
value: 10.0,
|
value: 10.0,
|
||||||
|
trailing_fill: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +66,7 @@ impl super::View for Sliders {
|
||||||
integer,
|
integer,
|
||||||
vertical,
|
vertical,
|
||||||
value,
|
value,
|
||||||
|
trailing_fill,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
ui.label("You can click a slider value to edit it with the keyboard.");
|
ui.label("You can click a slider value to edit it with the keyboard.");
|
||||||
|
@ -95,7 +98,8 @@ impl super::View for Sliders {
|
||||||
.smart_aim(*smart_aim)
|
.smart_aim(*smart_aim)
|
||||||
.orientation(orientation)
|
.orientation(orientation)
|
||||||
.text("i32 demo slider")
|
.text("i32 demo slider")
|
||||||
.step_by(istep),
|
.step_by(istep)
|
||||||
|
.trailing_fill(*trailing_fill),
|
||||||
);
|
);
|
||||||
*value = value_i32 as f64;
|
*value = value_i32 as f64;
|
||||||
} else {
|
} else {
|
||||||
|
@ -106,7 +110,8 @@ impl super::View for Sliders {
|
||||||
.smart_aim(*smart_aim)
|
.smart_aim(*smart_aim)
|
||||||
.orientation(orientation)
|
.orientation(orientation)
|
||||||
.text("f64 demo slider")
|
.text("f64 demo slider")
|
||||||
.step_by(istep),
|
.step_by(istep)
|
||||||
|
.trailing_fill(*trailing_fill),
|
||||||
);
|
);
|
||||||
|
|
||||||
ui.label(
|
ui.label(
|
||||||
|
@ -126,17 +131,24 @@ impl super::View for Sliders {
|
||||||
Slider::new(min, type_min..=type_max)
|
Slider::new(min, type_min..=type_max)
|
||||||
.logarithmic(true)
|
.logarithmic(true)
|
||||||
.smart_aim(*smart_aim)
|
.smart_aim(*smart_aim)
|
||||||
.text("left"),
|
.text("left")
|
||||||
|
.trailing_fill(*trailing_fill),
|
||||||
);
|
);
|
||||||
ui.add(
|
ui.add(
|
||||||
Slider::new(max, type_min..=type_max)
|
Slider::new(max, type_min..=type_max)
|
||||||
.logarithmic(true)
|
.logarithmic(true)
|
||||||
.smart_aim(*smart_aim)
|
.smart_aim(*smart_aim)
|
||||||
.text("right"),
|
.text("right")
|
||||||
|
.trailing_fill(*trailing_fill),
|
||||||
);
|
);
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
|
ui.checkbox(trailing_fill, "Toggle trailing color");
|
||||||
|
ui.label("When enabled, trailing color will be painted up until the circle.");
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
ui.checkbox(use_steps, "Use steps");
|
ui.checkbox(use_steps, "Use steps");
|
||||||
ui.label("When enabled, the minimal value change would be restricted to a given step.");
|
ui.label("When enabled, the minimal value change would be restricted to a given step.");
|
||||||
if *use_steps {
|
if *use_steps {
|
||||||
|
|
|
@ -85,6 +85,8 @@ fn lorem_ipsum(ui: &mut egui::Ui) {
|
||||||
egui::Layout::top_down(egui::Align::LEFT).with_cross_justify(true),
|
egui::Layout::top_down(egui::Align::LEFT).with_cross_justify(true),
|
||||||
|ui| {
|
|ui| {
|
||||||
ui.label(egui::RichText::new(crate::LOREM_IPSUM_LONG).small().weak());
|
ui.label(egui::RichText::new(crate::LOREM_IPSUM_LONG).small().weak());
|
||||||
|
ui.add(egui::Separator::default().grow(8.0));
|
||||||
|
ui.label(egui::RichText::new(crate::LOREM_IPSUM_LONG).small().weak());
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,8 @@ fn test_egui_zero_window_size() {
|
||||||
let clipped_primitives = ctx.tessellate(full_output.shapes);
|
let clipped_primitives = ctx.tessellate(full_output.shapes);
|
||||||
assert!(
|
assert!(
|
||||||
clipped_primitives.is_empty(),
|
clipped_primitives.is_empty(),
|
||||||
"There should be nothing to show"
|
"There should be nothing to show, has at least one primitive with clip_rect: {:?}",
|
||||||
|
clipped_primitives[0].clip_rect
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,10 @@ All notable changes to the `egui_extras` integration will be noted in this file.
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
|
||||||
|
## 0.21.0 - 2023-02-08
|
||||||
|
* Update to egui 0.21
|
||||||
|
|
||||||
|
|
||||||
## 0.20.0 - 2022-12-08
|
## 0.20.0 - 2022-12-08
|
||||||
* Added `RetainedImage::from_svg_bytes_with_size` to be able to specify a size for SVGs to be rasterized at.
|
* Added `RetainedImage::from_svg_bytes_with_size` to be able to specify a size for SVGs to be rasterized at.
|
||||||
* Lots of `Table` improvements ([#2369](https://github.com/emilk/egui/pull/2369)):
|
* Lots of `Table` improvements ([#2369](https://github.com/emilk/egui/pull/2369)):
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "egui_extras"
|
name = "egui_extras"
|
||||||
version = "0.20.0"
|
version = "0.21.0"
|
||||||
authors = [
|
authors = [
|
||||||
"Dominik Rössler <dominik@freshx.de>",
|
"Dominik Rössler <dominik@freshx.de>",
|
||||||
"Emil Ernerfeldt <emil.ernerfeldt@gmail.com>",
|
"Emil Ernerfeldt <emil.ernerfeldt@gmail.com>",
|
||||||
|
@ -37,7 +37,7 @@ tracing = ["dep:tracing", "egui/tracing"]
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { version = "0.20.0", path = "../egui", default-features = false }
|
egui = { version = "0.21.0", path = "../egui", default-features = false }
|
||||||
|
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
|
||||||
|
@ -58,9 +58,9 @@ document-features = { version = "0.2", optional = true }
|
||||||
image = { version = "0.24", optional = true, default-features = false }
|
image = { version = "0.24", optional = true, default-features = false }
|
||||||
|
|
||||||
# svg feature
|
# svg feature
|
||||||
resvg = { version = "0.23", optional = true }
|
resvg = { version = "0.28", optional = true, default-features = false }
|
||||||
tiny-skia = { version = "0.6", optional = true } # must be updated in lock-step with resvg
|
tiny-skia = { version = "0.8", optional = true, default-features = false } # must be updated in lock-step with resvg
|
||||||
usvg = { version = "0.23", optional = true }
|
usvg = { version = "0.28", optional = true, default-features = false }
|
||||||
|
|
||||||
# feature "tracing"
|
# feature "tracing"
|
||||||
tracing = { version = "0.1", optional = true, default-features = false, features = [
|
tracing = { version = "0.1", optional = true, default-features = false, features = [
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/egui_extras)
|
[](https://crates.io/crates/egui_extras)
|
||||||
[](https://docs.rs/egui_extras)
|
[](https://docs.rs/egui_extras)
|
||||||
|
[](https://github.com/rust-secure-code/safety-dance/)
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
|
|
|
@ -231,12 +231,11 @@ pub fn load_svg_bytes_with_size(
|
||||||
svg_bytes: &[u8],
|
svg_bytes: &[u8],
|
||||||
fit_to: FitTo,
|
fit_to: FitTo,
|
||||||
) -> Result<egui::ColorImage, String> {
|
) -> Result<egui::ColorImage, String> {
|
||||||
let mut opt = usvg::Options::default();
|
let opt = usvg::Options::default();
|
||||||
opt.fontdb.load_system_fonts();
|
|
||||||
|
|
||||||
let rtree = usvg::Tree::from_data(svg_bytes, &opt.to_ref()).map_err(|err| err.to_string())?;
|
let rtree = usvg::Tree::from_data(svg_bytes, &opt).map_err(|err| err.to_string())?;
|
||||||
|
|
||||||
let pixmap_size = rtree.svg_node().size.to_screen_size();
|
let pixmap_size = rtree.size.to_screen_size();
|
||||||
let [w, h] = match fit_to {
|
let [w, h] = match fit_to {
|
||||||
FitTo::Original => [pixmap_size.width(), pixmap_size.height()],
|
FitTo::Original => [pixmap_size.width(), pixmap_size.height()],
|
||||||
FitTo::Size(w, h) => [w, h],
|
FitTo::Size(w, h) => [w, h],
|
||||||
|
|
|
@ -3,10 +3,11 @@ All notable changes to the `egui_glium` integration will be noted in this file.
|
||||||
|
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
* Remove the `screen_reader` feature ([#2669](https://github.com/emilk/egui/pull/2669)).
|
||||||
|
|
||||||
|
|
||||||
## 0.20.1 - 2022-12-11
|
## 0.20.1 - 2022-12-11
|
||||||
* Fix docs.rs build ([#2420](https://github.com/emilk/egui/pull/2420)).
|
* Fix [docs.rs](https://docs.rs/egui_glium) build ([#2420](https://github.com/emilk/egui/pull/2420)).
|
||||||
|
|
||||||
|
|
||||||
## 0.20.0 - 2022-12-08
|
## 0.20.0 - 2022-12-08
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "egui_glium"
|
name = "egui_glium"
|
||||||
version = "0.20.1"
|
version = "0.21.0"
|
||||||
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||||
description = "Bindings for using egui natively using the glium library"
|
description = "Bindings for using egui natively using the glium library"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
@ -20,8 +20,7 @@ include = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
# Avoid speech-dispatcher dependencies - see https://docs.rs/crate/egui_glium/0.20.0/builds/695197
|
all-features = true
|
||||||
features = ["document-features"]
|
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -35,15 +34,12 @@ clipboard = ["egui-winit/clipboard"]
|
||||||
## Enable opening links in a browser when an egui hyperlink is clicked.
|
## Enable opening links in a browser when an egui hyperlink is clicked.
|
||||||
links = ["egui-winit/links"]
|
links = ["egui-winit/links"]
|
||||||
|
|
||||||
## Experimental support for a screen reader.
|
|
||||||
screen_reader = ["egui-winit/screen_reader"]
|
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { version = "0.20.0", path = "../egui", default-features = false, features = [
|
egui = { version = "0.21.0", path = "../egui", default-features = false, features = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
] }
|
] }
|
||||||
egui-winit = { version = "0.20.0", path = "../egui-winit", default-features = false }
|
egui-winit = { version = "0.21.1", path = "../egui-winit", default-features = false }
|
||||||
|
|
||||||
ahash = { version = "0.8.1", default-features = false, features = [
|
ahash = { version = "0.8.1", default-features = false, features = [
|
||||||
"no-rng", # we don't need DOS-protection, so we let users opt-in to it instead
|
"no-rng", # we don't need DOS-protection, so we let users opt-in to it instead
|
||||||
|
@ -58,5 +54,5 @@ document-features = { version = "0.2", optional = true }
|
||||||
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
egui_demo_lib = { version = "0.20.0", path = "../egui_demo_lib", default-features = false }
|
egui_demo_lib = { version = "0.21.0", path = "../egui_demo_lib", default-features = false }
|
||||||
image = { version = "0.24", default-features = false, features = ["png"] }
|
image = { version = "0.24", default-features = false, features = ["png"] }
|
||||||
|
|
|
@ -11,7 +11,11 @@ This crates provides bindings between [`egui`](https://github.com/emilk/egui) an
|
||||||
To use on Linux, first run:
|
To use on Linux, first run:
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libspeechd-dev libxkbcommon-dev libssl-dev
|
sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
This crate depends on [`egui-winit`](https://github.com/emilk/egui/tree/master/crates/egui-winit).
|
This crate depends on [`egui-winit`](https://github.com/emilk/egui/tree/master/crates/egui-winit).
|
||||||
|
|
||||||
|
|
||||||
|
## DEPRECATED - Looking for new maintainer
|
||||||
|
This crate is no longer being updated. If you are interested in keeping `egui_glium` updated, then fork it to its own repository, make a PR to the egui repo removing it, and then I will give you access to it on crates.io so you can publish new `egui_glium` crates.
|
||||||
|
|
|
@ -5,8 +5,13 @@ All notable changes to the `egui_glow` integration will be noted in this file.
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
|
||||||
|
## 0.21.0 - 2023-02-08
|
||||||
|
* Update to `glow` 0.12 ([#2695](https://github.com/emilk/egui/pull/2695)).
|
||||||
|
* Remove the `screen_reader` feature ([#2669](https://github.com/emilk/egui/pull/2669)).
|
||||||
|
|
||||||
|
|
||||||
## 0.20.1 - 2022-12-11
|
## 0.20.1 - 2022-12-11
|
||||||
* Fix docs.rs build ([#2420](https://github.com/emilk/egui/pull/2420)).
|
* Fix [docs.rs](https://docs.rs/egui_glow) build ([#2420](https://github.com/emilk/egui/pull/2420)).
|
||||||
|
|
||||||
|
|
||||||
## 0.20.0 - 2022-12-08
|
## 0.20.0 - 2022-12-08
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "egui_glow"
|
name = "egui_glow"
|
||||||
version = "0.20.1"
|
version = "0.21.0"
|
||||||
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||||
description = "Bindings for using egui natively using the glow library"
|
description = "Bindings for using egui natively using the glow library"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
@ -20,8 +20,7 @@ include = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
# Avoid speech-dispatcher dependencies - see https://docs.rs/crate/egui_glow/0.20.0/builds/695194
|
all-features = true
|
||||||
features = ["document-features"]
|
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -37,9 +36,6 @@ clipboard = ["egui-winit?/clipboard"]
|
||||||
## enable opening links in a browser when an egui hyperlink is clicked.
|
## enable opening links in a browser when an egui hyperlink is clicked.
|
||||||
links = ["egui-winit?/links"]
|
links = ["egui-winit?/links"]
|
||||||
|
|
||||||
## Experimental support for a screen reader.
|
|
||||||
screen_reader = ["egui-winit?/screen_reader"]
|
|
||||||
|
|
||||||
## Enable profiling with the [`puffin`](https://docs.rs/puffin) crate.
|
## Enable profiling with the [`puffin`](https://docs.rs/puffin) crate.
|
||||||
puffin = ["dep:puffin", "egui-winit?/puffin"]
|
puffin = ["dep:puffin", "egui-winit?/puffin"]
|
||||||
|
|
||||||
|
@ -48,12 +44,12 @@ winit = ["egui-winit"]
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { version = "0.20.0", path = "../egui", default-features = false, features = [
|
egui = { version = "0.21.0", path = "../egui", default-features = false, features = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
] }
|
] }
|
||||||
|
|
||||||
bytemuck = "1.7"
|
bytemuck = "1.7"
|
||||||
glow = "0.11"
|
glow = "0.12"
|
||||||
memoffset = "0.6"
|
memoffset = "0.6"
|
||||||
tracing = { version = "0.1", default-features = false, features = ["std"] }
|
tracing = { version = "0.1", default-features = false, features = ["std"] }
|
||||||
|
|
||||||
|
@ -63,7 +59,7 @@ document-features = { version = "0.2", optional = true }
|
||||||
|
|
||||||
# Native:
|
# Native:
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
egui-winit = { version = "0.20.0", path = "../egui-winit", optional = true, default-features = false }
|
egui-winit = { version = "0.21.1", path = "../egui-winit", optional = true, default-features = false }
|
||||||
puffin = { version = "0.14", optional = true }
|
puffin = { version = "0.14", optional = true }
|
||||||
|
|
||||||
# Web:
|
# Web:
|
||||||
|
@ -73,8 +69,9 @@ wasm-bindgen = { version = "0.2" }
|
||||||
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
glutin = "0.30.2" # examples/pure_glow
|
glutin = "0.30" # examples/pure_glow
|
||||||
raw-window-handle = "0.5.0"
|
raw-window-handle = "0.5.0"
|
||||||
|
glutin-winit = "0.3.0"
|
||||||
|
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
|
|
|
@ -14,7 +14,13 @@ To write web apps using `glow` you can use [`eframe`](https://github.com/emilk/e
|
||||||
To use on Linux, first run:
|
To use on Linux, first run:
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libspeechd-dev libxkbcommon-dev libssl-dev
|
sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
This crate optionally depends on [`egui-winit`](https://github.com/emilk/egui/tree/master/crates/egui-winit).
|
This crate optionally depends on [`egui-winit`](https://github.com/emilk/egui/tree/master/crates/egui-winit).
|
||||||
|
|
||||||
|
Text the example with:
|
||||||
|
|
||||||
|
``` sh
|
||||||
|
cargo run -p egui_glow --example pure_glow --features=winit,egui/default_fonts
|
||||||
|
```
|
||||||
|
|
|
@ -17,66 +17,91 @@ impl GlutinWindowContext {
|
||||||
// refactor this function to use `glutin-winit` crate eventually.
|
// refactor this function to use `glutin-winit` crate eventually.
|
||||||
// preferably add android support at the same time.
|
// preferably add android support at the same time.
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn new(winit_window: winit::window::Window) -> Self {
|
unsafe fn new(event_loop: &winit::event_loop::EventLoopWindowTarget<()>) -> Self {
|
||||||
use glutin::prelude::*;
|
use egui::NumExt;
|
||||||
use raw_window_handle::*;
|
use glutin::context::NotCurrentGlContextSurfaceAccessor;
|
||||||
|
use glutin::display::GetGlDisplay;
|
||||||
|
use glutin::display::GlDisplay;
|
||||||
|
use glutin::prelude::GlSurface;
|
||||||
|
use raw_window_handle::HasRawWindowHandle;
|
||||||
|
let winit_window_builder = winit::window::WindowBuilder::new()
|
||||||
|
.with_resizable(true)
|
||||||
|
.with_inner_size(winit::dpi::LogicalSize {
|
||||||
|
width: 800.0,
|
||||||
|
height: 600.0,
|
||||||
|
})
|
||||||
|
.with_title("egui_glow example") // Keep hidden until we've painted something. See https://github.com/emilk/egui/pull/2279
|
||||||
|
.with_visible(false);
|
||||||
|
|
||||||
let raw_display_handle = winit_window.raw_display_handle();
|
let config_template_builder = glutin::config::ConfigTemplateBuilder::new()
|
||||||
let raw_window_handle = winit_window.raw_window_handle();
|
|
||||||
|
|
||||||
// EGL is crossplatform and the official khronos way
|
|
||||||
// but sometimes platforms/drivers may not have it, so we use back up options where possible.
|
|
||||||
|
|
||||||
// try egl and fallback to windows wgl. Windows is the only platform that *requires* window handle to create display.
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
let preference = glutin::display::DisplayApiPreference::EglThenWgl(Some(window_handle));
|
|
||||||
// try egl and fallback to x11 glx
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
let preference = glutin::display::DisplayApiPreference::EglThenGlx(Box::new(
|
|
||||||
winit::platform::unix::register_xlib_error_hook,
|
|
||||||
));
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
let preference = glutin::display::DisplayApiPreference::Cgl;
|
|
||||||
#[cfg(target_os = "android")]
|
|
||||||
let preference = glutin::display::DisplayApiPreference::Egl;
|
|
||||||
|
|
||||||
let gl_display = glutin::display::Display::new(raw_display_handle, preference).unwrap();
|
|
||||||
|
|
||||||
let config_template = glutin::config::ConfigTemplateBuilder::new()
|
|
||||||
.prefer_hardware_accelerated(None)
|
.prefer_hardware_accelerated(None)
|
||||||
.with_depth_size(0)
|
.with_depth_size(0)
|
||||||
.with_stencil_size(0)
|
.with_stencil_size(0)
|
||||||
.with_transparency(false)
|
.with_transparency(false);
|
||||||
.compatible_with_native_window(raw_window_handle)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let config = gl_display
|
tracing::debug!("trying to get gl_config");
|
||||||
.find_configs(config_template)
|
let (mut window, gl_config) =
|
||||||
.unwrap()
|
glutin_winit::DisplayBuilder::new() // let glutin-winit helper crate handle the complex parts of opengl context creation
|
||||||
.next()
|
.with_preference(glutin_winit::ApiPrefence::FallbackEgl) // https://github.com/emilk/egui/issues/2520#issuecomment-1367841150
|
||||||
.unwrap();
|
.with_window_builder(Some(winit_window_builder.clone()))
|
||||||
|
.build(
|
||||||
|
event_loop,
|
||||||
|
config_template_builder,
|
||||||
|
|mut config_iterator| {
|
||||||
|
config_iterator.next().expect(
|
||||||
|
"failed to find a matching configuration for creating glutin config",
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.expect("failed to create gl_config");
|
||||||
|
let gl_display = gl_config.display();
|
||||||
|
tracing::debug!("found gl_config: {:?}", &gl_config);
|
||||||
|
|
||||||
|
let raw_window_handle = window.as_ref().map(|w| w.raw_window_handle());
|
||||||
|
tracing::debug!("raw window handle: {:?}", raw_window_handle);
|
||||||
let context_attributes =
|
let context_attributes =
|
||||||
glutin::context::ContextAttributesBuilder::new().build(Some(raw_window_handle));
|
glutin::context::ContextAttributesBuilder::new().build(raw_window_handle);
|
||||||
// for surface creation.
|
// by default, glutin will try to create a core opengl context. but, if it is not available, try to create a gl-es context using this fallback attributes
|
||||||
let (width, height): (u32, u32) = winit_window.inner_size().into();
|
let fallback_context_attributes = glutin::context::ContextAttributesBuilder::new()
|
||||||
|
.with_context_api(glutin::context::ContextApi::Gles(None))
|
||||||
|
.build(raw_window_handle);
|
||||||
|
let not_current_gl_context = unsafe {
|
||||||
|
gl_display
|
||||||
|
.create_context(&gl_config, &context_attributes)
|
||||||
|
.unwrap_or_else(|_| {
|
||||||
|
tracing::debug!("failed to create gl_context with attributes: {:?}. retrying with fallback context attributes: {:?}",
|
||||||
|
&context_attributes,
|
||||||
|
&fallback_context_attributes);
|
||||||
|
gl_config
|
||||||
|
.display()
|
||||||
|
.create_context(&gl_config, &fallback_context_attributes)
|
||||||
|
.expect("failed to create context even with fallback attributes")
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
// this is where the window is created, if it has not been created while searching for suitable gl_config
|
||||||
|
let window = window.take().unwrap_or_else(|| {
|
||||||
|
tracing::debug!("window doesn't exist yet. creating one now with finalize_window");
|
||||||
|
glutin_winit::finalize_window(event_loop, winit_window_builder.clone(), &gl_config)
|
||||||
|
.expect("failed to finalize glutin window")
|
||||||
|
});
|
||||||
|
let (width, height): (u32, u32) = window.inner_size().into();
|
||||||
|
let width = std::num::NonZeroU32::new(width.at_least(1)).unwrap();
|
||||||
|
let height = std::num::NonZeroU32::new(height.at_least(1)).unwrap();
|
||||||
let surface_attributes =
|
let surface_attributes =
|
||||||
glutin::surface::SurfaceAttributesBuilder::<glutin::surface::WindowSurface>::new()
|
glutin::surface::SurfaceAttributesBuilder::<glutin::surface::WindowSurface>::new()
|
||||||
.build(
|
.build(window.raw_window_handle(), width, height);
|
||||||
raw_window_handle,
|
tracing::debug!(
|
||||||
std::num::NonZeroU32::new(width).unwrap(),
|
"creating surface with attributes: {:?}",
|
||||||
std::num::NonZeroU32::new(height).unwrap(),
|
&surface_attributes
|
||||||
);
|
);
|
||||||
// start creating the gl objects
|
let gl_surface = unsafe {
|
||||||
let gl_context = gl_display
|
gl_display
|
||||||
.create_context(&config, &context_attributes)
|
.create_window_surface(&gl_config, &surface_attributes)
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
};
|
||||||
let gl_surface = gl_display
|
tracing::debug!("surface created successfully: {gl_surface:?}.making context current");
|
||||||
.create_window_surface(&config, &surface_attributes)
|
let gl_context = not_current_gl_context.make_current(&gl_surface).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let gl_context = gl_context.make_current(&gl_surface).unwrap();
|
|
||||||
|
|
||||||
gl_surface
|
gl_surface
|
||||||
.set_swap_interval(
|
.set_swap_interval(
|
||||||
|
@ -86,7 +111,7 @@ impl GlutinWindowContext {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
GlutinWindowContext {
|
GlutinWindowContext {
|
||||||
window: winit_window,
|
window,
|
||||||
gl_context,
|
gl_context,
|
||||||
gl_display,
|
gl_display,
|
||||||
gl_surface,
|
gl_surface,
|
||||||
|
@ -216,19 +241,7 @@ fn main() {
|
||||||
fn create_display(
|
fn create_display(
|
||||||
event_loop: &winit::event_loop::EventLoopWindowTarget<()>,
|
event_loop: &winit::event_loop::EventLoopWindowTarget<()>,
|
||||||
) -> (GlutinWindowContext, glow::Context) {
|
) -> (GlutinWindowContext, glow::Context) {
|
||||||
let winit_window = winit::window::WindowBuilder::new()
|
let glutin_window_context = unsafe { GlutinWindowContext::new(event_loop) };
|
||||||
.with_resizable(true)
|
|
||||||
.with_inner_size(winit::dpi::LogicalSize {
|
|
||||||
width: 800.0,
|
|
||||||
height: 600.0,
|
|
||||||
})
|
|
||||||
.with_title("egui_glow example")
|
|
||||||
.with_visible(false) // Keep hidden until we've painted something. See https://github.com/emilk/egui/pull/2279
|
|
||||||
.build(event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// a lot of the code below has been lifted from glutin example in their repo.
|
|
||||||
let glutin_window_context = unsafe { GlutinWindowContext::new(winit_window) };
|
|
||||||
let gl = unsafe {
|
let gl = unsafe {
|
||||||
glow::Context::from_loader_function(|s| {
|
glow::Context::from_loader_function(|s| {
|
||||||
let s = std::ffi::CString::new(s)
|
let s = std::ffi::CString::new(s)
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
use egui::{
|
use egui::{
|
||||||
emath::Rect,
|
emath::Rect,
|
||||||
epaint::{Color32, Mesh, PaintCallbackInfo, Primitive, Vertex},
|
epaint::{Mesh, PaintCallbackInfo, Primitive, Vertex},
|
||||||
};
|
};
|
||||||
use glow::HasContext as _;
|
use glow::HasContext as _;
|
||||||
use memoffset::offset_of;
|
use memoffset::offset_of;
|
||||||
|
@ -106,6 +106,23 @@ impl Painter {
|
||||||
crate::profile_function!();
|
crate::profile_function!();
|
||||||
crate::check_for_gl_error_even_in_release!(&gl, "before Painter::new");
|
crate::check_for_gl_error_even_in_release!(&gl, "before Painter::new");
|
||||||
|
|
||||||
|
// some useful debug info. all three of them are present in gl 1.1.
|
||||||
|
unsafe {
|
||||||
|
let version = gl.get_parameter_string(glow::VERSION);
|
||||||
|
let renderer = gl.get_parameter_string(glow::RENDERER);
|
||||||
|
let vendor = gl.get_parameter_string(glow::VENDOR);
|
||||||
|
tracing::debug!(
|
||||||
|
"\nopengl version: {version}\nopengl renderer: {renderer}\nopengl vendor: {vendor}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
if gl.version().major < 2 {
|
||||||
|
// this checks on desktop that we are not using opengl 1.1 microsoft sw rendering context.
|
||||||
|
// ShaderVersion::get fn will segfault due to SHADING_LANGUAGE_VERSION (added in gl2.0)
|
||||||
|
return Err("egui_glow requires opengl 2.0+. ".to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
let max_texture_side = unsafe { gl.get_parameter_i32(glow::MAX_TEXTURE_SIZE) } as usize;
|
let max_texture_side = unsafe { gl.get_parameter_i32(glow::MAX_TEXTURE_SIZE) } as usize;
|
||||||
let shader_version = shader_version.unwrap_or_else(|| ShaderVersion::get(&gl));
|
let shader_version = shader_version.unwrap_or_else(|| ShaderVersion::get(&gl));
|
||||||
let is_webgl_1 = shader_version == ShaderVersion::Es100;
|
let is_webgl_1 = shader_version == ShaderVersion::Es100;
|
||||||
|
@ -665,7 +682,7 @@ impl Painter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear(gl: &glow::Context, screen_size_in_pixels: [u32; 2], clear_color: egui::Rgba) {
|
pub fn clear(gl: &glow::Context, screen_size_in_pixels: [u32; 2], clear_color: [f32; 4]) {
|
||||||
crate::profile_function!();
|
crate::profile_function!();
|
||||||
unsafe {
|
unsafe {
|
||||||
gl.disable(glow::SCISSOR_TEST);
|
gl.disable(glow::SCISSOR_TEST);
|
||||||
|
@ -676,24 +693,12 @@ pub fn clear(gl: &glow::Context, screen_size_in_pixels: [u32; 2], clear_color: e
|
||||||
screen_size_in_pixels[0] as i32,
|
screen_size_in_pixels[0] as i32,
|
||||||
screen_size_in_pixels[1] as i32,
|
screen_size_in_pixels[1] as i32,
|
||||||
);
|
);
|
||||||
|
|
||||||
if true {
|
|
||||||
// verified to be correct on eframe native (on Mac).
|
|
||||||
gl.clear_color(
|
gl.clear_color(
|
||||||
clear_color[0],
|
clear_color[0],
|
||||||
clear_color[1],
|
clear_color[1],
|
||||||
clear_color[2],
|
clear_color[2],
|
||||||
clear_color[3],
|
clear_color[3],
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
let clear_color: Color32 = clear_color.into();
|
|
||||||
gl.clear_color(
|
|
||||||
clear_color[0] as f32 / 255.0,
|
|
||||||
clear_color[1] as f32 / 255.0,
|
|
||||||
clear_color[2] as f32 / 255.0,
|
|
||||||
clear_color[3] as f32 / 255.0,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
gl.clear(glow::COLOR_BUFFER_BIT);
|
gl.clear(glow::COLOR_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "emath"
|
name = "emath"
|
||||||
version = "0.20.0"
|
version = "0.21.0"
|
||||||
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||||
description = "Minimal 2D math library for GUI work"
|
description = "Minimal 2D math library for GUI work"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
# emath - egui math library
|
# emath - egui math library
|
||||||
|
|
||||||
|
[](https://crates.io/crates/emath)
|
||||||
|
[](https://docs.rs/emath)
|
||||||
|
[](https://github.com/rust-secure-code/safety-dance/)
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
A bare-bones 2D math library with types and functions useful for GUI building.
|
A bare-bones 2D math library with types and functions useful for GUI building.
|
||||||
|
|
||||||
Made for [`egui`](https://github.com/emilk/egui/).
|
Made for [`egui`](https://github.com/emilk/egui/).
|
||||||
|
|
|
@ -15,6 +15,7 @@ use crate::*;
|
||||||
pub struct Pos2 {
|
pub struct Pos2 {
|
||||||
/// How far to the right.
|
/// How far to the right.
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
|
|
||||||
/// How far down.
|
/// How far down.
|
||||||
pub y: f32,
|
pub y: f32,
|
||||||
// implicit w = 1
|
// implicit w = 1
|
||||||
|
|
|
@ -3,6 +3,9 @@ All notable changes to the epaint crate will be documented in this file.
|
||||||
|
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
|
||||||
|
## 0.21.0 - 2023-02-08
|
||||||
* Improve the look of thin white lines ([#2437](https://github.com/emilk/egui/pull/2437)).
|
* Improve the look of thin white lines ([#2437](https://github.com/emilk/egui/pull/2437)).
|
||||||
* Don't render `\r` (Carriage Return) ([#2452](https://github.com/emilk/egui/pull/2452)).
|
* Don't render `\r` (Carriage Return) ([#2452](https://github.com/emilk/egui/pull/2452)).
|
||||||
* Fix bug in `Mesh::split_to_u16` ([#2459](https://github.com/emilk/egui/pull/2459)).
|
* Fix bug in `Mesh::split_to_u16` ([#2459](https://github.com/emilk/egui/pull/2459)).
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "epaint"
|
name = "epaint"
|
||||||
version = "0.20.0"
|
version = "0.21.0"
|
||||||
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||||
description = "Minimal 2D graphics library for GUI work"
|
description = "Minimal 2D graphics library for GUI work"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
@ -63,9 +63,12 @@ mint = ["emath/mint"]
|
||||||
## Allow serialization using [`serde`](https://docs.rs/serde).
|
## Allow serialization using [`serde`](https://docs.rs/serde).
|
||||||
serde = ["dep:serde", "ahash/serde", "emath/serde", "ecolor/serde"]
|
serde = ["dep:serde", "ahash/serde", "emath/serde", "ecolor/serde"]
|
||||||
|
|
||||||
|
## Change Vertex layout to be compatible with unity
|
||||||
|
unity = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
emath = { version = "0.20.0", path = "../emath" }
|
emath = { version = "0.21.0", path = "../emath" }
|
||||||
ecolor = { version = "0.20.0", path = "../ecolor" }
|
ecolor = { version = "0.21.0", path = "../ecolor" }
|
||||||
|
|
||||||
ab_glyph = "0.2.11"
|
ab_glyph = "0.2.11"
|
||||||
ahash = { version = "0.8.1", default-features = false, features = [
|
ahash = { version = "0.8.1", default-features = false, features = [
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
# epaint - egui paint library
|
# epaint - egui paint library
|
||||||
|
|
||||||
|
[](https://crates.io/crates/epaint)
|
||||||
|
[](https://docs.rs/epaint)
|
||||||
|
[](https://github.com/rust-secure-code/safety-dance/)
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
A bare-bones 2D graphics library for turning simple 2D shapes and text into textured triangles.
|
A bare-bones 2D graphics library for turning simple 2D shapes and text into textured triangles.
|
||||||
|
|
||||||
Made for [`egui`](https://github.com/emilk/egui/).
|
Made for [`egui`](https://github.com/emilk/egui/).
|
||||||
|
|
|
@ -6,6 +6,7 @@ use emath::*;
|
||||||
/// Should be friendly to send to GPU as is.
|
/// Should be friendly to send to GPU as is.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||||
|
#[cfg(not(feature = "unity"))]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
|
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
|
||||||
pub struct Vertex {
|
pub struct Vertex {
|
||||||
|
@ -22,6 +23,25 @@ pub struct Vertex {
|
||||||
pub color: Color32, // 32 bit
|
pub color: Color32, // 32 bit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||||
|
#[cfg(feature = "unity")]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
|
||||||
|
pub struct Vertex {
|
||||||
|
/// Logical pixel coordinates (points).
|
||||||
|
/// (0,0) is the top left corner of the screen.
|
||||||
|
pub pos: Pos2, // 64 bit
|
||||||
|
|
||||||
|
/// sRGBA with premultiplied alpha
|
||||||
|
pub color: Color32, // 32 bit
|
||||||
|
|
||||||
|
/// Normalized texture coordinates.
|
||||||
|
/// (0, 0) is the top left corner of the texture.
|
||||||
|
/// (1, 1) is the bottom right corner of the texture.
|
||||||
|
pub uv: Pos2, // 64 bit
|
||||||
|
}
|
||||||
|
|
||||||
/// Textured triangles in two dimensions.
|
/// Textured triangles in two dimensions.
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
|
|
@ -973,12 +973,16 @@ pub struct Tessellator {
|
||||||
pixels_per_point: f32,
|
pixels_per_point: f32,
|
||||||
options: TessellationOptions,
|
options: TessellationOptions,
|
||||||
font_tex_size: [usize; 2],
|
font_tex_size: [usize; 2],
|
||||||
|
|
||||||
/// See [`TextureAtlas::prepared_discs`].
|
/// See [`TextureAtlas::prepared_discs`].
|
||||||
prepared_discs: Vec<PreparedDisc>,
|
prepared_discs: Vec<PreparedDisc>,
|
||||||
|
|
||||||
/// size of feathering in points. normally the size of a physical pixel. 0.0 if disabled
|
/// size of feathering in points. normally the size of a physical pixel. 0.0 if disabled
|
||||||
feathering: f32,
|
feathering: f32,
|
||||||
|
|
||||||
/// Only used for culling
|
/// Only used for culling
|
||||||
clip_rect: Rect,
|
clip_rect: Rect,
|
||||||
|
|
||||||
scratchpad_points: Vec<Pos2>,
|
scratchpad_points: Vec<Pos2>,
|
||||||
scratchpad_path: Path,
|
scratchpad_path: Path,
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,10 @@ impl UvRect {
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub struct GlyphInfo {
|
pub struct GlyphInfo {
|
||||||
|
/// Used for pair-kerning.
|
||||||
|
///
|
||||||
|
/// Doesn't need to be unique.
|
||||||
|
/// Use `ab_glyph::GlyphId(0)` if you just want to have an id, and don't care.
|
||||||
pub(crate) id: ab_glyph::GlyphId,
|
pub(crate) id: ab_glyph::GlyphId,
|
||||||
|
|
||||||
/// Unit: points.
|
/// Unit: points.
|
||||||
|
|
13
deny.toml
13
deny.toml
|
@ -24,22 +24,29 @@ ignore = [
|
||||||
multiple-versions = "deny"
|
multiple-versions = "deny"
|
||||||
wildcards = "allow" # at least until https://github.com/EmbarkStudios/cargo-deny/issues/241 is fixed
|
wildcards = "allow" # at least until https://github.com/EmbarkStudios/cargo-deny/issues/241 is fixed
|
||||||
deny = [
|
deny = [
|
||||||
{ name = "openssl" }, # prefer rustls
|
{ name = "cmake" }, # Lord no
|
||||||
{ name = "openssl-sys" }, # prefer rustls
|
{ name = "openssl-sys" }, # prefer rustls
|
||||||
|
{ name = "openssl" }, # prefer rustls
|
||||||
]
|
]
|
||||||
|
|
||||||
skip = [
|
skip = [
|
||||||
{ name = "ahash" }, # old version via dark-light
|
{ name = "ahash" }, # old version via dark-light
|
||||||
{ name = "arrayvec" }, # old version via tiny-skiaz
|
{ name = "arrayvec" }, # old version via tiny-skiaz
|
||||||
{ name = "hashbrown" }, # old version via dark-light
|
{ name = "hashbrown" }, # old version via dark-light
|
||||||
|
{ name = "nix" }, # old version via winit
|
||||||
{ name = "time" }, # old version pulled in by unmaintianed crate 'chrono'
|
{ name = "time" }, # old version pulled in by unmaintianed crate 'chrono'
|
||||||
|
{ name = "tiny-skia" }, # winit uses a different version from egui_extras (TODO(emilk): update egui_extras!)
|
||||||
{ name = "ttf-parser" }, # different versions pulled in by ab_glyph and usvg
|
{ name = "ttf-parser" }, # different versions pulled in by ab_glyph and usvg
|
||||||
|
{ name = "wayland-sys" }, # old version via winit
|
||||||
|
{ name = "windows_x86_64_msvc" }, # old version via glutin
|
||||||
|
{ name = "windows-sys" }, # old version via glutin
|
||||||
|
{ name = "windows" }, # old version via accesskit
|
||||||
]
|
]
|
||||||
skip-tree = [
|
skip-tree = [
|
||||||
{ name = "criterion" }, # dev-dependency
|
{ name = "criterion" }, # dev-dependency
|
||||||
{ name = "glium" }, # legacy crate, lots of old dependencies
|
{ name = "darling" }, # old version via tts
|
||||||
|
{ name = "foreign-types" }, # old version from wgpu
|
||||||
{ name = "rfd" }, # example dependency
|
{ name = "rfd" }, # example dependency
|
||||||
{ name = "three-d" }, # example dependency
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Binary file not shown.
|
@ -4,3 +4,7 @@ All the examples in this folder uses [`eframe`](https://github.com/emilk/egui/tr
|
||||||
There are a lot more examples at <https://www.egui.rs>, and it has links to the source code of each example.
|
There are a lot more examples at <https://www.egui.rs>, and it has links to the source code of each example.
|
||||||
|
|
||||||
Also check out the official docs at <https://docs.rs/egui> and <https://docs.rs/eframe>.
|
Also check out the official docs at <https://docs.rs/egui> and <https://docs.rs/eframe>.
|
||||||
|
|
||||||
|
Note that all the examples on `master` are for the latest `master` version of `egui`.
|
||||||
|
|
||||||
|
If you want to look for examples for a specific version of egui, go to that tag, e.g. <https://github.com/emilk/egui/tree/latest/examples>.
|
||||||
|
|
|
@ -10,5 +10,5 @@ publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe", features = [
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
"__screenshot", # __screenshot is so we can dump a screenshot using EFRAME_SCREENSHOT_TO
|
||||||
] }
|
] }
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue