Skip to content

Commit

Permalink
Move icon_data module
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 19, 2023
1 parent 6d559f1 commit af2ef39
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
8 changes: 1 addition & 7 deletions crates/eframe/src/epi/mod.rs → crates/eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
#![warn(missing_docs)] // Let's keep `epi` well-documented.

#[cfg(not(target_arch = "wasm32"))]
mod icon_data;

#[cfg(not(target_arch = "wasm32"))]
pub use icon_data::IconDataExt;

#[cfg(target_arch = "wasm32")]
use std::any::Any;

Expand Down Expand Up @@ -399,7 +393,7 @@ impl Default for NativeOptions {
Self {
viewport: egui::ViewportBuilder {
icon: Some(std::sync::Arc::new(
icon_data::icon_from_png_bytes(&include_bytes!("../../data/icon.png")[..])
crate::icon_data::from_png_bytes(&include_bytes!("../data/icon.png")[..])
.unwrap(),
)),
..Default::default()
Expand Down
4 changes: 4 additions & 0 deletions crates/eframe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ mod native;
#[cfg(feature = "persistence")]
pub use native::file_storage::storage_dir;

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

/// This is how you start a native (desktop) app.
///
/// The first argument is name of your app, which is a an identifier
Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/src/native/app_icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn set_title_and_icon_mac(title: &str, icon_data: Option<&IconData>) -> AppIconS
use objc::{msg_send, sel, sel_impl};

let png_bytes = if let Some(icon_data) = icon_data {
use crate::IconDataExt as _;
use crate::icon_data::IconDataExt as _;
match icon_data.to_png_bytes() {
Ok(png_bytes) => Some(png_bytes),
Err(err) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ pub trait IconDataExt {
fn to_png_bytes(&self) -> Result<Vec<u8>, String>;
}

/// Convert into [`image::RgbaImage`]
/// Load the contents of .png file.
///
/// # Errors
/// If this is not a valid png.
pub fn icon_from_png_bytes(png_bytes: &[u8]) -> Result<IconData, image::ImageError> {
pub fn from_png_bytes(png_bytes: &[u8]) -> Result<IconData, image::ImageError> {
crate::profile_function!();
let image = image::load_from_memory(png_bytes)?;
Ok(icon_from_image(image))
Ok(from_image(image))
}

fn icon_from_image(image: image::DynamicImage) -> IconData {
fn from_image(image: image::DynamicImage) -> IconData {
let image = image.into_rgba8();
IconData {
width: image.width(),
Expand Down
2 changes: 2 additions & 0 deletions crates/eframe/src/native/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod app_icon;
mod epi_integration;
/// Helpers for loading [`egui::IconData`].
pub mod icon_data;
pub mod run;

/// File storage which can be used by native backends.
Expand Down

0 comments on commit af2ef39

Please sign in to comment.