Browse Source

Misc code cleanup (#3398)

* eframe README: explain how to enable copy/paste

* Implement Debug for a couple of structs

* Code cleanup

* Better docs

* profile ron serialization

* CI: Allow "exclude from changelog" as the only label
pull/3400/head
Emil Ernerfeldt 1 year ago
committed by GitHub
parent
commit
35945dea46
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .github/workflows/labels.yml
  2. 1
      crates/eframe/README.md
  3. 9
      crates/eframe/src/epi/icon_data.rs
  4. 1
      crates/eframe/src/epi/mod.rs
  5. 1
      crates/eframe/src/native/file_storage.rs
  6. 10
      crates/egui-wgpu/src/lib.rs
  7. 13
      crates/egui/src/load.rs
  8. 1
      crates/egui_demo_app/src/wrap_app.rs
  9. 2
      crates/epaint/src/shape.rs
  10. 14
      crates/epaint/src/text/font.rs

2
.github/workflows/labels.yml

@ -29,4 +29,4 @@ jobs:
with:
mode: minimum
count: 1
labels: "CI, dependencies, docs and examples, ecolor, eframe, egui_extras, egui_glow, egui_plot, egui-wgpu, egui-winit, egui, epaint, typo"
labels: "CI, dependencies, docs and examples, ecolor, eframe, egui_extras, egui_glow, egui_plot, egui-wgpu, egui-winit, egui, epaint, exclude from changelog, typo"

1
crates/eframe/README.md

@ -28,6 +28,7 @@ You need to either use `edition = "2021"`, or set `resolver = "2"` in the `[work
You can opt-in to the using [`egui_wgpu`](https://github.com/emilk/egui/tree/master/crates/egui_wgpu) for rendering by enabling the `wgpu` feature and setting `NativeOptions::renderer` to `Renderer::Wgpu`.
To get copy-paste working on web, you need to compile with `export RUSTFLAGS=--cfg=web_sys_unstable_apis`.
## Alternatives
`eframe` is not the only way to write an app using `egui`! You can also try [`egui-miniquad`](https://github.com/not-fl3/egui-miniquad), [`bevy_egui`](https://github.com/mvlabat/bevy_egui), [`egui_sdl2_gl`](https://github.com/ArjunNair/egui_sdl2_gl), and others.

9
crates/eframe/src/epi/icon_data.rs

@ -14,6 +14,15 @@ pub struct IconData {
pub height: u32,
}
impl std::fmt::Debug for IconData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("IconData")
.field("width", &self.width)
.field("height", &self.height)
.finish_non_exhaustive()
}
}
impl IconData {
/// Convert into [`image::RgbaImage`]
///

1
crates/eframe/src/epi/mod.rs

@ -308,6 +308,7 @@ pub struct NativeOptions {
pub resizable: bool,
/// On desktop: make the window transparent.
///
/// You control the transparency with [`App::clear_color()`].
/// You should avoid having a [`egui::CentralPanel`], or make sure its frame is also transparent.
pub transparent: bool,

1
crates/eframe/src/native/file_storage.rs

@ -130,6 +130,7 @@ fn save_to_disk(file_path: &PathBuf, kv: &HashMap<String, String>) {
let mut writer = std::io::BufWriter::new(file);
let config = Default::default();
crate::profile_scope!("ron::serialize");
if let Err(err) = ron::ser::to_writer_pretty(&mut writer, &kv, config)
.and_then(|_| writer.flush().map_err(|err| err.into()))
{

10
crates/egui-wgpu/src/lib.rs

@ -123,6 +123,16 @@ pub struct WgpuConfiguration {
pub on_surface_error: Arc<dyn Fn(wgpu::SurfaceError) -> SurfaceErrorAction>,
}
impl std::fmt::Debug for WgpuConfiguration {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("WgpuConfiguration")
.field("supported_backends", &self.supported_backends)
.field("present_mode", &self.present_mode)
.field("power_preference", &self.power_preference)
.finish_non_exhaustive()
}
}
impl Default for WgpuConfiguration {
fn default() -> Self {
Self {

13
crates/egui/src/load.rs

@ -55,17 +55,20 @@
mod bytes_loader;
mod texture_loader;
use crate::Context;
use std::borrow::Cow;
use std::fmt::Debug;
use std::ops::Deref;
use std::{error::Error as StdError, fmt::Display, sync::Arc};
use ahash::HashMap;
use epaint::mutex::Mutex;
use epaint::util::FloatOrd;
use epaint::util::OrderedFloat;
use epaint::TextureHandle;
use epaint::{textures::TextureOptions, ColorImage, TextureId, Vec2};
use std::borrow::Cow;
use std::fmt::Debug;
use std::ops::Deref;
use std::{error::Error as StdError, fmt::Display, sync::Arc};
use crate::Context;
pub use self::bytes_loader::DefaultBytesLoader;
pub use self::texture_loader::DefaultTextureLoader;

1
crates/egui_demo_app/src/wrap_app.rs

@ -165,6 +165,7 @@ pub struct WrapApp {
impl WrapApp {
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
// This gives us image support:
egui_extras::install_image_loaders(&cc.egui_ctx);
#[allow(unused_mut)]

2
crates/epaint/src/shape.rs

@ -498,6 +498,8 @@ pub struct RectShape {
///
/// To display a texture, set [`Self::fill_texture_id`],
/// and set this to `Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0))`.
///
/// Use [`Rect::ZERO`] to turn off texturing.
pub uv: Rect,
}

14
crates/epaint/src/text/font.rs

@ -72,7 +72,7 @@ pub struct FontImpl {
height_in_points: f32,
// move each character by this much (hack)
y_offset: f32,
y_offset_in_points: f32,
ascent: f32,
pixels_per_point: f32,
@ -111,22 +111,23 @@ impl FontImpl {
scale_in_points * tweak.y_offset_factor
} + tweak.y_offset;
// center scaled glyphs properly
let y_offset_points = y_offset_points + (tweak.scale - 1.0) * 0.5 * (ascent + descent);
// Center scaled glyphs properly:
let height = ascent + descent;
let y_offset_points = y_offset_points - (1.0 - tweak.scale) * 0.5 * height;
// Round to an even number of physical pixels to get even kerning.
// See https://github.com/emilk/egui/issues/382
let scale_in_pixels = scale_in_pixels.round() as u32;
// Round to closest pixel:
let y_offset = (y_offset_points * pixels_per_point).round() / pixels_per_point;
let y_offset_in_points = (y_offset_points * pixels_per_point).round() / pixels_per_point;
Self {
name,
ab_glyph_font,
scale_in_pixels,
height_in_points: ascent - descent + line_gap,
y_offset,
y_offset_in_points,
ascent: ascent + baseline_offset,
pixels_per_point,
glyph_info_cache: Default::default(),
@ -283,7 +284,8 @@ impl FontImpl {
});
let offset_in_pixels = vec2(bb.min.x, bb.min.y);
let offset = offset_in_pixels / self.pixels_per_point + self.y_offset * Vec2::Y;
let offset =
offset_in_pixels / self.pixels_per_point + self.y_offset_in_points * Vec2::Y;
UvRect {
offset,
size: vec2(glyph_width as f32, glyph_height as f32) / self.pixels_per_point,

Loading…
Cancel
Save