mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Introduce global zoom_factor (#3608)
* Closes https://github.com/emilk/egui/issues/3602 You can now zoom any egui app by pressing Cmd+Plus, Cmd+Minus or Cmd+0, just like in a browser. This will change the current `zoom_factor` (default 1.0) which is persisted in the egui memory, and is the same for all viewports. You can turn off the keyboard shortcuts with `ctx.options_mut(|o| o.zoom_with_keyboard = false);` `zoom_factor` can also be explicitly read/written with `ctx.zoom_factor()` and `ctx.set_zoom_factor()`. This redefines `pixels_per_point` as `zoom_factor * native_pixels_per_point`, where `native_pixels_per_point` is whatever is the native scale factor for the monitor that the current viewport is in. This adds some complexity to the interaction with winit, since we need to know the current `zoom_factor` in a lot of places, because all egui IO is done in ui points. I'm pretty sure this PR fixes a bunch of subtle bugs though that used to be in this code. `egui::gui_zoom::zoom_with_keyboard_shortcuts` is now gone, and is no longer needed, as this is now the default behavior. `Context::set_pixels_per_point` is still there, but it is recommended you use `Context::set_zoom_factor` instead.
This commit is contained in:
@@ -200,6 +200,9 @@ struct ContextImpl {
|
||||
animation_manager: AnimationManager,
|
||||
tex_manager: WrappedTextureManager,
|
||||
|
||||
/// Set during the frame, becomes active at the start of the next frame.
|
||||
new_zoom_factor: Option<f32>,
|
||||
|
||||
os: OperatingSystem,
|
||||
|
||||
/// How deeply nested are we?
|
||||
@@ -234,6 +237,8 @@ impl ContextImpl {
|
||||
.and_then(|v| v.parent)
|
||||
.unwrap_or_default();
|
||||
let ids = ViewportIdPair::from_self_and_parent(viewport_id, parent_id);
|
||||
|
||||
let is_outermost_viewport = self.viewport_stack.is_empty(); // not necessarily root, just outermost immediate viewport
|
||||
self.viewport_stack.push(ids);
|
||||
let viewport = self.viewports.entry(viewport_id).or_default();
|
||||
|
||||
@@ -252,19 +257,26 @@ impl ContextImpl {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(new_pixels_per_point) = self.memory.override_pixels_per_point {
|
||||
if viewport.input.pixels_per_point != new_pixels_per_point {
|
||||
new_raw_input.pixels_per_point = Some(new_pixels_per_point);
|
||||
if is_outermost_viewport {
|
||||
if let Some(new_zoom_factor) = self.new_zoom_factor.take() {
|
||||
let ratio = self.memory.options.zoom_factor / new_zoom_factor;
|
||||
self.memory.options.zoom_factor = new_zoom_factor;
|
||||
|
||||
let input = &viewport.input;
|
||||
// This is a bit hacky, but is required to avoid jitter:
|
||||
let ratio = input.pixels_per_point / new_pixels_per_point;
|
||||
let mut rect = input.screen_rect;
|
||||
rect.min = (ratio * rect.min.to_vec2()).to_pos2();
|
||||
rect.max = (ratio * rect.max.to_vec2()).to_pos2();
|
||||
new_raw_input.screen_rect = Some(rect);
|
||||
// We should really scale everything else in the input too,
|
||||
// but the `screen_rect` is the most important part.
|
||||
}
|
||||
}
|
||||
let pixels_per_point = self.memory.options.zoom_factor
|
||||
* new_raw_input
|
||||
.viewport()
|
||||
.native_pixels_per_point
|
||||
.unwrap_or(1.0);
|
||||
|
||||
viewport.layer_rects_prev_frame = std::mem::take(&mut viewport.layer_rects_this_frame);
|
||||
|
||||
@@ -275,8 +287,11 @@ impl ContextImpl {
|
||||
self.memory
|
||||
.begin_frame(&viewport.input, &new_raw_input, &all_viewport_ids);
|
||||
|
||||
viewport.input = std::mem::take(&mut viewport.input)
|
||||
.begin_frame(new_raw_input, viewport.repaint.requested_last_frame);
|
||||
viewport.input = std::mem::take(&mut viewport.input).begin_frame(
|
||||
new_raw_input,
|
||||
viewport.repaint.requested_last_frame,
|
||||
pixels_per_point,
|
||||
);
|
||||
|
||||
viewport.frame_state.begin_frame(&viewport.input);
|
||||
|
||||
@@ -469,13 +484,11 @@ impl std::cmp::PartialEq for Context {
|
||||
|
||||
impl Default for Context {
|
||||
fn default() -> Self {
|
||||
let s = Self(Arc::new(RwLock::new(ContextImpl::default())));
|
||||
|
||||
s.write(|ctx| {
|
||||
ctx.embed_viewports = true;
|
||||
});
|
||||
|
||||
s
|
||||
let ctx = ContextImpl {
|
||||
embed_viewports: true,
|
||||
..Default::default()
|
||||
};
|
||||
Self(Arc::new(RwLock::new(ctx)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1338,44 +1351,85 @@ impl Context {
|
||||
}
|
||||
|
||||
/// The number of physical pixels for each logical point.
|
||||
///
|
||||
/// This is calculated as [`Self::zoom_factor`] * [`Self::native_pixels_per_point`]
|
||||
#[inline(always)]
|
||||
pub fn pixels_per_point(&self) -> f32 {
|
||||
self.input(|i| i.pixels_per_point())
|
||||
self.input(|i| i.pixels_per_point)
|
||||
}
|
||||
|
||||
/// Set the number of physical pixels for each logical point.
|
||||
/// Will become active at the start of the next frame.
|
||||
///
|
||||
/// Note that this may be overwritten by input from the integration via [`RawInput::pixels_per_point`].
|
||||
/// For instance, when using `eframe` on web, the browsers native zoom level will always be used.
|
||||
/// This will actually translate to a call to [`Self::set_zoom_factor`].
|
||||
pub fn set_pixels_per_point(&self, pixels_per_point: f32) {
|
||||
if pixels_per_point != self.pixels_per_point() {
|
||||
self.write(|ctx| {
|
||||
ctx.memory.override_pixels_per_point = Some(pixels_per_point);
|
||||
for id in ctx.all_viewport_ids() {
|
||||
ctx.request_repaint(id);
|
||||
}
|
||||
});
|
||||
self.set_zoom_factor(pixels_per_point / self.native_pixels_per_point().unwrap_or(1.0));
|
||||
}
|
||||
}
|
||||
|
||||
/// The number of physical pixels for each logical point on this monitor.
|
||||
///
|
||||
/// This is given as input to egui via [`ViewportInfo::native_pixels_per_point`]
|
||||
/// and cannot be changed.
|
||||
#[inline(always)]
|
||||
pub fn native_pixels_per_point(&self) -> Option<f32> {
|
||||
self.input(|i| i.viewport().native_pixels_per_point)
|
||||
}
|
||||
|
||||
/// Global zoom factor of the UI.
|
||||
///
|
||||
/// This is used to calculate the `pixels_per_point`
|
||||
/// for the UI as `pixels_per_point = zoom_fator * native_pixels_per_point`.
|
||||
///
|
||||
/// The default is 1.0.
|
||||
/// Make larger to make everything larger.
|
||||
#[inline(always)]
|
||||
pub fn zoom_factor(&self) -> f32 {
|
||||
self.options(|o| o.zoom_factor)
|
||||
}
|
||||
|
||||
/// Sets zoom factor of the UI.
|
||||
/// Will become active at the start of the next frame.
|
||||
///
|
||||
/// This is used to calculate the `pixels_per_point`
|
||||
/// for the UI as `pixels_per_point = zoom_fator * native_pixels_per_point`.
|
||||
///
|
||||
/// The default is 1.0.
|
||||
/// Make larger to make everything larger.
|
||||
#[inline(always)]
|
||||
pub fn set_zoom_factor(&self, zoom_factor: f32) {
|
||||
self.write(|ctx| {
|
||||
if ctx.memory.options.zoom_factor != zoom_factor {
|
||||
ctx.new_zoom_factor = Some(zoom_factor);
|
||||
for id in ctx.all_viewport_ids() {
|
||||
ctx.request_repaint(id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Useful for pixel-perfect rendering
|
||||
#[inline]
|
||||
pub(crate) fn round_to_pixel(&self, point: f32) -> f32 {
|
||||
let pixels_per_point = self.pixels_per_point();
|
||||
(point * pixels_per_point).round() / pixels_per_point
|
||||
}
|
||||
|
||||
/// Useful for pixel-perfect rendering
|
||||
#[inline]
|
||||
pub(crate) fn round_pos_to_pixels(&self, pos: Pos2) -> Pos2 {
|
||||
pos2(self.round_to_pixel(pos.x), self.round_to_pixel(pos.y))
|
||||
}
|
||||
|
||||
/// Useful for pixel-perfect rendering
|
||||
#[inline]
|
||||
pub(crate) fn round_vec_to_pixels(&self, vec: Vec2) -> Vec2 {
|
||||
vec2(self.round_to_pixel(vec.x), self.round_to_pixel(vec.y))
|
||||
}
|
||||
|
||||
/// Useful for pixel-perfect rendering
|
||||
#[inline]
|
||||
pub(crate) fn round_rect_to_pixels(&self, rect: Rect) -> Rect {
|
||||
Rect {
|
||||
min: self.round_pos_to_pixels(rect.min),
|
||||
@@ -1496,6 +1550,11 @@ impl Context {
|
||||
#[must_use]
|
||||
pub fn end_frame(&self) -> FullOutput {
|
||||
crate::profile_function!();
|
||||
|
||||
if self.options(|o| o.zoom_with_keyboard) {
|
||||
crate::gui_zoom::zoom_with_keyboard(self);
|
||||
}
|
||||
|
||||
self.write(|ctx| ctx.end_frame())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,10 @@ use crate::{emath::*, ViewportId, ViewportIdMap};
|
||||
/// You can check if `egui` is using the inputs using
|
||||
/// [`crate::Context::wants_pointer_input`] and [`crate::Context::wants_keyboard_input`].
|
||||
///
|
||||
/// All coordinates are in points (logical pixels) with origin (0, 0) in the top left corner.
|
||||
/// All coordinates are in points (logical pixels) with origin (0, 0) in the top left .corner.
|
||||
///
|
||||
/// Ii "points" can be calculated from native physical pixels
|
||||
/// using `pixels_per_point` = [`crate::Context::zoom_factor`] * `native_pixels_per_point`;
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||
pub struct RawInput {
|
||||
@@ -31,20 +34,6 @@ pub struct RawInput {
|
||||
/// `None` will be treated as "same as last frame", with the default being a very big area.
|
||||
pub screen_rect: Option<Rect>,
|
||||
|
||||
/// Also known as device pixel ratio, > 1 for high resolution screens.
|
||||
///
|
||||
/// If text looks blurry you probably forgot to set this.
|
||||
/// Set this the first frame, whenever it changes, or just on every frame.
|
||||
pub pixels_per_point: Option<f32>,
|
||||
|
||||
/// The OS native pixels-per-point.
|
||||
///
|
||||
/// This should always be set, if known.
|
||||
///
|
||||
/// On web this takes browser scaling into account,
|
||||
/// and orresponds to [`window.devicePixelRatio`](https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio) in JavaScript.
|
||||
pub native_pixels_per_point: Option<f32>,
|
||||
|
||||
/// Maximum size of one side of the font texture.
|
||||
///
|
||||
/// Ask your graphics drivers about this. This corresponds to `GL_MAX_TEXTURE_SIZE`.
|
||||
@@ -89,11 +78,9 @@ pub struct RawInput {
|
||||
impl Default for RawInput {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
viewport_id: Default::default(),
|
||||
viewports: Default::default(),
|
||||
viewport_id: ViewportId::ROOT,
|
||||
viewports: std::iter::once((ViewportId::ROOT, Default::default())).collect(),
|
||||
screen_rect: None,
|
||||
pixels_per_point: None,
|
||||
native_pixels_per_point: None,
|
||||
max_texture_side: None,
|
||||
time: None,
|
||||
predicted_dt: 1.0 / 60.0,
|
||||
@@ -122,8 +109,6 @@ impl RawInput {
|
||||
viewport_id: self.viewport_id,
|
||||
viewports: self.viewports.clone(),
|
||||
screen_rect: self.screen_rect.take(),
|
||||
pixels_per_point: self.pixels_per_point.take(), // take the diff
|
||||
native_pixels_per_point: self.native_pixels_per_point, // copy
|
||||
max_texture_side: self.max_texture_side.take(),
|
||||
time: self.time.take(),
|
||||
predicted_dt: self.predicted_dt,
|
||||
@@ -141,8 +126,6 @@ impl RawInput {
|
||||
viewport_id: viewport_ids,
|
||||
viewports,
|
||||
screen_rect,
|
||||
pixels_per_point,
|
||||
native_pixels_per_point,
|
||||
max_texture_side,
|
||||
time,
|
||||
predicted_dt,
|
||||
@@ -156,8 +139,6 @@ impl RawInput {
|
||||
self.viewport_id = viewport_ids;
|
||||
self.viewports = viewports;
|
||||
self.screen_rect = screen_rect.or(self.screen_rect);
|
||||
self.pixels_per_point = pixels_per_point.or(self.pixels_per_point);
|
||||
self.native_pixels_per_point = native_pixels_per_point.or(self.native_pixels_per_point);
|
||||
self.max_texture_side = max_texture_side.or(self.max_texture_side);
|
||||
self.time = time; // use latest time
|
||||
self.predicted_dt = predicted_dt; // use latest dt
|
||||
@@ -181,10 +162,12 @@ pub enum ViewportEvent {
|
||||
Close,
|
||||
}
|
||||
|
||||
/// Information about the current viewport,
|
||||
/// given as input each frame.
|
||||
/// Information about the current viewport, given as input each frame.
|
||||
///
|
||||
/// `None` means "unknown".
|
||||
///
|
||||
/// All units are in ui "points", which can be calculated from native physical pixels
|
||||
/// using `pixels_per_point` = [`crate::Context::zoom_factor`] * `[Self::native_pixels_per_point`];
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||
pub struct ViewportInfo {
|
||||
@@ -196,8 +179,13 @@ pub struct ViewportInfo {
|
||||
|
||||
pub events: Vec<ViewportEvent>,
|
||||
|
||||
/// Number of physical pixels per ui point.
|
||||
pub pixels_per_point: f32,
|
||||
/// The OS native pixels-per-point.
|
||||
///
|
||||
/// This should always be set, if known.
|
||||
///
|
||||
/// On web this takes browser scaling into account,
|
||||
/// and orresponds to [`window.devicePixelRatio`](https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio) in JavaScript.
|
||||
pub native_pixels_per_point: Option<f32>,
|
||||
|
||||
/// Current monitor size in egui points.
|
||||
pub monitor_size: Option<Vec2>,
|
||||
@@ -239,7 +227,7 @@ impl ViewportInfo {
|
||||
parent,
|
||||
title,
|
||||
events,
|
||||
pixels_per_point,
|
||||
native_pixels_per_point,
|
||||
monitor_size,
|
||||
inner_rect,
|
||||
outer_rect,
|
||||
@@ -262,8 +250,8 @@ impl ViewportInfo {
|
||||
ui.label(format!("{events:?}"));
|
||||
ui.end_row();
|
||||
|
||||
ui.label("Pixels per point:");
|
||||
ui.label(pixels_per_point.to_string());
|
||||
ui.label("Native pixels-per-point:");
|
||||
ui.label(opt_as_str(native_pixels_per_point));
|
||||
ui.end_row();
|
||||
|
||||
ui.label("Monitor size:");
|
||||
@@ -1115,8 +1103,6 @@ impl RawInput {
|
||||
viewport_id,
|
||||
viewports,
|
||||
screen_rect,
|
||||
pixels_per_point,
|
||||
native_pixels_per_point,
|
||||
max_texture_side,
|
||||
time,
|
||||
predicted_dt,
|
||||
@@ -1137,16 +1123,7 @@ impl RawInput {
|
||||
});
|
||||
}
|
||||
ui.label(format!("screen_rect: {screen_rect:?} points"));
|
||||
ui.label(format!("pixels_per_point: {pixels_per_point:?}"))
|
||||
.on_hover_text(
|
||||
"Also called HDPI factor.\nNumber of physical pixels per each logical pixel.",
|
||||
);
|
||||
ui.label(format!(
|
||||
"native_pixels_per_point: {native_pixels_per_point:?}"
|
||||
))
|
||||
.on_hover_text(
|
||||
"Also called HDPI factor.\nNumber of physical pixels per each logical pixel.",
|
||||
);
|
||||
|
||||
ui.label(format!("max_texture_side: {max_texture_side:?}"));
|
||||
if let Some(time) = time {
|
||||
ui.label(format!("time: {time:.3} s"));
|
||||
|
||||
@@ -12,20 +12,14 @@ pub mod kb_shortcuts {
|
||||
pub const ZOOM_RESET: KeyboardShortcut = KeyboardShortcut::new(Modifiers::COMMAND, Key::Num0);
|
||||
}
|
||||
|
||||
/// Let the user scale the GUI (change `Context::pixels_per_point`) by pressing
|
||||
/// Let the user scale the GUI (change [`Context::zoom_factor`]) by pressing
|
||||
/// Cmd+Plus, Cmd+Minus or Cmd+0, just like in a browser.
|
||||
///
|
||||
/// ```
|
||||
/// # let ctx = &egui::Context::default();
|
||||
/// // On web, the browser controls the gui zoom.
|
||||
/// #[cfg(not(target_arch = "wasm32"))]
|
||||
/// egui::gui_zoom::zoom_with_keyboard_shortcuts(ctx);
|
||||
/// ```
|
||||
pub fn zoom_with_keyboard_shortcuts(ctx: &Context) {
|
||||
/// By default, [`crate::Context`] calls this function at the end of each frame,
|
||||
/// controllable by [`crate::Options::zoom_with_keyboard`].
|
||||
pub(crate) fn zoom_with_keyboard(ctx: &Context) {
|
||||
if ctx.input_mut(|i| i.consume_shortcut(&kb_shortcuts::ZOOM_RESET)) {
|
||||
if let Some(native_pixels_per_point) = ctx.input(|i| i.raw.native_pixels_per_point) {
|
||||
ctx.set_pixels_per_point(native_pixels_per_point);
|
||||
}
|
||||
ctx.set_zoom_factor(1.0);
|
||||
} else {
|
||||
if ctx.input_mut(|i| i.consume_shortcut(&kb_shortcuts::ZOOM_IN)) {
|
||||
zoom_in(ctx);
|
||||
@@ -36,47 +30,34 @@ pub fn zoom_with_keyboard_shortcuts(ctx: &Context) {
|
||||
}
|
||||
}
|
||||
|
||||
const MIN_PIXELS_PER_POINT: f32 = 0.2;
|
||||
const MAX_PIXELS_PER_POINT: f32 = 4.0;
|
||||
const MIN_ZOOM_FACTOR: f32 = 0.2;
|
||||
const MAX_ZOOM_FACTOR: f32 = 5.0;
|
||||
|
||||
/// Make everything larger.
|
||||
/// Make everything larger by increasing [`Context::zoom_factor`].
|
||||
pub fn zoom_in(ctx: &Context) {
|
||||
let mut pixels_per_point = ctx.pixels_per_point();
|
||||
pixels_per_point += 0.1;
|
||||
pixels_per_point = pixels_per_point.clamp(MIN_PIXELS_PER_POINT, MAX_PIXELS_PER_POINT);
|
||||
pixels_per_point = (pixels_per_point * 10.).round() / 10.;
|
||||
ctx.set_pixels_per_point(pixels_per_point);
|
||||
let mut zoom_factor = ctx.zoom_factor();
|
||||
zoom_factor += 0.1;
|
||||
zoom_factor = zoom_factor.clamp(MIN_ZOOM_FACTOR, MAX_ZOOM_FACTOR);
|
||||
zoom_factor = (zoom_factor * 10.).round() / 10.;
|
||||
ctx.set_zoom_factor(zoom_factor);
|
||||
}
|
||||
|
||||
/// Make everything smaller.
|
||||
/// Make everything smaller by decreasing [`Context::zoom_factor`].
|
||||
pub fn zoom_out(ctx: &Context) {
|
||||
let mut pixels_per_point = ctx.pixels_per_point();
|
||||
pixels_per_point -= 0.1;
|
||||
pixels_per_point = pixels_per_point.clamp(MIN_PIXELS_PER_POINT, MAX_PIXELS_PER_POINT);
|
||||
pixels_per_point = (pixels_per_point * 10.).round() / 10.;
|
||||
ctx.set_pixels_per_point(pixels_per_point);
|
||||
let mut zoom_factor = ctx.zoom_factor();
|
||||
zoom_factor -= 0.1;
|
||||
zoom_factor = zoom_factor.clamp(MIN_ZOOM_FACTOR, MAX_ZOOM_FACTOR);
|
||||
zoom_factor = (zoom_factor * 10.).round() / 10.;
|
||||
ctx.set_zoom_factor(zoom_factor);
|
||||
}
|
||||
|
||||
/// Show buttons for zooming the ui.
|
||||
///
|
||||
/// This is meant to be called from within a menu (See [`Ui::menu_button`]).
|
||||
///
|
||||
/// When using [`eframe`](https://github.com/emilk/egui/tree/master/crates/eframe), you want to call this as:
|
||||
/// ```ignore
|
||||
/// // On web, the browser controls the gui zoom.
|
||||
/// if !frame.is_web() {
|
||||
/// ui.menu_button("View", |ui| {
|
||||
/// egui::gui_zoom::zoom_menu_buttons(
|
||||
/// ui,
|
||||
/// frame.info().native_pixels_per_point,
|
||||
/// );
|
||||
/// });
|
||||
/// }
|
||||
/// ```
|
||||
pub fn zoom_menu_buttons(ui: &mut Ui, native_pixels_per_point: Option<f32>) {
|
||||
pub fn zoom_menu_buttons(ui: &mut Ui) {
|
||||
if ui
|
||||
.add_enabled(
|
||||
ui.ctx().pixels_per_point() < MAX_PIXELS_PER_POINT,
|
||||
ui.ctx().zoom_factor() < MAX_ZOOM_FACTOR,
|
||||
Button::new("Zoom In").shortcut_text(ui.ctx().format_shortcut(&kb_shortcuts::ZOOM_IN)),
|
||||
)
|
||||
.clicked()
|
||||
@@ -87,7 +68,7 @@ pub fn zoom_menu_buttons(ui: &mut Ui, native_pixels_per_point: Option<f32>) {
|
||||
|
||||
if ui
|
||||
.add_enabled(
|
||||
ui.ctx().pixels_per_point() > MIN_PIXELS_PER_POINT,
|
||||
ui.ctx().zoom_factor() > MIN_ZOOM_FACTOR,
|
||||
Button::new("Zoom Out")
|
||||
.shortcut_text(ui.ctx().format_shortcut(&kb_shortcuts::ZOOM_OUT)),
|
||||
)
|
||||
@@ -97,17 +78,15 @@ pub fn zoom_menu_buttons(ui: &mut Ui, native_pixels_per_point: Option<f32>) {
|
||||
ui.close_menu();
|
||||
}
|
||||
|
||||
if let Some(native_pixels_per_point) = native_pixels_per_point {
|
||||
if ui
|
||||
.add_enabled(
|
||||
ui.ctx().pixels_per_point() != native_pixels_per_point,
|
||||
Button::new("Reset Zoom")
|
||||
.shortcut_text(ui.ctx().format_shortcut(&kb_shortcuts::ZOOM_RESET)),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
ui.ctx().set_pixels_per_point(native_pixels_per_point);
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui
|
||||
.add_enabled(
|
||||
ui.ctx().zoom_factor() != 1.0,
|
||||
Button::new("Reset Zoom")
|
||||
.shortcut_text(ui.ctx().format_shortcut(&kb_shortcuts::ZOOM_RESET)),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
ui.ctx().set_zoom_factor(1.0);
|
||||
ui.close_menu();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,6 +148,7 @@ impl InputState {
|
||||
mut self,
|
||||
mut new: RawInput,
|
||||
requested_repaint_last_frame: bool,
|
||||
pixels_per_point: f32,
|
||||
) -> InputState {
|
||||
crate::profile_function!();
|
||||
|
||||
@@ -217,7 +218,7 @@ impl InputState {
|
||||
scroll_delta,
|
||||
zoom_factor_delta,
|
||||
screen_rect,
|
||||
pixels_per_point: new.pixels_per_point.unwrap_or(self.pixels_per_point),
|
||||
pixels_per_point,
|
||||
max_texture_side: new.max_texture_side.unwrap_or(self.max_texture_side),
|
||||
time,
|
||||
unstable_dt,
|
||||
|
||||
@@ -71,10 +71,6 @@ pub struct Memory {
|
||||
pub caches: crate::util::cache::CacheStorage,
|
||||
|
||||
// ------------------------------------------
|
||||
/// new scale that will be applied at the start of the next frame
|
||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||
pub(crate) override_pixels_per_point: Option<f32>,
|
||||
|
||||
/// new fonts that will be applied at the start of the next frame
|
||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||
pub(crate) new_font_definitions: Option<epaint::text::FontDefinitions>,
|
||||
@@ -111,7 +107,6 @@ impl Default for Memory {
|
||||
options: Default::default(),
|
||||
data: Default::default(),
|
||||
caches: Default::default(),
|
||||
override_pixels_per_point: Default::default(),
|
||||
new_font_definitions: Default::default(),
|
||||
interactions: Default::default(),
|
||||
viewport_id: Default::default(),
|
||||
@@ -176,6 +171,21 @@ pub struct Options {
|
||||
#[cfg_attr(feature = "serde", serde(skip))]
|
||||
pub(crate) style: std::sync::Arc<Style>,
|
||||
|
||||
/// Global zoom factor of the UI.
|
||||
///
|
||||
/// This is used to calculate the `pixels_per_point`
|
||||
/// for the UI as `pixels_per_point = zoom_fator * native_pixels_per_point`.
|
||||
///
|
||||
/// The default is 1.0.
|
||||
/// Make larger to make everything larger.
|
||||
pub zoom_factor: f32,
|
||||
|
||||
/// If `true`, egui will change the scale of the ui ([`crate::Context::zoom_factor`]) when the user
|
||||
/// presses Cmd+Plus, Cmd+Minus or Cmd+0, just like in a browser.
|
||||
///
|
||||
/// This is `true` by default.
|
||||
pub zoom_with_keyboard: bool,
|
||||
|
||||
/// Controls the tessellator.
|
||||
pub tessellation_options: epaint::TessellationOptions,
|
||||
|
||||
@@ -208,6 +218,8 @@ impl Default for Options {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
style: Default::default(),
|
||||
zoom_factor: 1.0,
|
||||
zoom_with_keyboard: true,
|
||||
tessellation_options: Default::default(),
|
||||
screen_reader: false,
|
||||
preload_font_glyphs: true,
|
||||
|
||||
Reference in New Issue
Block a user