Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add icon support to eframe #193

Merged
merged 7 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions egui_glium/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ fn create_display(
initial_size_points: Option<Vec2>,
window_settings: Option<WindowSettings>,
is_resizable: bool,
window_icon: Option<glutin::window::Icon>,
event_loop: &glutin::event_loop::EventLoop<RequestRepaintEvent>,
) -> glium::Display {
let mut window_builder = glutin::window::WindowBuilder::new()
.with_decorations(true)
.with_resizable(is_resizable)
.with_title(title)
.with_window_icon(window_icon)
.with_transparent(false);

if let Some(window_settings) = &window_settings {
Expand Down Expand Up @@ -131,6 +133,17 @@ fn integration_info(
}
}

fn load_icon(icon_data: Option<epi::IconData>) -> Option<glutin::window::Icon> {
let icon_data = icon_data?;
if let Ok(icon) =
glutin::window::Icon::from_rgba(icon_data.rgba, icon_data.width, icon_data.height)
{
Some(icon)
} else {
None
}
}
phoglund marked this conversation as resolved.
Show resolved Hide resolved

/// Run an egui app
pub fn run(mut app: Box<dyn epi::App>) -> ! {
let mut storage = create_storage(app.name());
Expand All @@ -141,11 +154,13 @@ pub fn run(mut app: Box<dyn epi::App>) -> ! {

let window_settings = deserialize_window_settings(&storage);
let event_loop = glutin::event_loop::EventLoop::with_user_event();
let icon = load_icon(app.icon_data());
let display = create_display(
app.name(),
app.initial_window_size(),
window_settings,
app.is_resizable(),
icon,
&event_loop,
);

Expand Down
11 changes: 11 additions & 0 deletions epi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ pub trait App {
// NOTE: a bright gray makes the shadows of the windows look weird.
egui::Color32::from_rgb(12, 12, 12).into()
}

/// The application icon, e.g. in the Windows task bar etc.
fn icon_data(&self) -> Option<IconData> {
None
}
}

pub struct IconData {
pub rgba: Vec<u8>,
pub width: u32,
pub height: u32,
}

/// Represents the surroundings of your app.
Expand Down