Skip to content
Open
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
6 changes: 6 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Enable these if you want to run `cargo +nightly fmt`:
#group_imports = "StdExternalCrate"
#imports_granularity = "Module"

# To apply these, uncomment the above lines, then run `cargo +nightly fmt`.
# Then comment them again, and run `cargo fmt`
3 changes: 2 additions & 1 deletion crates/ecolor/src/cint_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{Color32, Hsva, HsvaGamma, Rgba, linear_f32_from_linear_u8, linear_u8_from_linear_f32};
use cint::{Alpha, ColorInterop, EncodedSrgb, Hsv, LinearSrgb, PremultipliedAlpha};

use super::{Color32, Hsva, HsvaGamma, Rgba, linear_f32_from_linear_u8, linear_u8_from_linear_f32};

// ---- Color32 ----

impl From<Alpha<EncodedSrgb<u8>>> for Color32 {
Expand Down
6 changes: 3 additions & 3 deletions crates/ecolor/src/hex_color_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
//! Supports the 3, 4, 6, and 8-digit formats, according to the specification in
//! <https://drafts.csswg.org/css-color-4/#hex-color>

use std::{fmt::Display, str::FromStr};
use std::fmt::Display;
use std::str::FromStr;

use crate::Color32;

Expand Down Expand Up @@ -170,8 +171,7 @@ mod tests {

#[test]
fn hex_string_formats() {
use Color32 as C;
use HexColor as H;
use {Color32 as C, HexColor as H};
let cases = [
(H::Hex3(C::RED), "#f00"),
(H::Hex4(C::RED), "#f00f"),
Expand Down
9 changes: 4 additions & 5 deletions crates/eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@
#[cfg(target_arch = "wasm32")]
use std::any::Any;

#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))]
pub use crate::native::winit_integration::UserEvent;

#[cfg(not(target_arch = "wasm32"))]
use raw_window_handle::{
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawDisplayHandle,
RawWindowHandle, WindowHandle,
};
#[cfg(not(target_arch = "wasm32"))]
use static_assertions::assert_not_impl_any;

#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))]
pub use winit::{event_loop::EventLoopBuilder, window::WindowAttributes};

#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))]
pub use crate::native::winit_integration::UserEvent;

/// Hook into the building of an event loop before it is run
///
/// You can configure any platform specific details required on top of the default configuration
Expand Down
14 changes: 5 additions & 9 deletions crates/eframe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,10 @@
compile_error!("`accesskit` feature is only available with `android-game-activity`");

// Re-export all useful libraries:
pub use {egui, egui::emath, egui::epaint};

pub use egui;
pub use egui::{emath, epaint};
#[cfg(feature = "glow")]
pub use {egui_glow, glow};

#[cfg(feature = "wgpu_no_default_features")]
pub use {egui_wgpu, wgpu};

Expand All @@ -174,7 +173,6 @@ pub(crate) mod stopwatch;

#[cfg(target_arch = "wasm32")]
pub use wasm_bindgen;

#[cfg(target_arch = "wasm32")]
pub use web_sys;

Expand All @@ -193,16 +191,14 @@ mod native;

#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))]
pub use native::run::EframeWinitApplication;

#[cfg(feature = "persistence")]
pub use native::file_storage::storage_dir;
#[cfg(not(any(target_arch = "wasm32", target_os = "ios")))]
#[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))]
pub use native::run::EframePumpStatus;

#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))]
#[cfg(feature = "persistence")]
pub use native::file_storage::storage_dir;
pub use native::run::EframeWinitApplication;

#[cfg(not(target_arch = "wasm32"))]
pub mod icon_data;
Expand Down
3 changes: 2 additions & 1 deletion crates/eframe/src/native/app_icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@ fn set_title_and_icon(_title: &str, _icon_data: Option<&IconData>) -> AppIconSta
#[cfg(target_os = "windows")]
#[expect(unsafe_code)]
fn set_app_icon_windows(icon_data: &IconData) -> AppIconStatus {
use crate::icon_data::IconDataExt as _;
use windows_sys::Win32::UI::Input::KeyboardAndMouse::GetActiveWindow;
use windows_sys::Win32::UI::WindowsAndMessaging::{
CreateIconFromResourceEx, GetSystemMetrics, HICON, ICON_BIG, ICON_SMALL, LR_DEFAULTCOLOR,
SM_CXICON, SM_CXSMICON, SendMessageW, WM_SETICON,
};

use crate::icon_data::IconDataExt as _;

// We would get fairly far already with winit's `set_window_icon` (which is exposed to eframe) actually!
// However, it only sets ICON_SMALL, i.e. doesn't allow us to set a higher resolution icon for the task bar.
// Also, there is scaling issues, detailed below.
Expand Down
8 changes: 3 additions & 5 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
//! Common tools used by [`super::glow_integration`] and [`super::wgpu_integration`].

use web_time::Instant;

use std::path::PathBuf;
use winit::event_loop::ActiveEventLoop;

use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _};

use egui::{DeferredViewportUiCallback, ViewportBuilder, ViewportId};
use egui_winit::{EventResponse, WindowSettings};
use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _};
use web_time::Instant;
use winit::event_loop::ActiveEventLoop;

use crate::epi;

Expand Down
1 change: 1 addition & 0 deletions crates/eframe/src/native/event_loop_context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::cell::Cell;

use winit::event_loop::ActiveEventLoop;

thread_local! {
Expand Down
14 changes: 6 additions & 8 deletions crates/eframe/src/native/file_storage.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::{
collections::HashMap,
io::Write as _,
path::{Path, PathBuf},
};
use std::collections::HashMap;
use std::io::Write as _;
use std::path::{Path, PathBuf};

/// The folder where `eframe` will store its state.
///
Expand All @@ -15,8 +13,9 @@ use std::{
/// * macOS: `/Users/UserName/Library/Application Support/APP_ID`
/// * Windows: `C:\Users\UserName\AppData\Roaming\APP_ID\data`
pub fn storage_dir(app_id: &str) -> Option<PathBuf> {
use egui::os::OperatingSystem as OS;
use std::env::var_os;

use egui::os::OperatingSystem as OS;
match OS::from_target_os() {
OS::Nix => var_os("XDG_DATA_HOME")
.map(PathBuf::from)
Expand Down Expand Up @@ -46,8 +45,7 @@ pub fn storage_dir(app_id: &str) -> Option<PathBuf> {
fn roaming_appdata() -> Option<PathBuf> {
use std::ffi::OsString;
use std::os::windows::ffi::OsStringExt as _;
use std::ptr;
use std::slice;
use std::{ptr, slice};

use windows_sys::Win32::Foundation::S_OK;
use windows_sys::Win32::System::Com::CoTaskMemFree;
Expand Down
42 changes: 18 additions & 24 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,33 @@

#![allow(clippy::undocumented_unsafe_blocks)]

use std::{cell::RefCell, num::NonZeroU32, rc::Rc, sync::Arc, time::Instant};

use egui_winit::ActionRequested;
use glutin::{
config::GlConfig as _,
context::NotCurrentGlContext as _,
display::GetGlDisplay as _,
prelude::{GlDisplay as _, PossiblyCurrentGlContext as _},
surface::GlSurface as _,
};
use raw_window_handle::HasWindowHandle as _;
use winit::{
event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy},
window::{Window, WindowId},
};
use std::cell::RefCell;
use std::num::NonZeroU32;
use std::rc::Rc;
use std::sync::Arc;
use std::time::Instant;

use ahash::HashMap;
use egui::{
DeferredViewportUiCallback, ImmediateViewport, OrderedViewportIdMap, ViewportBuilder,
ViewportClass, ViewportId, ViewportIdPair, ViewportInfo, ViewportOutput,
};
use egui_winit::ActionRequested;
#[cfg(feature = "accesskit")]
use egui_winit::accesskit_winit;
use glutin::config::GlConfig as _;
use glutin::context::NotCurrentGlContext as _;
use glutin::display::GetGlDisplay as _;
use glutin::prelude::{GlDisplay as _, PossiblyCurrentGlContext as _};
use glutin::surface::GlSurface as _;
use raw_window_handle::HasWindowHandle as _;
use winit::event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy};
use winit::window::{Window, WindowId};

use crate::{
App, AppCreator, CreationContext, NativeOptions, Result, Storage,
native::epi_integration::EpiIntegration,
};

use super::{
epi_integration, event_loop_context,
winit_integration::{EventResult, UserEvent, WinitApp, create_egui_context},
};
use super::winit_integration::{EventResult, UserEvent, WinitApp, create_egui_context};
use super::{epi_integration, event_loop_context};
use crate::native::epi_integration::EpiIntegration;
use crate::{App, AppCreator, CreationContext, NativeOptions, Result, Storage};

// ----------------------------------------------------------------------------
// Types:
Expand Down
16 changes: 6 additions & 10 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
use std::time::Instant;

use winit::{
application::ApplicationHandler,
event_loop::{ActiveEventLoop, ControlFlow, EventLoop},
window::WindowId,
};

use ahash::HashMap;
use winit::application::ApplicationHandler;
use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop};
use winit::window::WindowId;

use super::winit_integration::{UserEvent, WinitApp};
use crate::{
Result, epi,
native::{event_loop_context, winit_integration::EventResult},
};
use crate::native::event_loop_context;
use crate::native::winit_integration::EventResult;
use crate::{Result, epi};

// ----------------------------------------------------------------------------
fn create_event_loop(native_options: &mut epi::NativeOptions) -> Result<EventLoop<UserEvent>> {
Expand Down
30 changes: 15 additions & 15 deletions crates/eframe/src/native/wgpu_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@
//! There is a bunch of improvements we could do,
//! like removing a bunch of `unwraps`.

use std::{cell::RefCell, num::NonZeroU32, rc::Rc, sync::Arc, time::Instant};

use egui_winit::ActionRequested;
use parking_lot::Mutex;
use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _};
use winit::{
event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy},
window::{Window, WindowId},
};
use std::cell::RefCell;
use std::num::NonZeroU32;
use std::rc::Rc;
use std::sync::Arc;
use std::time::Instant;

use ahash::HashMap;
use egui::{
DeferredViewportUiCallback, FullOutput, ImmediateViewport, OrderedViewportIdMap,
ViewportBuilder, ViewportClass, ViewportId, ViewportIdPair, ViewportIdSet, ViewportInfo,
ViewportOutput,
};
use egui_winit::ActionRequested;
#[cfg(feature = "accesskit")]
use egui_winit::accesskit_winit;
use parking_lot::Mutex;
use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _};
use winit::event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy};
use winit::window::{Window, WindowId};
use winit_integration::UserEvent;

use crate::{
App, AppCreator, CreationContext, NativeOptions, Result, Storage,
native::{epi_integration::EpiIntegration, winit_integration::EventResult},
};

use super::{epi_integration, event_loop_context, winit_integration, winit_integration::WinitApp};
use super::winit_integration::WinitApp;
use super::{epi_integration, event_loop_context, winit_integration};
use crate::native::epi_integration::EpiIntegration;
use crate::native::winit_integration::EventResult;
use crate::{App, AppCreator, CreationContext, NativeOptions, Result, Storage};

// ----------------------------------------------------------------------------
// Types:
Expand Down
10 changes: 4 additions & 6 deletions crates/eframe/src/native/winit_integration.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use std::{sync::Arc, time::Instant};

use winit::{
event_loop::ActiveEventLoop,
window::{Window, WindowId},
};
use std::sync::Arc;
use std::time::Instant;

use egui::ViewportId;
#[cfg(feature = "accesskit")]
use egui_winit::accesskit_winit;
use winit::event_loop::ActiveEventLoop;
use winit::window::{Window, WindowId};

/// Create an egui context, restoring it from storage if possible.
pub fn create_egui_context(storage: Option<&dyn crate::Storage>) -> egui::Context {
Expand Down
7 changes: 4 additions & 3 deletions crates/eframe/src/web/app_runner.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use egui::{TexturesDelta, UserData, ViewportCommand};

use crate::{App, epi, web::web_painter::WebPainter};

use super::{NeedRepaint, now_sec, text_agent::TextAgent};
use super::text_agent::TextAgent;
use super::{NeedRepaint, now_sec};
use crate::web::web_painter::WebPainter;
use crate::{App, epi};

pub struct AppRunner {
#[allow(dead_code, clippy::allow_attributes)]
Expand Down
3 changes: 1 addition & 2 deletions crates/eframe/src/web/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use std::collections::BTreeMap;

use egui::mutex::Mutex;

use crate::epi;

use super::percent_decode;
use crate::epi;

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

Expand Down
7 changes: 3 additions & 4 deletions crates/eframe/src/web/events.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use crate::web::string_from_js_value;
use js_sys::Reflect;
use web_sys::{Document, EventTarget, ShadowRoot};

use super::{
AppRunner, Closure, DEBUG_RESIZE, JsCast as _, JsValue, WebRunner, button_from_mouse_event,
location_hash, modifiers_from_kb_event, modifiers_from_mouse_event, modifiers_from_wheel_event,
native_pixels_per_point, pos_from_mouse_event, prefers_color_scheme, primary_touch_pos,
push_touches, text_from_keyboard_event, translate_key,
};

use js_sys::Reflect;
use web_sys::{Document, EventTarget, ShadowRoot};
use crate::web::string_from_js_value;

// TODO(emilk): there are more calls to `prevent_default` and `stop_propagation`
// than what is probably needed.
Expand Down
6 changes: 2 additions & 4 deletions crates/eframe/src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ mod web_painter_glow;
mod web_painter_wgpu;

pub use backend::*;

use egui::Theme;
use wasm_bindgen::prelude::*;
use web_sys::{Document, MediaQueryList, Node};

use input::{
button_from_mouse_event, modifiers_from_kb_event, modifiers_from_mouse_event,
modifiers_from_wheel_event, pos_from_mouse_event, primary_touch_pos, push_touches,
text_from_keyboard_event, translate_key,
};
use wasm_bindgen::prelude::*;
use web_sys::{Document, MediaQueryList, Node};

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

Expand Down
Loading
Loading