1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -04:00

Merge branch 'master' into cache_galley_lines

This commit is contained in:
Hubert Głuchowski
2024-12-19 23:21:09 +01:00
committed by GitHub
138 changed files with 2386 additions and 1394 deletions

View File

@@ -55,14 +55,11 @@ serde = { workspace = true, optional = true }
[dev-dependencies]
# when running tests we always want to use the `chrono` feature
egui_demo_lib = { workspace = true, features = ["chrono"] }
rand = "0.8"
criterion.workspace = true
egui_kittest = { workspace = true, features = ["wgpu", "snapshot"] }
wgpu = { workspace = true, features = ["metal"] }
egui = { workspace = true, features = ["default_fonts"] }
rand = "0.8"
[[bench]]
name = "benchmark"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 129 B

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@@ -38,6 +38,7 @@ impl Default for Demos {
Box::<super::painting::Painting>::default(),
Box::<super::pan_zoom::PanZoom>::default(),
Box::<super::panels::Panels>::default(),
Box::<super::screenshot::Screenshot>::default(),
Box::<super::scrolling::Scrolling>::default(),
Box::<super::sliders::Sliders>::default(),
Box::<super::strip_demo::StripDemo>::default(),

View File

@@ -24,6 +24,7 @@ pub mod painting;
pub mod pan_zoom;
pub mod panels;
pub mod password;
pub mod screenshot;
pub mod scrolling;
pub mod sliders;
pub mod strip_demo;

View File

@@ -0,0 +1,84 @@
use egui::{Image, UserData, ViewportCommand, Widget};
use std::sync::Arc;
/// Showcase [`ViewportCommand::Screenshot`].
#[derive(PartialEq, Eq, Default)]
pub struct Screenshot {
image: Option<(Arc<egui::ColorImage>, egui::TextureHandle)>,
continuous: bool,
}
impl crate::Demo for Screenshot {
fn name(&self) -> &'static str {
"📷 Screenshot"
}
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
egui::Window::new(self.name())
.open(open)
.resizable(false)
.default_width(250.0)
.show(ctx, |ui| {
use crate::View as _;
self.ui(ui);
});
}
}
impl crate::View for Screenshot {
fn ui(&mut self, ui: &mut egui::Ui) {
ui.set_width(300.0);
ui.vertical_centered(|ui| {
ui.add(crate::egui_github_link_file!());
});
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing.x = 0.0;
ui.label("This demo showcases how to take screenshots via ");
ui.code("ViewportCommand::Screenshot");
ui.label(".");
});
ui.horizontal_top(|ui| {
let capture = ui.button("📷 Take Screenshot").clicked();
ui.checkbox(&mut self.continuous, "Capture continuously");
if capture || self.continuous {
ui.ctx()
.send_viewport_cmd(ViewportCommand::Screenshot(UserData::default()));
}
});
let image = ui.ctx().input(|i| {
i.events
.iter()
.filter_map(|e| {
if let egui::Event::Screenshot { image, .. } = e {
Some(image.clone())
} else {
None
}
})
.last()
});
if let Some(image) = image {
self.image = Some((
image.clone(),
ui.ctx()
.load_texture("screenshot_demo", image, Default::default()),
));
}
if let Some((_, texture)) = &self.image {
Image::new(texture).shrink_to_fit().ui(ui);
} else {
ui.group(|ui| {
ui.set_width(ui.available_width());
ui.set_height(100.0);
ui.centered_and_justified(|ui| {
ui.label("No screenshot taken yet.");
});
});
}
}
}

View File

@@ -286,6 +286,7 @@ fn doc_link_label_with_crate<'a>(
}
}
#[cfg(feature = "chrono")]
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:579a7a66f86ade628e9f469b0014e9010aa56312ad5bd1e8de2faaae7e0d1af6
size 23770