diff --git a/crates/egui_demo_app/Cargo.toml b/crates/egui_demo_app/Cargo.toml index 0c50f214..8589faf8 100644 --- a/crates/egui_demo_app/Cargo.toml +++ b/crates/egui_demo_app/Cargo.toml @@ -47,7 +47,6 @@ log = { version = "0.4", features = ["std"] } bytemuck = { version = "1.7.1", optional = true } egui_extras = { version = "0.22.0", path = "../egui_extras", features = [ - "log", "image", ] } rfd = { version = "0.11", optional = true } diff --git a/crates/egui_demo_lib/Cargo.toml b/crates/egui_demo_lib/Cargo.toml index 6a826273..33b927fa 100644 --- a/crates/egui_demo_lib/Cargo.toml +++ b/crates/egui_demo_lib/Cargo.toml @@ -33,9 +33,7 @@ syntect = ["egui_extras/syntect"] [dependencies] egui = { version = "0.22.0", path = "../egui", default-features = false } -egui_extras = { version = "0.22.0", path = "../egui_extras", features = [ - "log", -] } +egui_extras = { version = "0.22.0", path = "../egui_extras" } egui_plot = { version = "0.22.0", path = "../egui_plot" } log = { version = "0.4", features = ["std"] } unicode_names2 = { version = "0.6.0", default-features = false } diff --git a/crates/egui_extras/Cargo.toml b/crates/egui_extras/Cargo.toml index 7517c71f..b6ed2245 100644 --- a/crates/egui_extras/Cargo.toml +++ b/crates/egui_extras/Cargo.toml @@ -27,7 +27,7 @@ all-features = true default = ["dep:mime_guess"] ## Shorthand for enabling the different types of image loaders (`file`, `http`, `image`, `svg`). -all-loaders = ["svg", "image", "http", "file"] +all-loaders = ["file", "http", "image", "svg"] ## Enable [`DatePickerButton`] widget. datepicker = ["chrono"] @@ -35,9 +35,6 @@ datepicker = ["chrono"] ## Add support for loading images from `file://` URIs. file = ["dep:mime_guess"] -## Log warnings using [`log`](https://docs.rs/log) crate. -log = ["dep:log", "egui/log"] - ## Add support for loading images via HTTP. http = ["dep:ehttp"] @@ -54,8 +51,11 @@ syntect = ["dep:syntect"] [dependencies] -egui = { version = "0.22.0", path = "../egui", default-features = false } +egui = { version = "0.22.0", path = "../egui", default-features = false, features = [ + "serde", +] } enum-map = { version = "2", features = ["serde"] } +log = { version = "0.4", features = ["std"] } serde = { version = "1", features = ["derive"] } #! ### Optional dependencies @@ -79,9 +79,6 @@ document-features = { version = "0.2", optional = true } ## ``` image = { version = "0.24", optional = true, default-features = false } -# feature "log" -log = { version = "0.4", optional = true, features = ["std"] } - # file feature mime_guess = { version = "2.0.4", optional = true, default-features = false } diff --git a/crates/egui_extras/src/lib.rs b/crates/egui_extras/src/lib.rs index 8ab0a0e9..e6448677 100644 --- a/crates/egui_extras/src/lib.rs +++ b/crates/egui_extras/src/lib.rs @@ -66,21 +66,6 @@ pub(crate) use profiling_scopes::*; // --------------------------------------------------------------------------- -/// Log an error with either `log` or `eprintln` -macro_rules! log_err { - ($fmt: literal) => {$crate::log_err!($fmt,)}; - ($fmt: literal, $($arg: tt)*) => {{ - #[cfg(feature = "log")] - log::error!($fmt, $($arg)*); - - #[cfg(not(feature = "log"))] - eprintln!( - concat!("egui_extras: ", $fmt), $($arg)* - ); - }}; -} -pub(crate) use log_err; - /// Panic in debug builds, log otherwise. macro_rules! log_or_panic { ($fmt: literal) => {$crate::log_or_panic!($fmt,)}; @@ -88,36 +73,8 @@ macro_rules! log_or_panic { if cfg!(debug_assertions) { panic!($fmt, $($arg)*); } else { - $crate::log_err!($fmt, $($arg)*); + log::error!($fmt, $($arg)*); } }}; } pub(crate) use log_or_panic; - -#[allow(unused_macros)] -macro_rules! log_warn { - ($fmt: literal) => {$crate::log_warn!($fmt,)}; - ($fmt: literal, $($arg: tt)*) => {{ - #[cfg(feature = "log")] - log::warn!($fmt, $($arg)*); - - #[cfg(not(feature = "log"))] - println!( - concat!("egui_extras: warning: ", $fmt), $($arg)* - ) - }}; -} - -#[allow(unused_imports)] -pub(crate) use log_warn; - -#[allow(unused_macros)] -macro_rules! log_trace { - ($fmt: literal) => {$crate::log_trace!($fmt,)}; - ($fmt: literal, $($arg: tt)*) => {{ - #[cfg(feature = "log")] - log::trace!($fmt, $($arg)*); - }}; -} -#[allow(unused_imports)] -pub(crate) use log_trace; diff --git a/crates/egui_extras/src/loaders.rs b/crates/egui_extras/src/loaders.rs index 59639167..4b689672 100644 --- a/crates/egui_extras/src/loaders.rs +++ b/crates/egui_extras/src/loaders.rs @@ -55,7 +55,7 @@ pub fn install(ctx: &egui::Context) { #[cfg(all(not(target_arch = "wasm32"), feature = "file"))] if !ctx.is_loader_installed(self::file_loader::FileLoader::ID) { ctx.add_bytes_loader(std::sync::Arc::new(self::file_loader::FileLoader::default())); - crate::log_trace!("installed FileLoader"); + log::trace!("installed FileLoader"); } #[cfg(feature = "http")] @@ -63,7 +63,7 @@ pub fn install(ctx: &egui::Context) { ctx.add_bytes_loader(std::sync::Arc::new( self::ehttp_loader::EhttpLoader::default(), )); - crate::log_trace!("installed EhttpLoader"); + log::trace!("installed EhttpLoader"); } #[cfg(feature = "image")] @@ -71,13 +71,13 @@ pub fn install(ctx: &egui::Context) { ctx.add_image_loader(std::sync::Arc::new( self::image_loader::ImageCrateLoader::default(), )); - crate::log_trace!("installed ImageCrateLoader"); + log::trace!("installed ImageCrateLoader"); } #[cfg(feature = "svg")] if !ctx.is_loader_installed(self::svg_loader::SvgLoader::ID) { ctx.add_image_loader(std::sync::Arc::new(self::svg_loader::SvgLoader::default())); - crate::log_trace!("installed SvgLoader"); + log::trace!("installed SvgLoader"); } #[cfg(all( @@ -86,7 +86,7 @@ pub fn install(ctx: &egui::Context) { not(feature = "image"), not(feature = "svg") ))] - crate::log_warn!("`loaders::install` was called, but no loaders are enabled"); + log::warn!("`loaders::install` was called, but no loaders are enabled"); let _ = ctx; } diff --git a/crates/egui_extras/src/loaders/ehttp_loader.rs b/crates/egui_extras/src/loaders/ehttp_loader.rs index a8c435cc..0c8f6b3b 100644 --- a/crates/egui_extras/src/loaders/ehttp_loader.rs +++ b/crates/egui_extras/src/loaders/ehttp_loader.rs @@ -76,7 +76,7 @@ impl BytesLoader for EhttpLoader { Poll::Pending => Ok(BytesPoll::Pending { size: None }), } } else { - crate::log_trace!("started loading {uri:?}"); + log::trace!("started loading {uri:?}"); let uri = uri.to_owned(); cache.insert(uri.clone(), Poll::Pending); @@ -90,11 +90,11 @@ impl BytesLoader for EhttpLoader { Ok(response) => File::from_response(&uri, response), Err(err) => { // Log details; return summary - crate::log_err!("Failed to load {uri:?}: {err}"); + log::error!("Failed to load {uri:?}: {err}"); Err(format!("Failed to load {uri:?}")) } }; - crate::log_trace!("finished loading {uri:?}"); + log::trace!("finished loading {uri:?}"); let prev = cache.lock().insert(uri, Poll::Ready(result)); assert!(matches!(prev, Some(Poll::Pending))); ctx.request_repaint(); diff --git a/crates/egui_extras/src/loaders/file_loader.rs b/crates/egui_extras/src/loaders/file_loader.rs index 5a86fe1c..2dd90717 100644 --- a/crates/egui_extras/src/loaders/file_loader.rs +++ b/crates/egui_extras/src/loaders/file_loader.rs @@ -49,7 +49,7 @@ impl BytesLoader for FileLoader { Poll::Pending => Ok(BytesPoll::Pending { size: None }), } } else { - crate::log_trace!("started loading {uri:?}"); + log::trace!("started loading {uri:?}"); // We need to load the file at `path`. // Set the file to `pending` until we finish loading it. @@ -85,7 +85,7 @@ impl BytesLoader for FileLoader { let prev = cache.lock().insert(path, Poll::Ready(result)); assert!(matches!(prev, Some(Poll::Pending))); ctx.request_repaint(); - crate::log_trace!("finished loading {_uri:?}"); + log::trace!("finished loading {_uri:?}"); } }) .expect("failed to spawn thread"); diff --git a/crates/egui_extras/src/loaders/image_loader.rs b/crates/egui_extras/src/loaders/image_loader.rs index 46098332..b9374fe4 100644 --- a/crates/egui_extras/src/loaders/image_loader.rs +++ b/crates/egui_extras/src/loaders/image_loader.rs @@ -62,9 +62,9 @@ impl ImageLoader for ImageCrateLoader { return Err(LoadError::NotSupported); } - crate::log_trace!("started loading {uri:?}"); + log::trace!("started loading {uri:?}"); let result = crate::image::load_image_bytes(&bytes).map(Arc::new); - crate::log_trace!("finished loading {uri:?}"); + log::trace!("finished loading {uri:?}"); cache.insert(uri.into(), result.clone()); match result { Ok(image) => Ok(ImagePoll::Ready { image }), diff --git a/crates/egui_extras/src/loaders/svg_loader.rs b/crates/egui_extras/src/loaders/svg_loader.rs index cb4263c7..6af69a61 100644 --- a/crates/egui_extras/src/loaders/svg_loader.rs +++ b/crates/egui_extras/src/loaders/svg_loader.rs @@ -47,7 +47,7 @@ impl ImageLoader for SvgLoader { } else { match ctx.try_load_bytes(&uri) { Ok(BytesPoll::Ready { bytes, .. }) => { - crate::log_trace!("started loading {uri:?}"); + log::trace!("started loading {uri:?}"); let fit_to = match size_hint { SizeHint::Scale(factor) => usvg::FitTo::Zoom(factor.into_inner()), SizeHint::Width(w) => usvg::FitTo::Width(w), @@ -56,7 +56,7 @@ impl ImageLoader for SvgLoader { }; let result = crate::image::load_svg_bytes_with_size(&bytes, fit_to).map(Arc::new); - crate::log_trace!("finished loading {uri:?}"); + log::trace!("finished loading {uri:?}"); cache.insert((uri, size_hint), result.clone()); match result { Ok(image) => Ok(ImagePoll::Ready { image }), diff --git a/crates/egui_extras/src/syntax_highlighting.rs b/crates/egui_extras/src/syntax_highlighting.rs index dd92e938..1bb81d13 100644 --- a/crates/egui_extras/src/syntax_highlighting.rs +++ b/crates/egui_extras/src/syntax_highlighting.rs @@ -50,9 +50,7 @@ pub fn highlight(ctx: &egui::Context, theme: &CodeTheme, code: &str, language: & // ---------------------------------------------------------------------------- #[cfg(not(feature = "syntect"))] -#[derive(Clone, Copy, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] -#[derive(enum_map::Enum)] +#[derive(Clone, Copy, PartialEq, serde::Deserialize, serde::Serialize, enum_map::Enum)] enum TokenType { Comment, Keyword, @@ -63,8 +61,7 @@ enum TokenType { } #[cfg(feature = "syntect")] -#[derive(Clone, Copy, Hash, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] +#[derive(Clone, Copy, Hash, PartialEq, serde::Deserialize, serde::Serialize)] enum SyntectTheme { Base16EightiesDark, Base16MochaDark, @@ -128,9 +125,8 @@ impl SyntectTheme { } /// A selected color theme. -#[derive(Clone, Hash, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] -#[cfg_attr(feature = "serde", serde(default))] +#[derive(Clone, Hash, PartialEq, serde::Deserialize, serde::Serialize)] +#[serde(default)] pub struct CodeTheme { dark_mode: bool, @@ -160,7 +156,6 @@ impl CodeTheme { /// Load code theme from egui memory. /// /// There is one dark and one light theme stored at any one time. - #[cfg(feature = "serde")] pub fn from_memory(ctx: &egui::Context) -> Self { if ctx.style().visuals.dark_mode { ctx.data_mut(|d| { @@ -178,7 +173,6 @@ impl CodeTheme { /// Store theme to egui memory. /// /// There is one dark and one light theme stored at any one time. - #[cfg(feature = "serde")] pub fn store_in_memory(self, ctx: &egui::Context) { if self.dark_mode { ctx.data_mut(|d| d.insert_persisted(egui::Id::new("dark"), self)); @@ -186,36 +180,6 @@ impl CodeTheme { ctx.data_mut(|d| d.insert_persisted(egui::Id::new("light"), self)); } } - - /// Load code theme from egui memory. - /// - /// There is one dark and one light theme stored at any one time. - #[cfg(not(feature = "serde"))] - pub fn from_memory(ctx: &egui::Context) -> Self { - if ctx.style().visuals.dark_mode { - ctx.data_mut(|d| { - d.get_temp(egui::Id::new("dark")) - .unwrap_or_else(CodeTheme::dark) - }) - } else { - ctx.data_mut(|d| { - d.get_temp(egui::Id::new("light")) - .unwrap_or_else(CodeTheme::light) - }) - } - } - - /// Store theme to egui memory. - /// - /// There is one dark and one light theme stored at any one time. - #[cfg(not(feature = "serde"))] - pub fn store_in_memory(self, ctx: &egui::Context) { - if self.dark_mode { - ctx.data_mut(|d| d.insert_temp(egui::Id::new("dark"), self)); - } else { - ctx.data_mut(|d| d.insert_temp(egui::Id::new("light"), self)); - } - } } #[cfg(feature = "syntect")] @@ -285,12 +249,8 @@ impl CodeTheme { pub fn ui(&mut self, ui: &mut egui::Ui) { ui.horizontal_top(|ui| { let selected_id = egui::Id::null(); - #[cfg(feature = "serde")] let mut selected_tt: TokenType = ui.data_mut(|d| *d.get_persisted_mut_or(selected_id, TokenType::Comment)); - #[cfg(not(feature = "serde"))] - let mut selected_tt: TokenType = - ui.data_mut(|d| *d.get_temp_mut_or(selected_id, TokenType::Comment)); ui.vertical(|ui| { ui.set_width(150.0); @@ -332,10 +292,7 @@ impl CodeTheme { ui.add_space(16.0); - #[cfg(feature = "serde")] ui.data_mut(|d| d.insert_persisted(selected_id, selected_tt)); - #[cfg(not(feature = "serde"))] - ui.data_mut(|d| d.insert_temp(selected_id, selected_tt)); egui::Frame::group(ui.style()) .inner_margin(egui::Vec2::splat(2.0)) diff --git a/examples/images/Cargo.toml b/examples/images/Cargo.toml index 85f68479..e6fc82e3 100644 --- a/examples/images/Cargo.toml +++ b/examples/images/Cargo.toml @@ -12,10 +12,7 @@ publish = false eframe = { path = "../../crates/eframe", features = [ "__screenshot", # __screenshot is so we can dump a screenshot using EFRAME_SCREENSHOT_TO ] } -egui_extras = { path = "../../crates/egui_extras", features = [ - "all-loaders", - "log", -] } +egui_extras = { path = "../../crates/egui_extras", features = ["all-loaders"] } env_logger = "0.10" image = { version = "0.24", default-features = false, features = [ "jpeg",