mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
* Better cargo deny check in check.sh
* cargo update
Updating ab_glyph v0.2.16 -> v0.2.18
Updating ab_glyph_rasterizer v0.1.5 -> v0.1.7
Removing adler32 v1.2.0
Removing ahash v0.4.7
Removing ahash v0.8.1
Adding ahash v0.8.2
Updating aho-corasick v0.7.18 -> v0.7.20
Updating android_system_properties v0.1.4 -> v0.1.5
Removing ansi_term v0.12.1
Updating anyhow v1.0.62 -> v1.0.66
Updating ash v0.37.0+1.3.209 -> v0.37.1+1.3.235
Updating async-channel v1.7.1 -> v1.8.0
Updating async-executor v1.4.1 -> v1.5.0
Updating async-io v1.8.0 -> v1.12.0
Updating async-lock v2.5.0 -> v2.6.0
Updating async-recursion v0.3.2 -> v1.0.0
Updating async-trait v0.1.57 -> v0.1.59
Updating base64 v0.13.0 -> v0.13.1
Updating bindgen v0.61.0 -> v0.63.0
Adding block-buffer v0.10.3
Updating bumpalo v3.11.0 -> v3.11.1
Updating bytemuck v1.12.1 -> v1.12.3
Updating bytemuck_derive v1.2.1 -> v1.3.0
Updating bytes v1.2.1 -> v1.3.0
Removing cache-padded v1.2.0
Updating calloop v0.10.1 -> v0.10.3
Updating cc v1.0.73 -> v1.0.77
Updating cfg-expr v0.10.3 -> v0.11.0
Updating chrono v0.4.22 -> v0.4.23
Updating clang-sys v1.3.3 -> v1.4.0
Updating clap v3.2.17 -> v3.2.23
Updating cmake v0.1.48 -> v0.1.49
Updating cocoa v0.24.0 -> v0.24.1
Updating concurrent-queue v1.2.4 -> v2.0.0
Adding cpufeatures v0.2.5
Updating crossbeam-utils v0.8.11 -> v0.8.14
Updating crossfont v0.5.0 -> v0.5.1
Adding crypto-common v0.1.6
Adding cxx v1.0.83
Adding cxx-build v1.0.83
Adding cxxbridge-flags v1.0.83
Adding cxxbridge-macro v1.0.83
Updating dark-light v0.2.2 -> v0.2.3
Removing deflate v1.0.0
Adding digest v0.10.6
Updating dlv-list v0.2.3 -> v0.3.0
Updating document-features v0.2.3 -> v0.2.6
Updating flate2 v1.0.24 -> v1.0.25
Updating fontconfig-parser v0.5.0 -> v0.5.1
Updating fontdb v0.9.1 -> v0.9.3
Updating form_urlencoded v1.0.1 -> v1.1.0
Updating futures-core v0.3.23 -> v0.3.25
Updating futures-io v0.3.23 -> v0.3.25
Updating futures-sink v0.3.23 -> v0.3.25
Updating futures-task v0.3.23 -> v0.3.25
Updating futures-util v0.3.23 -> v0.3.25
Adding generic-array v0.14.6
Updating getrandom v0.2.7 -> v0.2.8
Removing hashbrown v0.9.1
Updating iana-time-zone v0.1.46 -> v0.1.53
Adding iana-time-zone-haiku v0.1.1
Updating idna v0.2.3 -> v0.3.0
Updating image v0.24.3 -> v0.24.5
Updating indexmap v1.9.1 -> v1.9.2
Updating itertools v0.10.3 -> v0.10.5
Updating itoa v1.0.3 -> v1.0.4
Adding jni v0.20.0
Updating jobserver v0.1.24 -> v0.1.25
Adding jpeg-decoder v0.3.0
Updating libc v0.2.132 -> v0.2.138
Updating libloading v0.7.3 -> v0.7.4
Updating libm v0.2.5 -> v0.2.6
Adding link-cplusplus v1.0.7
Adding litrs v0.2.3
Updating lock_api v0.4.7 -> v0.4.9
Updating memmap2 v0.5.7 -> v0.5.8
Removing miniz_oxide v0.5.3
Adding miniz_oxide v0.5.4
Adding miniz_oxide v0.6.2
Updating mio v0.8.4 -> v0.8.5
Removing nix v0.22.3
Removing nix v0.23.1
Removing nix v0.24.2
Adding nix v0.24.3
Adding nix v0.25.1
Adding nu-ansi-term v0.46.0
Removing num_threads v0.1.6
Updating once_cell v1.13.1 -> v1.16.0
Updating ordered-multimap v0.3.1 -> v0.4.3
Updating ordered-stream v0.0.1 -> v0.1.2
Updating os_str_bytes v6.3.0 -> v6.4.1
Adding overload v0.1.1
Updating owned_ttf_parser v0.15.1 -> v0.17.1
Updating parking_lot_core v0.9.3 -> v0.9.5
Updating percent-encoding v2.1.0 -> v2.2.0
Updating pkg-config v0.3.25 -> v0.3.26
Updating png v0.17.5 -> v0.17.7
Updating polling v2.2.0 -> v2.5.1
Updating ppv-lite86 v0.2.16 -> v0.2.17
Updating proc-macro2 v1.0.43 -> v1.0.47
Updating profiling v1.0.6 -> v1.0.7
Updating rand_core v0.6.3 -> v0.6.4
Updating regex v1.6.0 -> v1.7.0
Updating regex-syntax v0.6.27 -> v0.6.28
Updating rgb v0.8.33 -> v0.8.34
Adding roxmltree v0.15.1
Updating rust-ini v0.17.0 -> v0.18.0
Updating rustls v0.20.6 -> v0.20.7
Updating scoped-tls v1.0.0 -> v1.0.1
Adding scratch v1.0.2
Updating sctk-adwaita v0.4.2 -> v0.4.3
Updating serde v1.0.143 -> v1.0.149
Updating serde_derive v1.0.143 -> v1.0.149
Updating serde_json v1.0.83 -> v1.0.89
Updating sha1 v0.6.1 -> v0.10.5
Removing sha1_smol v1.0.0
Updating smallvec v1.9.0 -> v1.10.0
Updating socket2 v0.4.4 -> v0.4.7
Updating svgtypes v0.8.1 -> v0.8.2
Updating syn v1.0.99 -> v1.0.105
Removing synstructure v0.12.6
Updating system-deps v6.0.2 -> v6.0.3
Updating textwrap v0.15.0 -> v0.16.0
Updating thiserror v1.0.32 -> v1.0.37
Updating thiserror-impl v1.0.32 -> v1.0.37
Removing time v0.1.44
Removing time v0.3.13
Adding time v0.1.45
Adding time v0.3.17
Adding time-core v0.1.0
Adding time-macros v0.2.6
Updating tracing v0.1.36 -> v0.1.37
Updating tracing-attributes v0.1.22 -> v0.1.23
Updating tracing-core v0.1.29 -> v0.1.30
Updating tracing-subscriber v0.3.15 -> v0.3.16
Adding ttf-parser v0.17.1
Adding typenum v1.15.0
Updating unicode-ident v1.0.3 -> v1.0.5
Updating unicode-normalization v0.1.21 -> v0.1.22
Updating unicode-script v0.5.4 -> v0.5.5
Updating unicode-width v0.1.9 -> v0.1.10
Updating unicode-xid v0.2.3 -> v0.2.4
Updating url v2.2.2 -> v2.3.1
Updating version-compare v0.1.0 -> v0.1.1
Updating wayland-client v0.29.4 -> v0.29.5
Updating wayland-commons v0.29.4 -> v0.29.5
Updating wayland-cursor v0.29.4 -> v0.29.5
Updating wayland-egl v0.29.4 -> v0.29.5
Updating wayland-protocols v0.29.4 -> v0.29.5
Updating wayland-scanner v0.29.4 -> v0.29.5
Updating wayland-sys v0.29.4 -> v0.29.5
Updating webbrowser v0.8.0 -> v0.8.2
Updating webpki-roots v0.22.4 -> v0.22.5
Updating wgpu v0.14.0 -> v0.14.2
Updating wgpu-core v0.14.0 -> v0.14.2
Updating wgpu-hal v0.14.0 -> v0.14.1
Updating wgpu-types v0.14.0 -> v0.14.1
Updating which v4.2.5 -> v4.3.0
Updating widestring v0.5.1 -> v1.0.2
Adding windows-sys v0.42.0
Updating winreg v0.8.0 -> v0.10.1
Updating x11-dl v2.20.0 -> v2.20.1
Updating xmlparser v0.13.3 -> v0.13.5
Updating zbus v2.3.2 -> v3.6.0
Updating zbus_macros v2.3.2 -> v3.6.0
Updating zbus_names v2.2.0 -> v2.4.0
Updating zerocopy-derive v0.3.1 -> v0.3.2
Updating zstd-sys v2.0.1+zstd.1.5.2 -> v2.0.4+zstd.1.5.2
Updating zvariant v3.6.0 -> v3.9.0
Updating zvariant_derive v3.6.0 -> v3.9.0
* downgrade image, webbrowser and fontconfig-parser to pass cargo deny
avoiding duplicate crate
* Remove unused dependency on egui_extras from screenshot demo
* Downgrade `chrono` to avoid having to fix egui-extras now
109 lines
3.4 KiB
Rust
109 lines
3.4 KiB
Rust
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
|
|
|
use eframe::{
|
|
egui::{self, ColorImage},
|
|
glow::{self, HasContext},
|
|
};
|
|
use itertools::Itertools as _;
|
|
|
|
fn main() {
|
|
let options = eframe::NativeOptions::default();
|
|
eframe::run_native(
|
|
"Take screenshots and display with eframe/egui",
|
|
options,
|
|
Box::new(|_cc| Box::new(MyApp::default())),
|
|
);
|
|
}
|
|
|
|
#[derive(Default)]
|
|
struct MyApp {
|
|
continuously_take_screenshots: bool,
|
|
take_screenshot: bool,
|
|
texture: Option<egui::TextureHandle>,
|
|
screenshot: Option<ColorImage>,
|
|
}
|
|
|
|
impl eframe::App for MyApp {
|
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
|
if let Some(screenshot) = self.screenshot.take() {
|
|
self.texture = Some(ui.ctx().load_texture(
|
|
"screenshot",
|
|
screenshot,
|
|
Default::default(),
|
|
));
|
|
}
|
|
|
|
ui.horizontal(|ui| {
|
|
ui.checkbox(
|
|
&mut self.continuously_take_screenshots,
|
|
"continuously take screenshots",
|
|
);
|
|
|
|
ui.with_layout(egui::Layout::top_down(egui::Align::RIGHT), |ui| {
|
|
if self.continuously_take_screenshots {
|
|
if ui
|
|
.add(egui::Label::new("hover me!").sense(egui::Sense::hover()))
|
|
.hovered()
|
|
{
|
|
ctx.set_visuals(egui::Visuals::dark());
|
|
} else {
|
|
ctx.set_visuals(egui::Visuals::light());
|
|
};
|
|
} else if ui.button("take screenshot!").clicked() {
|
|
self.take_screenshot = true;
|
|
}
|
|
});
|
|
});
|
|
|
|
if let Some(texture) = self.texture.as_ref() {
|
|
ui.image(texture, ui.available_size());
|
|
} else {
|
|
ui.spinner();
|
|
}
|
|
|
|
ctx.request_repaint();
|
|
});
|
|
}
|
|
|
|
#[allow(unsafe_code)]
|
|
fn post_rendering(&mut self, screen_size_px: [u32; 2], frame: &eframe::Frame) {
|
|
if !self.take_screenshot && !self.continuously_take_screenshots {
|
|
return;
|
|
}
|
|
|
|
self.take_screenshot = false;
|
|
if let Some(gl) = frame.gl() {
|
|
let [w, h] = screen_size_px;
|
|
let mut buf = vec![0u8; w as usize * h as usize * 4];
|
|
let pixels = glow::PixelPackData::Slice(&mut buf[..]);
|
|
unsafe {
|
|
gl.read_pixels(
|
|
0,
|
|
0,
|
|
w as i32,
|
|
h as i32,
|
|
glow::RGBA,
|
|
glow::UNSIGNED_BYTE,
|
|
pixels,
|
|
);
|
|
}
|
|
|
|
// Flip vertically:
|
|
let mut rows: Vec<Vec<u8>> = buf
|
|
.into_iter()
|
|
.chunks(w as usize * 4)
|
|
.into_iter()
|
|
.map(|chunk| chunk.collect())
|
|
.collect();
|
|
rows.reverse();
|
|
let buf: Vec<u8> = rows.into_iter().flatten().collect();
|
|
|
|
self.screenshot = Some(ColorImage::from_rgba_unmultiplied(
|
|
[screen_size_px[0] as usize, screen_size_px[1] as usize],
|
|
&buf[..],
|
|
));
|
|
}
|
|
}
|
|
}
|