Skip to content

Commit

Permalink
Merge branch 'master' into antoine/modal-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 committed Dec 3, 2024
2 parents 64c0c62 + 8647b56 commit 09667f8
Show file tree
Hide file tree
Showing 62 changed files with 400 additions and 158 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cargo_machete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Machete
uses: bnjbvr/cargo-machete@main
run: cargo install cargo-machete --locked && cargo machete
2 changes: 1 addition & 1 deletion .github/workflows/deploy_web_demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
with:
profile: minimal
target: wasm32-unknown-unknown
toolchain: 1.77.0
toolchain: 1.79.0
override: true

- uses: Swatinem/rust-cache@v2
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.77.0
toolchain: 1.79.0

- name: Install packages (Linux)
if: runner.os == 'Linux'
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.77.0
toolchain: 1.79.0
targets: wasm32-unknown-unknown

- run: sudo apt-get update && sudo apt-get install libgtk-3-dev libatk1.0-dev
Expand Down Expand Up @@ -155,7 +155,7 @@ jobs:
- uses: actions/checkout@v4
- uses: EmbarkStudios/cargo-deny-action@v1
with:
rust-version: "1.77.0"
rust-version: "1.79.0"
log-level: error
command: check
arguments: --target ${{ matrix.target }}
Expand All @@ -170,7 +170,7 @@ jobs:

- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.77.0
toolchain: 1.79.0
targets: aarch64-linux-android

- name: Set up cargo cache
Expand All @@ -189,7 +189,7 @@ jobs:

- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.77.0
toolchain: 1.79.0
targets: aarch64-apple-ios

- name: Set up cargo cache
Expand All @@ -208,7 +208,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.77.0
toolchain: 1.79.0

- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
Expand All @@ -232,7 +232,7 @@ jobs:
lfs: true
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.77.0
toolchain: 1.79.0

- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
Expand Down
16 changes: 14 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ members = [
[workspace.package]
edition = "2021"
license = "MIT OR Apache-2.0"
rust-version = "1.77"
rust-version = "1.79"
version = "0.29.1"


Expand Down Expand Up @@ -145,6 +145,7 @@ disallowed_types = "warn" # See clippy.toml
doc_link_with_quotes = "warn"
doc_markdown = "warn"
empty_enum = "warn"
empty_enum_variants_with_brackets = "warn"
enum_glob_use = "warn"
equatable_if_let = "warn"
exit = "warn"
Expand All @@ -169,6 +170,8 @@ inefficient_to_string = "warn"
infinite_loop = "warn"
into_iter_without_iter = "warn"
invalid_upcast_comparisons = "warn"
iter_filter_is_ok = "warn"
iter_filter_is_some = "warn"
iter_not_returning_iterator = "warn"
iter_on_empty_collections = "warn"
iter_on_single_items = "warn"
Expand All @@ -185,6 +188,7 @@ macro_use_imports = "warn"
manual_assert = "warn"
manual_clamp = "warn"
manual_instant_elapsed = "warn"
manual_is_variant_and = "warn"
manual_let_else = "warn"
manual_ok_or = "warn"
manual_string_new = "warn"
Expand All @@ -202,6 +206,7 @@ mismatching_type_param_order = "warn"
missing_enforced_import_renames = "warn"
missing_errors_doc = "warn"
missing_safety_doc = "warn"
mixed_attributes_style = "warn"
mut_mut = "warn"
mutex_integer = "warn"
needless_borrow = "warn"
Expand All @@ -211,21 +216,25 @@ needless_pass_by_ref_mut = "warn"
needless_pass_by_value = "warn"
negative_feature_names = "warn"
nonstandard_macro_braces = "warn"
option_as_ref_cloned = "warn"
option_option = "warn"
path_buf_push_overwrite = "warn"
print_stderr = "warn"
ptr_as_ptr = "warn"
ptr_cast_constness = "warn"
pub_underscore_fields = "warn"
pub_without_shorthand = "warn"
rc_mutex = "warn"
readonly_write_lock = "warn"
redundant_type_annotations = "warn"
ref_as_ptr = "warn"
ref_option_ref = "warn"
ref_patterns = "warn"
rest_pat_in_fully_bound_structs = "warn"
same_functions_in_if_condition = "warn"
semicolon_if_nothing_returned = "warn"
single_match_else = "warn"
str_split_at_newline = "warn"
str_to_string = "warn"
string_add = "warn"
string_add_assign = "warn"
Expand Down Expand Up @@ -261,12 +270,15 @@ zero_sized_map_values = "warn"

# TODO(emilk): enable more of these lints:
iter_over_hash_type = "allow"
let_underscore_untyped = "allow"
missing_assert_message = "allow"
should_panic_without_expect = "allow"
too_many_lines = "allow"
unwrap_used = "allow" # TODO(emilk): We really wanna warn on this one

# These are meh:
assigning_clones = "allow" # No please
let_underscore_must_use = "allow"
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
7 changes: 5 additions & 2 deletions clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# -----------------------------------------------------------------------------
# Section identical to scripts/clippy_wasm/clippy.toml:

msrv = "1.77"
msrv = "1.79"

allow-unwrap-in-tests = true

Expand Down Expand Up @@ -69,9 +69,12 @@ disallowed-types = [

# Allow-list of words for markdown in docstrings https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
doc-valid-idents = [
# You must also update the same list in the root `clippy.toml`!
# You must also update the same list in `scripts/clippy_wasm/clippy.toml`!
"AccessKit",
"WebGL",
"WebGL1",
"WebGL2",
"WebGPU",
"VirtualBox",
"..",
]
2 changes: 1 addition & 1 deletion crates/eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ pub struct WebOptions {
/// Unused by webgl context as of writing.
pub depth_buffer: u8,

/// Which version of WebGl context to select
/// Which version of WebGL context to select
///
/// Default: [`WebGlContextOption::BestFirst`].
#[cfg(feature = "glow")]
Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/src/native/event_loop_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl EventLoopGuard {
cell.get().is_none(),
"Attempted to set a new event loop while one is already set"
);
cell.set(Some(event_loop as *const ActiveEventLoop));
cell.set(Some(std::ptr::from_ref::<ActiveEventLoop>(event_loop)));
});
Self
}
Expand Down
5 changes: 3 additions & 2 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,13 +661,14 @@ impl<'app> GlowWinitRunning<'app> {
{
for action in viewport.actions_requested.drain() {
match action {
ActionRequested::Screenshot => {
ActionRequested::Screenshot(user_data) => {
let screenshot = painter.read_screen_rgba(screen_size_in_pixels);
egui_winit
.egui_input_mut()
.events
.push(egui::Event::Screenshot {
viewport_id,
user_data,
image: screenshot.into(),
});
}
Expand Down Expand Up @@ -943,7 +944,7 @@ impl GlutinWindowContext {
// we might want to expose this option to users in the future. maybe using an env var or using native_options.
//
// The justification for FallbackEgl over PreferEgl is at https://github.com/emilk/egui/pull/2526#issuecomment-1400229576 .
.with_preference(glutin_winit::ApiPreference::PreferEgl)
.with_preference(glutin_winit::ApiPreference::FallbackEgl)
.with_window_attributes(Some(egui_winit::create_winit_window_attributes(
egui_ctx,
event_loop,
Expand Down
45 changes: 32 additions & 13 deletions crates/eframe/src/native/wgpu_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,16 @@ impl<'app> WgpuWinitRunning<'app> {

let clipped_primitives = egui_ctx.tessellate(shapes, pixels_per_point);

let screenshot_requested = viewport
.actions_requested
.take(&ActionRequested::Screenshot)
.is_some();
let mut screenshot_commands = vec![];
viewport.actions_requested.retain(|cmd| {
if let ActionRequested::Screenshot(info) = cmd {
screenshot_commands.push(info.clone());
false
} else {
true
}
});
let screenshot_requested = !screenshot_commands.is_empty();
let (vsync_secs, screenshot) = painter.paint_and_update_textures(
viewport_id,
pixels_per_point,
Expand All @@ -655,19 +661,32 @@ impl<'app> WgpuWinitRunning<'app> {
&textures_delta,
screenshot_requested,
);
if let Some(screenshot) = screenshot {
egui_winit
.egui_input_mut()
.events
.push(egui::Event::Screenshot {
viewport_id,
image: screenshot.into(),
});
match (screenshot_requested, screenshot) {
(false, None) => {}
(true, Some(screenshot)) => {
let screenshot = Arc::new(screenshot);
for user_data in screenshot_commands {
egui_winit
.egui_input_mut()
.events
.push(egui::Event::Screenshot {
viewport_id,
user_data,
image: screenshot.clone(),
});
}
}
(true, None) => {
log::error!("Bug in egui_wgpu: screenshot requested, but no screenshot was taken");
}
(false, Some(_)) => {
log::warn!("Bug in egui_wgpu: Got screenshot without requesting it");
}
}

for action in viewport.actions_requested.drain() {
match action {
ActionRequested::Screenshot => {
ActionRequested::Screenshot { .. } => {
// already handled above
}
ActionRequested::Cut => {
Expand Down
34 changes: 3 additions & 31 deletions crates/eframe/src/web/web_painter_wgpu.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,13 @@
use raw_window_handle::{
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawDisplayHandle,
RawWindowHandle, WebDisplayHandle, WebWindowHandle, WindowHandle,
};
use std::sync::Arc;

use wasm_bindgen::JsValue;
use web_sys::HtmlCanvasElement;

use crate::WebOptions;
use egui_wgpu::{RenderState, SurfaceErrorAction, WgpuSetup};

use super::web_painter::WebPainter;

struct EguiWebWindow(u32);

#[allow(unsafe_code)]
impl HasWindowHandle for EguiWebWindow {
fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError> {
// SAFETY: there is no lifetime here.
unsafe {
Ok(WindowHandle::borrow_raw(RawWindowHandle::Web(
WebWindowHandle::new(self.0),
)))
}
}
}
use crate::WebOptions;

#[allow(unsafe_code)]
impl HasDisplayHandle for EguiWebWindow {
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
// SAFETY: there is no lifetime here.
unsafe {
Ok(DisplayHandle::borrow_raw(RawDisplayHandle::Web(
WebDisplayHandle::new(),
)))
}
}
}
use super::web_painter::WebPainter;

pub(crate) struct WebPainterWgpu {
canvas: HtmlCanvasElement,
Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/src/web/web_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct WebRunner {
/// Have we ever panicked?
panic_handler: PanicHandler,

/// If we ever panic during running, this RefCell is poisoned.
/// If we ever panic during running, this `RefCell` is poisoned.
/// So before we use it, we need to check [`Self::panic_handler`].
runner: Rc<RefCell<Option<AppRunner>>>,

Expand Down
2 changes: 1 addition & 1 deletion crates/egui-wgpu/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub struct ScreenDescriptor {
/// Size of the window in physical pixels.
pub size_in_pixels: [u32; 2],

/// HiDPI scale factor (pixels per point).
/// High-DPI scale factor (pixels per point).
pub pixels_per_point: f32,
}

Expand Down
6 changes: 3 additions & 3 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ fn translate_cursor(cursor_icon: egui::CursorIcon) -> Option<winit::window::Curs
// ---------------------------------------------------------------------------
#[derive(PartialEq, Eq, Hash, Debug)]
pub enum ActionRequested {
Screenshot,
Screenshot(egui::UserData),
Cut,
Copy,
Paste,
Expand Down Expand Up @@ -1516,8 +1516,8 @@ fn process_viewport_command(
log::warn!("{command:?}: {err}");
}
}
ViewportCommand::Screenshot => {
actions_requested.insert(ActionRequested::Screenshot);
ViewportCommand::Screenshot(user_data) => {
actions_requested.insert(ActionRequested::Screenshot(user_data));
}
ViewportCommand::RequestCut => {
actions_requested.insert(ActionRequested::Cut);
Expand Down
Loading

0 comments on commit 09667f8

Please sign in to comment.