diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b23c21..26c487e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [0.5.0] - 2023-03-30 +### Added +- on native target, you can set the window icon with AppConfig.icon + ## [0.4.1] - 2023-02-17 ### Fixed - scancodes for F11 and F12 (windows & linux) diff --git a/Cargo.toml b/Cargo.toml index 1030ae4..c3f944e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uni-app" -version = "0.4.1" +version = "0.5.0" authors = [ "Edwin Cheng ", "jice " diff --git a/README.md b/README.md index 0c21636..cd7b838 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ fn main() { headless: false, resizable: true, fullscreen: false, + intercept_close_request: false, + icon: None, }); // start game loop app.run(move |app: &mut uni_app::App| { diff --git a/examples/Cargo.toml b/examples/Cargo.toml index ffc9da3..ef6c97c 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uni-app-example" -version = "0.4.1" +version = "0.5.0" edition = "2021" license = "MIT" repository = "https://github.com/unrust/uni-app" diff --git a/examples/basic.rs b/examples/basic.rs index 1e3a8fd..c25853e 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -22,6 +22,7 @@ fn main() { resizable: true, fullscreen: false, intercept_close_request: false, + icon: None, }); // loading a file // if the "http" feature is enabled, this would also work with an url like "https://raw.githubusercontent.com/unrust/uni-app/master/www/test.txt" diff --git a/src/lib.rs b/src/lib.rs index df38671..d2cc760 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,6 +45,14 @@ pub struct AppConfig { pub title: String, /// the window/canvas size in pixels pub size: (u32, u32), + /// The window icon : width,height,pixel data in rgba format. + /// winit recommends using a 32x32 image. + /// You can use the image crate to embed the icon in your executable at build time : + /// + /// pub static ICON: &[u8] = include_bytes!("my_icon.png"); + /// let icon=image::load_from_memory(ICON).unwrap(); + /// app_config.icon = Some((icon.width(),icon.height(),icon.as_bytes().to_vec())) + pub icon: Option<(u32,u32,Vec)>, /// sync frames with screen frequency (can only be disabled on native target) pub vsync: bool, /// start the program without actually creating a window, for test purposes @@ -70,6 +78,7 @@ impl AppConfig { resizable: true, show_cursor: true, intercept_close_request: false, + icon : None, } } } diff --git a/src/native_app.rs b/src/native_app.rs index 0a26ee5..eac46f6 100644 --- a/src/native_app.rs +++ b/src/native_app.rs @@ -175,7 +175,12 @@ impl App { None }) .with_resizable(config.resizable) - .with_inner_size(LogicalSize::new(config.size.0, config.size.1)); + .with_inner_size(LogicalSize::new(config.size.0, config.size.1)) + .with_window_icon( + if let Some((w,h,data)) = config.icon { + window::Icon::from_rgba(data, w, h).ok() + } else { None } + ); let windowed_context = ContextBuilder::new() .with_vsync(config.vsync) @@ -337,3 +342,4 @@ pub fn now() -> f64 { // https://doc.rust-lang.org/time/time/fn.precise_time_s.html time::precise_time_s() } +