From 01ee23c1a0ec4d8ac375f94a078391fca93f3461 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 8 Sep 2025 18:27:28 +0200 Subject: [PATCH] Add Zoom Factor to options panel (#7517) --- crates/egui/src/data/output.rs | 9 ++------- crates/egui/src/memory/mod.rs | 7 ++++++- crates/egui_demo_app/src/wrap_app.rs | 9 ++------- crates/egui_demo_lib/src/demo/scrolling.rs | 9 ++------- .../egui_demo_lib/src/easy_mark/easy_mark_highlighter.rs | 2 +- crates/epaint/src/stats.rs | 9 ++------- 6 files changed, 15 insertions(+), 30 deletions(-) diff --git a/crates/egui/src/data/output.rs b/crates/egui/src/data/output.rs index 0a658965..58153c8f 100644 --- a/crates/egui/src/data/output.rs +++ b/crates/egui/src/data/output.rs @@ -294,10 +294,11 @@ pub enum UserAttentionType { /// egui emits a [`CursorIcon`] in [`PlatformOutput`] each frame as a request to the integration. /// /// Loosely based on . -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub enum CursorIcon { /// Normal cursor icon, whatever that is. + #[default] Default, /// Show no cursor @@ -457,12 +458,6 @@ impl CursorIcon { ]; } -impl Default for CursorIcon { - fn default() -> Self { - Self::Default - } -} - /// Things that happened during this frame that the integration may be interested in. /// /// In particular, these events may be useful for accessibility, i.e. for screen readers. diff --git a/crates/egui/src/memory/mod.rs b/crates/egui/src/memory/mod.rs index 904d24c0..eaf54352 100644 --- a/crates/egui/src/memory/mod.rs +++ b/crates/egui/src/memory/mod.rs @@ -357,7 +357,7 @@ impl Options { theme_preference, fallback_theme: _, system_theme: _, - zoom_factor: _, // TODO(emilk) + zoom_factor, zoom_with_keyboard, tessellation_options, repaint_on_widget_change, @@ -384,6 +384,11 @@ impl Options { "Repaint if any widget moves or changes id", ); + ui.horizontal(|ui| { + ui.label("Zoom factor:"); + ui.add(crate::DragValue::new(zoom_factor).range(0.10..=10.0)); + }); + ui.checkbox( zoom_with_keyboard, "Zoom with keyboard (Cmd +, Cmd -, Cmd 0)", diff --git a/crates/egui_demo_app/src/wrap_app.rs b/crates/egui_demo_app/src/wrap_app.rs index 3775d93d..eb901010 100644 --- a/crates/egui_demo_app/src/wrap_app.rs +++ b/crates/egui_demo_app/src/wrap_app.rs @@ -80,9 +80,10 @@ impl eframe::App for ColorTestApp { } } -#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub enum Anchor { + #[default] Demo, EasyMarkEditor, @@ -138,12 +139,6 @@ impl From for egui::WidgetText { } } -impl Default for Anchor { - fn default() -> Self { - Self::Demo - } -} - // ---------------------------------------------------------------------------- #[derive(Clone, Copy, Debug)] diff --git a/crates/egui_demo_lib/src/demo/scrolling.rs b/crates/egui_demo_lib/src/demo/scrolling.rs index 63fc81db..8c1250a9 100644 --- a/crates/egui_demo_lib/src/demo/scrolling.rs +++ b/crates/egui_demo_lib/src/demo/scrolling.rs @@ -4,8 +4,9 @@ use egui::{ }; #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, Default, PartialEq)] enum ScrollDemo { + #[default] ScrollAppearance, ScrollTo, ManyLines, @@ -14,12 +15,6 @@ enum ScrollDemo { Bidirectional, } -impl Default for ScrollDemo { - fn default() -> Self { - Self::ScrollAppearance - } -} - #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", serde(default))] #[derive(Default, PartialEq)] diff --git a/crates/egui_demo_lib/src/easy_mark/easy_mark_highlighter.rs b/crates/egui_demo_lib/src/easy_mark/easy_mark_highlighter.rs index 5c6bc2ef..8ed3eb38 100644 --- a/crates/egui_demo_lib/src/easy_mark/easy_mark_highlighter.rs +++ b/crates/egui_demo_lib/src/easy_mark/easy_mark_highlighter.rs @@ -108,7 +108,7 @@ pub fn highlight_easymark(egui_style: &egui::Style, mut text: &str) -> egui::tex // Swallow everything up to the next special character: let line_end = text[skip..] .find('\n') - .map_or_else(|| text.len(), |i| (skip + i + 1)); + .map_or_else(|| text.len(), |i| skip + i + 1); let end = text[skip..] .find(&['*', '`', '~', '_', '/', '$', '^', '\\', '<', '['][..]) .map_or_else(|| text.len(), |i| (skip + i).max(1)); diff --git a/crates/epaint/src/stats.rs b/crates/epaint/src/stats.rs index 2acf1e93..1eef4f44 100644 --- a/crates/epaint/src/stats.rs +++ b/crates/epaint/src/stats.rs @@ -3,19 +3,14 @@ use crate::{ClippedShape, Galley, Mesh, Primitive, Shape}; /// Size of the elements in a vector/array. -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, Default, PartialEq)] enum ElementSize { + #[default] Unknown, Homogeneous(usize), Heterogenous, } -impl Default for ElementSize { - fn default() -> Self { - Self::Unknown - } -} - /// Aggregate information about a bunch of allocations. #[derive(Clone, Copy, Default, PartialEq)] pub struct AllocInfo {