mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
eframe app creation refactor (#1363)
* Change how eframe apps are created * eframe: re-export epi::* so users don't need to care about what epi is
This commit is contained in:
@@ -4,41 +4,6 @@
|
||||
|
||||
use glium::glutin;
|
||||
|
||||
fn create_display(event_loop: &glutin::event_loop::EventLoop<()>) -> glium::Display {
|
||||
let window_builder = glutin::window::WindowBuilder::new()
|
||||
.with_resizable(true)
|
||||
.with_inner_size(glutin::dpi::LogicalSize {
|
||||
width: 800.0,
|
||||
height: 600.0,
|
||||
})
|
||||
.with_title("egui_glium example");
|
||||
|
||||
let context_builder = glutin::ContextBuilder::new()
|
||||
.with_depth_buffer(0)
|
||||
.with_srgb(true)
|
||||
.with_stencil_buffer(0)
|
||||
.with_vsync(true);
|
||||
|
||||
glium::Display::new(window_builder, context_builder, event_loop).unwrap()
|
||||
}
|
||||
|
||||
fn load_glium_image(png_data: &[u8]) -> glium::texture::RawImage2d<u8> {
|
||||
// Load image using the image crate:
|
||||
let image = image::load_from_memory(png_data).unwrap().to_rgba8();
|
||||
let image_dimensions = image.dimensions();
|
||||
|
||||
// Premultiply alpha:
|
||||
let pixels: Vec<_> = image
|
||||
.into_vec()
|
||||
.chunks_exact(4)
|
||||
.map(|p| egui::Color32::from_rgba_unmultiplied(p[0], p[1], p[2], p[3]))
|
||||
.flat_map(|color| color.to_array())
|
||||
.collect();
|
||||
|
||||
// Convert to glium image:
|
||||
glium::texture::RawImage2d::from_raw_rgba(pixels, image_dimensions)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let event_loop = glutin::event_loop::EventLoop::with_user_event();
|
||||
let display = create_display(&event_loop);
|
||||
@@ -127,3 +92,38 @@ fn main() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn create_display(event_loop: &glutin::event_loop::EventLoop<()>) -> glium::Display {
|
||||
let window_builder = glutin::window::WindowBuilder::new()
|
||||
.with_resizable(true)
|
||||
.with_inner_size(glutin::dpi::LogicalSize {
|
||||
width: 800.0,
|
||||
height: 600.0,
|
||||
})
|
||||
.with_title("egui_glium example");
|
||||
|
||||
let context_builder = glutin::ContextBuilder::new()
|
||||
.with_depth_buffer(0)
|
||||
.with_srgb(true)
|
||||
.with_stencil_buffer(0)
|
||||
.with_vsync(true);
|
||||
|
||||
glium::Display::new(window_builder, context_builder, event_loop).unwrap()
|
||||
}
|
||||
|
||||
fn load_glium_image(png_data: &[u8]) -> glium::texture::RawImage2d<u8> {
|
||||
// Load image using the image crate:
|
||||
let image = image::load_from_memory(png_data).unwrap().to_rgba8();
|
||||
let image_dimensions = image.dimensions();
|
||||
|
||||
// Premultiply alpha:
|
||||
let pixels: Vec<_> = image
|
||||
.into_vec()
|
||||
.chunks_exact(4)
|
||||
.map(|p| egui::Color32::from_rgba_unmultiplied(p[0], p[1], p[2], p[3]))
|
||||
.flat_map(|color| color.to_array())
|
||||
.collect();
|
||||
|
||||
// Convert to glium image:
|
||||
glium::texture::RawImage2d::from_raw_rgba(pixels, image_dimensions)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user