Skip to content

Commit

Permalink
Merge branch 'master' into fix/hit-test-clickable-behind-hoverable
Browse files Browse the repository at this point in the history
  • Loading branch information
M4tthewDE authored Jan 7, 2025
2 parents 53d9b53 + 7186f72 commit a43040e
Show file tree
Hide file tree
Showing 176 changed files with 5,757 additions and 3,217 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,10 @@ jobs:
uses: Swatinem/rust-cache@v2

- name: Run tests
# TODO(lucasmerlin): Enable --all-features (currently this breaks the rendering in the tests because of the `unity` feature)
run: cargo test
run: cargo test --all-features

- name: Run doc-tests
# TODO(lucasmerlin): Enable --all-features (currently this breaks the rendering in the tests because of the `unity` feature)
run: cargo test --doc
run: cargo test --all-features --doc

- name: Upload artifacts
uses: actions/upload-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
**/target_wasm
**/tests/snapshots/**/*.diff.png
**/tests/snapshots/**/*.new.png
**/tests/snapshots/**/*.old.png
/.*.json
/.vscode
/media/*
Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@
"--all-features",
],
"rust-analyzer.showUnlinkedFileNotification": false,

// Uncomment the following options and restart rust-analyzer to get it to check code behind `cfg(target_arch=wasm32)`.
// Don't forget to put it in a comment again before committing.
// "rust-analyzer.cargo.target": "wasm32-unknown-unknown",
}
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ egui_extras::install_image_loaders(egui_ctx);
* [Tweaked the default visuals style](https://github.com/emilk/egui/pull/450).
* Plot: Renamed `Curve` to `Line`.
* `TopPanel::top` is now `TopBottomPanel::top`.
* `SidePanel::left` no longet takes the default width by argument, but by a builder call.
* `SidePanel::left` no longer takes the default width by argument, but by a builder call.
* `SidePanel::left` is resizable by default.

### 🐛 Fixed
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ For small things, just go ahead an open a PR. For bigger things, please file an
Browse through [`ARCHITECTURE.md`](ARCHITECTURE.md) to get a sense of how all pieces connects.

You can test your code locally by running `./scripts/check.sh`.
There are snapshots test that might need to be updated. Run the tests with `UPDATE_SNAPSHOTS=true` to update them.
There are snapshots test that might need to be updated.
Run the tests with `UPDATE_SNAPSHOTS=true cargo test --workspace --all-features` to update all of them.
For more info about the tests see [egui_kittest](./crates/egui_kittest/README.md).

We use [git-lfs](https://git-lfs.com/) to store big files in the repository.
Expand Down Expand Up @@ -101,6 +102,7 @@ While using an immediate mode gui is simple, implementing one is a lot more tric
* Avoid double negatives
* Flip `if !condition {} else {}`
* Sets of things should be lexicographically sorted (e.g. crate dependencies in `Cargo.toml`)
* Put each type in their own file, unless they are trivial (e.g. a `struct` with no `impl`)
* Break the above rules when it makes sense


Expand Down
42 changes: 42 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df099ccb16cd014ff054ac1bf392c67feeef57164b05c42f037cd40f5d4357f4"
dependencies = [
"clipboard-win",
"core-graphics",
"image",
"log",
"objc2",
"objc2-app-kit",
"objc2-foundation",
"parking_lot",
"windows-sys 0.48.0",
"x11rb",
]

Expand Down Expand Up @@ -1257,6 +1260,7 @@ dependencies = [
"accesskit",
"ahash",
"backtrace",
"bitflags 2.6.0",
"document-features",
"emath",
"epaint",
Expand Down Expand Up @@ -1292,6 +1296,7 @@ dependencies = [
"accesskit_winit",
"ahash",
"arboard",
"bytemuck",
"document-features",
"egui",
"log",
Expand All @@ -1315,6 +1320,7 @@ dependencies = [
"egui",
"egui_demo_lib",
"egui_extras",
"egui_kittest",
"ehttp",
"env_logger",
"image",
Expand Down Expand Up @@ -1391,6 +1397,7 @@ version = "0.30.0"
dependencies = [
"dify",
"document-features",
"eframe",
"egui",
"egui-wgpu",
"image",
Expand Down Expand Up @@ -2202,12 +2209,24 @@ dependencies = [
"byteorder-lite",
"color_quant",
"gif",
"image-webp",
"num-traits",
"png",
"tiff",
"zune-core",
"zune-jpeg",
]

[[package]]
name = "image-webp"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e031e8e3d94711a9ccb5d6ea357439ef3dcbed361798bd4071dc4d9793fbe22f"
dependencies = [
"byteorder-lite",
"quick-error",
]

[[package]]
name = "images"
version = "0.1.0"
Expand Down Expand Up @@ -2300,6 +2319,12 @@ dependencies = [
"libc",
]

[[package]]
name = "jpeg-decoder"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0"

[[package]]
name = "js-sys"
version = "0.3.72"
Expand Down Expand Up @@ -3165,6 +3190,12 @@ dependencies = [
"puffin_http",
]

[[package]]
name = "quick-error"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"

[[package]]
name = "quick-xml"
version = "0.30.0"
Expand Down Expand Up @@ -3865,6 +3896,17 @@ dependencies = [
"syn",
]

[[package]]
name = "tiff"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba1310fcea54c6a9a4fd1aad794ecc02c31682f6bfbecdf460bf19533eed1e3e"
dependencies = [
"flate2",
"jpeg-decoder",
"weezl",
]

[[package]]
name = "time"
version = "0.3.36"
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ ahash = { version = "0.8.11", default-features = false, features = [
"std",
] }
backtrace = "0.3"
bitflags = "2.6"
bytemuck = "1.7.2"
criterion = { version = "0.5.1", default-features = false }
dify = { version = "0.7", default-features = false }
Expand Down Expand Up @@ -266,11 +267,10 @@ use_self = "warn"
useless_transmute = "warn"
verbose_file_reads = "warn"
wildcard_dependencies = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"


# TODO(emilk): enable more of these lints:
# TODO(emilk): maybe enable more of these lints?
iter_over_hash_type = "allow"
missing_assert_message = "allow"
should_panic_without_expect = "allow"
Expand All @@ -284,3 +284,4 @@ let_underscore_untyped = "allow"
manual_range_contains = "allow" # this one is just worse imho
self_named_module_files = "allow" # Disabled waiting on https://github.com/rust-lang/rust-clippy/issues/9602
significant_drop_tightening = "allow" # Too many false positives
wildcard_imports = "allow" # `use crate::*` is useful to avoid merge conflicts when adding/removing imports
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ Light Theme:

* [`ab_glyph`](https://crates.io/crates/ab_glyph)
* [`ahash`](https://crates.io/crates/ahash)
* [`bitflags`](https://crates.io/crates/bitflags)
* [`nohash-hasher`](https://crates.io/crates/nohash-hasher)
* [`parking_lot`](https://crates.io/crates/parking_lot)

Expand Down
3 changes: 3 additions & 0 deletions crates/eframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,18 @@ windows-sys = { workspace = true, features = [
# web:
[target.'cfg(target_arch = "wasm32")'.dependencies]
bytemuck.workspace = true
image = { workspace = true, features = ["png"] } # For copying images
js-sys = "0.3"
percent-encoding = "2.1"
wasm-bindgen.workspace = true
wasm-bindgen-futures.workspace = true
web-sys = { workspace = true, features = [
"BinaryType",
"Blob",
"BlobPropertyBag",
"Clipboard",
"ClipboardEvent",
"ClipboardItem",
"CompositionEvent",
"console",
"CssStyleDeclaration",
Expand Down
67 changes: 66 additions & 1 deletion crates/eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,28 @@ impl HasDisplayHandle for CreationContext<'_> {
}
}

impl CreationContext<'_> {
/// Create a new empty [CreationContext] for testing [App]s in kittest.
#[doc(hidden)]
pub fn _new_kittest(egui_ctx: egui::Context) -> Self {
Self {
egui_ctx,
integration_info: IntegrationInfo::mock(),
storage: None,
#[cfg(feature = "glow")]
gl: None,
#[cfg(feature = "glow")]
get_proc_address: None,
#[cfg(feature = "wgpu")]
wgpu_render_state: None,
#[cfg(not(target_arch = "wasm32"))]
raw_window_handle: Err(HandleError::NotSupported),
#[cfg(not(target_arch = "wasm32"))]
raw_display_handle: Err(HandleError::NotSupported),
}
}
}

// ----------------------------------------------------------------------------

/// Implement this trait to write apps that can be compiled for both web/wasm and desktop/native using [`eframe`](https://github.com/emilk/egui/tree/master/crates/eframe).
Expand Down Expand Up @@ -617,7 +639,8 @@ pub struct Frame {

/// Can be used to manage GPU resources for custom rendering with WGPU using [`egui::PaintCallback`]s.
#[cfg(feature = "wgpu")]
pub(crate) wgpu_render_state: Option<egui_wgpu::RenderState>,
#[doc(hidden)]
pub wgpu_render_state: Option<egui_wgpu::RenderState>,

/// Raw platform window handle
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -651,6 +674,25 @@ impl HasDisplayHandle for Frame {
}

impl Frame {
/// Create a new empty [Frame] for testing [App]s in kittest.
#[doc(hidden)]
pub fn _new_kittest() -> Self {
Self {
#[cfg(feature = "glow")]
gl: None,
#[cfg(all(feature = "glow", not(target_arch = "wasm32")))]
glow_register_native_texture: None,
info: IntegrationInfo::mock(),
#[cfg(not(target_arch = "wasm32"))]
raw_display_handle: Err(HandleError::NotSupported),
#[cfg(not(target_arch = "wasm32"))]
raw_window_handle: Err(HandleError::NotSupported),
storage: None,
#[cfg(feature = "wgpu")]
wgpu_render_state: None,
}
}

/// True if you are in a web environment.
///
/// Equivalent to `cfg!(target_arch = "wasm32")`
Expand Down Expand Up @@ -794,6 +836,29 @@ pub struct IntegrationInfo {
pub cpu_usage: Option<f32>,
}

impl IntegrationInfo {
fn mock() -> Self {
Self {
#[cfg(target_arch = "wasm32")]
web_info: WebInfo {
user_agent: "kittest".to_owned(),
location: Location {
url: "http://localhost".to_owned(),
protocol: "http:".to_owned(),
host: "localhost".to_owned(),
hostname: "localhost".to_owned(),
port: "80".to_owned(),
hash: String::new(),
query: String::new(),
query_map: Default::default(),
origin: "http://localhost".to_owned(),
},
},
cpu_usage: None,
}
}
}

// ----------------------------------------------------------------------------

/// A place where you can store custom data in a way that persists when you restart the app.
Expand Down
18 changes: 18 additions & 0 deletions crates/eframe/src/web/app_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,15 @@ impl AppRunner {
}

fn handle_platform_output(&self, platform_output: egui::PlatformOutput) {
#![allow(deprecated)]

#[cfg(feature = "web_screen_reader")]
if self.egui_ctx.options(|o| o.screen_reader) {
super::screen_reader::speak(&platform_output.events_description());
}

let egui::PlatformOutput {
commands,
cursor_icon,
open_url,
copied_text,
Expand All @@ -310,7 +313,22 @@ impl AppRunner {
request_discard_reasons: _, // handled by `Context::run`
} = platform_output;

for command in commands {
match command {
egui::OutputCommand::CopyText(text) => {
super::set_clipboard_text(&text);
}
egui::OutputCommand::CopyImage(image) => {
super::set_clipboard_image(&image);
}
egui::OutputCommand::OpenUrl(open_url) => {
super::open_url(&open_url.url, open_url.new_tab);
}
}
}

super::set_cursor_icon(cursor_icon);

if let Some(open) = open_url {
super::open_url(&open.url, open.new_tab);
}
Expand Down
Loading

0 comments on commit a43040e

Please sign in to comment.