Skip to content

Commit

Permalink
add AppConfig::icon to set window icon
Browse files Browse the repository at this point in the history
  • Loading branch information
jice-nospam committed Mar 30, 2023
1 parent 68b8908 commit 011db67
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "uni-app"
version = "0.4.1"
version = "0.5.0"
authors = [
"Edwin Cheng <edwin0cheng@gmail.com>",
"jice <jice.nospam@gmail.com>"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 1 addition & 0 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>)>,
/// 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
Expand All @@ -70,6 +78,7 @@ impl AppConfig {
resizable: true,
show_cursor: true,
intercept_close_request: false,
icon : None,
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/native_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -337,3 +342,4 @@ pub fn now() -> f64 {
// https://doc.rust-lang.org/time/time/fn.precise_time_s.html
time::precise_time_s()
}

0 comments on commit 011db67

Please sign in to comment.