egui: Can't set an icon properly
fn main() -> Result<()> {
let mut icon_bytes = Vec::new();
let mut img_reader = BufReader::new(File::open("asset/test.jpg")?);
img_reader.read_to_end(&mut icon_bytes)?;
let options = eframe::NativeOptions {
transparent: true,
icon_data: Some(IconData{
rgba: icon_bytes,
width: 32,
height: 32,
}),
..Default::default()
};
eframe::run_native(Box::new(HelloWorldApp::new()?), options);
}
The is no change after add icon_data to options
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 25 (2 by maintainers)
For anyone that uses Windows and wants to take the icon from the exe that they set with winres, here’s a beefy function that’s compatible with egui
build.rs
cargo.toml (note I left too many feature deps in here and this needs to be slimmed down)
load_app_icon()functionit works:
@TheMaverickProgrammer Please replace
pixel.rotate_right(1);withpixel.swap(0, 2);and see if that works. Your icon colors look right to me now after thatI probably just need to get the pixel order ironed out.
Update: eframe::epi is private. The following worked for me.
@MolotovCherry Didn’t mean to leave you hanging. I thought it was clear that you fixed the color problem before me! Thank you!
@TheMaverickProgrammer Did you define the icon like so?
res.set_icon_with_id("file.ico", "your-icon-name-here");The name you need to specify yourself. The api call can get the dimensions (you can set it to 0x0), but it may be too small to look good at that point. Probably best to just specify a size, e.g. 64x64
@TheMaverickProgrammer This is the standard toml format recommended by windows-rs and Rust https://github.com/microsoft/windows-rs#rust-for-windows https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#choosing-features