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
This commit is contained in:
parent
4986b35701
commit
35945dea46
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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`]
|
||||
///
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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()))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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…
Reference in New Issue