50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
//! A good way of displaying an SVG image in egui.
|
|
//!
|
|
//! Requires the dependency `egui_extras` with the `svg` feature.
|
|
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
|
|
|
use eframe::egui;
|
|
|
|
fn main() {
|
|
let options = eframe::NativeOptions {
|
|
initial_window_size: Some(egui::vec2(1000.0, 700.0)),
|
|
..Default::default()
|
|
};
|
|
eframe::run_native(
|
|
"svg example",
|
|
options,
|
|
Box::new(|_cc| Box::new(MyApp::default())),
|
|
);
|
|
}
|
|
|
|
struct MyApp {
|
|
svg_image: egui_extras::RetainedImage,
|
|
}
|
|
|
|
impl Default for MyApp {
|
|
fn default() -> Self {
|
|
Self {
|
|
svg_image: egui_extras::RetainedImage::from_svg_bytes_with_size(
|
|
"rustacean-flat-happy.svg",
|
|
include_bytes!("rustacean-flat-happy.svg"),
|
|
egui_extras::image::FitTo::Original,
|
|
)
|
|
.unwrap(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl eframe::App for MyApp {
|
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
|
ui.heading("SVG example");
|
|
ui.label("The SVG is rasterized and displayed as a texture.");
|
|
|
|
ui.separator();
|
|
|
|
let max_size = ui.available_size();
|
|
self.svg_image.show_size(ui, max_size);
|
|
});
|
|
}
|
|
}
|