Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
420 changes: 393 additions & 27 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ chrono = { version = "0.4.42", default-features = false }
cint = "0.3.1"
color-hex = "0.2.0"
criterion = { version = "0.7.0", default-features = false }
cursor-icon = "1"
dify = { version = "0.7.4", default-features = false }
directories = "6.0.0"
document-features = "0.2.11"
dpi = "0.1"
ehttp = { version = "0.5.0", default-features = false }
enum-map = "2.7.3"
env_logger = { version = "0.11.8", default-features = false }
Expand Down Expand Up @@ -142,7 +144,8 @@ web-time = "1.1.0" # Timekeeping for native and web
webbrowser = "1.0.5"
wgpu = { version = "27.0.1", default-features = false, features = ["std"] }
windows-sys = "0.61.2"
winit = { version = "0.30.12", default-features = false }
winit = { version = "0.31.0-beta.2", default-features = false }
winit-core = { version = "0.31.0-beta.2", default-features = false }


[workspace.lints.rust]
Expand Down
8 changes: 6 additions & 2 deletions crates/eframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ default = [
]

## Enable platform accessibility API implementations through [AccessKit](https://accesskit.dev/).
accesskit = ["egui-winit/accesskit"]
accesskit = ["egui/accesskit", "egui-winit/accesskit"]

# Allow crates to choose an android-activity backend via Winit
# - It's important that most applications should not have to depend on android-activity directly, and can
Expand Down Expand Up @@ -140,7 +140,8 @@ serde = { workspace = true, optional = true }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
egui-winit = { workspace = true, default-features = false, features = ["clipboard", "links"] }
image = { workspace = true, features = ["png"] } # Needed for app icon
winit = { workspace = true, default-features = false, features = ["rwh_06"] }
winit = { workspace = true, default-features = false }
winit-core.workspace = true

# optional native:
egui-wgpu = { workspace = true, optional = true, features = [
Expand Down Expand Up @@ -169,7 +170,10 @@ objc2-foundation = { workspace = true, default-features = false, features = [
objc2-app-kit = { workspace = true, default-features = false, features = [
"std",
"NSApplication",
"NSBitmapImageRep",
"NSGraphics",
"NSImage",
"NSImageRep",
"NSMenu",
"NSMenuItem",
"NSResponder",
Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub use winit::{event_loop::EventLoopBuilder, window::WindowAttributes};
/// done by `EFrame`.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))]
pub type EventLoopBuilderHook = Box<dyn FnOnce(&mut EventLoopBuilder<UserEvent>)>;
pub type EventLoopBuilderHook = Box<dyn FnOnce(&mut EventLoopBuilder)>;

/// Hook into the building of a the native window.
///
Expand Down
17 changes: 16 additions & 1 deletion crates/eframe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ pub fn create_native<'a>(
app_name: &str,
mut native_options: NativeOptions,
app_creator: AppCreator<'a>,
event_loop: &winit::event_loop::EventLoop<UserEvent>,
event_loop: &winit::event_loop::EventLoop,
) -> EframeWinitApplication<'a> {
let renderer = init_native(app_name, &mut native_options);

Expand Down Expand Up @@ -455,6 +455,10 @@ pub enum Error {
#[cfg(not(target_arch = "wasm32"))]
Winit(winit::error::OsError),

/// An request error from [`winit`].
#[cfg(not(target_arch = "wasm32"))]
WinitRequest(winit::error::RequestError),

/// An error from [`winit::event_loop::EventLoop`].
#[cfg(not(target_arch = "wasm32"))]
WinitEventLoop(winit::error::EventLoopError),
Expand Down Expand Up @@ -486,6 +490,14 @@ impl From<winit::error::OsError> for Error {
}
}

#[cfg(not(target_arch = "wasm32"))]
impl From<winit::error::RequestError> for Error {
#[inline]
fn from(err: winit::error::RequestError) -> Self {
Self::WinitRequest(err)
}
}

#[cfg(not(target_arch = "wasm32"))]
impl From<winit::error::EventLoopError> for Error {
#[inline]
Expand Down Expand Up @@ -555,6 +567,9 @@ impl std::fmt::Display for Error {
Self::Wgpu(err) => {
write!(f, "WGPU error: {err}")
}
Error::WinitRequest(err) => {
write!(f, "winit request error: {err}")
}
}
}
}
Expand Down
63 changes: 33 additions & 30 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::epi;
#[cfg_attr(target_os = "ios", allow(dead_code, unused_variables, unused_mut))]
pub fn viewport_builder(
egui_zoom_factor: f32,
event_loop: &ActiveEventLoop,
event_loop: &dyn ActiveEventLoop,
native_options: &mut epi::NativeOptions,
window_settings: Option<WindowSettings>,
) -> ViewportBuilder {
Expand Down Expand Up @@ -71,15 +71,16 @@ pub fn viewport_builder(
.primary_monitor()
.or_else(|| event_loop.available_monitors().next())
{
let monitor_size = monitor
.size()
.to_logical::<f32>(egui_zoom_factor as f64 * monitor.scale_factor());
let inner_size = inner_size_points.unwrap_or(egui::Vec2 { x: 800.0, y: 600.0 });
if 0.0 < monitor_size.width && 0.0 < monitor_size.height {
let x = (monitor_size.width - inner_size.x) / 2.0;
let y = (monitor_size.height - inner_size.y) / 2.0;
viewport_builder = viewport_builder.with_position([x, y]);
}
todo!()
// let monitor_size = monitor
// .size()
// .to_logical::<f32>(egui_zoom_factor as f64 * monitor.scale_factor());
// let inner_size = inner_size_points.unwrap_or(egui::Vec2 { x: 800.0, y: 600.0 });
// if 0.0 < monitor_size.width && 0.0 < monitor_size.height {
// let x = (monitor_size.width - inner_size.x) / 2.0;
// let y = (monitor_size.height - inner_size.y) / 2.0;
// viewport_builder = viewport_builder.with_position([x, y]);
// }
}
}

Expand All @@ -90,7 +91,7 @@ pub fn viewport_builder(
}

pub fn apply_window_settings(
window: &winit::window::Window,
window: &dyn winit::window::Window,
window_settings: Option<WindowSettings>,
) {
profiling::function_scope!();
Expand All @@ -100,7 +101,7 @@ pub fn apply_window_settings(
}

#[cfg(not(target_os = "ios"))]
fn largest_monitor_point_size(egui_zoom_factor: f32, event_loop: &ActiveEventLoop) -> egui::Vec2 {
fn largest_monitor_point_size(egui_zoom_factor: f32, event_loop: &dyn ActiveEventLoop) -> egui::Vec2 {
profiling::function_scope!();
let mut max_size = egui::Vec2::ZERO;

Expand All @@ -110,11 +111,12 @@ fn largest_monitor_point_size(egui_zoom_factor: f32, event_loop: &ActiveEventLoo
};

for monitor in available_monitors {
let size = monitor
.size()
.to_logical::<f32>(egui_zoom_factor as f64 * monitor.scale_factor());
let size = egui::vec2(size.width, size.height);
max_size = max_size.max(size);
todo!()
// let size = monitor
// .size()
// .to_logical::<f32>(egui_zoom_factor as f64 * monitor.scale_factor());
// let size = egui::vec2(size.width, size.height);
// max_size = max_size.max(size);
}

if max_size == egui::Vec2::ZERO {
Expand Down Expand Up @@ -171,7 +173,7 @@ impl EpiIntegration {
#[allow(clippy::allow_attributes, clippy::too_many_arguments)]
pub fn new(
egui_ctx: egui::Context,
window: &winit::window::Window,
window: &dyn winit::window::Window,
app_name: &str,
native_options: &crate::NativeOptions,
storage: Option<Box<dyn epi::Storage>>,
Expand Down Expand Up @@ -233,22 +235,23 @@ impl EpiIntegration {

pub fn on_window_event(
&mut self,
window: &winit::window::Window,
window: &dyn winit::window::Window,
egui_winit: &mut egui_winit::State,
event: &winit::event::WindowEvent,
) -> EventResponse {
profiling::function_scope!(egui_winit::short_window_event_description(event));

use winit::event::{ElementState, MouseButton, WindowEvent};

if let WindowEvent::MouseInput {
button: MouseButton::Left,
state: ElementState::Pressed,
..
} = event
{
self.can_drag_window = true;
}
// TODO
// if let WindowEvent::MouseInput {
// button: MouseButton::Left,
// state: ElementState::Pressed,
// ..
// } = event
// {
// self.can_drag_window = true;
// }

egui_winit.on_window_event(window, event)
}
Expand Down Expand Up @@ -304,7 +307,7 @@ impl EpiIntegration {
self.frame.info.cpu_usage = Some(seconds);
}

pub fn post_rendering(&mut self, window: &winit::window::Window) {
pub fn post_rendering(&mut self, window: &dyn winit::window::Window) {
profiling::function_scope!();
if std::mem::take(&mut self.is_first_frame) {
// We keep hidden until we've painted something. See https://github.com/emilk/egui/pull/2279
Expand All @@ -318,7 +321,7 @@ impl EpiIntegration {
pub fn maybe_autosave(
&mut self,
app: &mut dyn epi::App,
window: Option<&winit::window::Window>,
window: Option<&dyn winit::window::Window>,
) {
let now = Instant::now();
if now - self.last_auto_save > app.auto_save_interval() {
Expand All @@ -327,7 +330,7 @@ impl EpiIntegration {
}
}

pub fn save(&mut self, app: &mut dyn epi::App, window: Option<&winit::window::Window>) {
pub fn save(&mut self, app: &mut dyn epi::App, window: Option<&dyn winit::window::Window>) {
#[cfg(not(feature = "persistence"))]
let _ = (self, app, window);

Expand Down
10 changes: 5 additions & 5 deletions crates/eframe/src/native/event_loop_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ use std::cell::Cell;
use winit::event_loop::ActiveEventLoop;

thread_local! {
static CURRENT_EVENT_LOOP: Cell<Option<*const ActiveEventLoop>> = const { Cell::new(None) };
static CURRENT_EVENT_LOOP: Cell<Option<*const dyn ActiveEventLoop>> = const { Cell::new(None) };
}

struct EventLoopGuard;

impl EventLoopGuard {
fn new(event_loop: &ActiveEventLoop) -> Self {
fn new(event_loop: &dyn ActiveEventLoop) -> Self {
CURRENT_EVENT_LOOP.with(|cell| {
assert!(
cell.get().is_none(),
"Attempted to set a new event loop while one is already set"
);
cell.set(Some(std::ptr::from_ref::<ActiveEventLoop>(event_loop)));
cell.set(Some(std::ptr::from_ref::<dyn ActiveEventLoop>(event_loop)));
});
Self
}
Expand All @@ -30,7 +30,7 @@ impl Drop for EventLoopGuard {
#[expect(unsafe_code)]
pub fn with_current_event_loop<F, R>(f: F) -> Option<R>
where
F: FnOnce(&ActiveEventLoop) -> R,
F: FnOnce(&dyn ActiveEventLoop) -> R,
{
CURRENT_EVENT_LOOP.with(|cell| {
cell.get().map(|ptr| {
Expand All @@ -47,7 +47,7 @@ where
}

// The only public interface to use the event loop
pub fn with_event_loop_context(event_loop: &ActiveEventLoop, f: impl FnOnce()) {
pub fn with_event_loop_context(event_loop: &dyn ActiveEventLoop, f: impl FnOnce()) {
// NOTE: For safety, this guard must NOT be leaked.
let _guard = EventLoopGuard::new(event_loop);
f();
Expand Down
Loading
Loading