Skip to content

Commit

Permalink
Delete some Scale code.
Browse files Browse the repository at this point in the history
  • Loading branch information
xStrom committed May 18, 2020
1 parent 16ec5af commit 060dc4f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 34 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion druid-shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ kurbo = "0.6.0"
log = "0.4.8"
lazy_static = "1.0"
time = "0.2.7"
float-cmp = { version = "0.8.0", features = ["std"], default-features = false }
cfg-if = "0.1.10"
instant = { version = "0.1", features = ["wasm-bindgen"] }

Expand Down
5 changes: 3 additions & 2 deletions druid-shell/src/platform/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ impl WindowBuilder {
// so that we can change our scale factor without restarting the application.
if let Some(dpi) = state.window.get_window()
.map(|w| w.get_display().get_default_screen().get_resolution()) {
if !scale.dpi_approx_eq(dpi, dpi) {
scale = Scale::from_dpi(dpi, dpi);
let reported_scale = Scale::from_dpi(dpi, dpi);
if scale != reported_scale {
scale = reported_scale;
state.scale.set(scale);
scale_changed = true;
if let Ok(mut handler_borrow) = state.handler.try_borrow_mut() {
Expand Down
32 changes: 2 additions & 30 deletions druid-shell/src/scale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

//! Resolution scale related helpers.
use float_cmp::ApproxEq;

use crate::kurbo::{Insets, Line, Point, Rect, Size, Vec2};

const SCALE_TARGET_DPI: f64 = 96.0;
Expand Down Expand Up @@ -68,9 +66,9 @@ pub struct Scale {
///
/// The logical area size in display points is an unrounded conversion, which means that it is
/// often not limited to integers. This allows for accurate calculations of
/// the platform area pixel boundaries from the logcal area using a [`Scale`].
/// the platform area pixel boundaries from the logical area using a [`Scale`].
///
/// Even though the logcal area size can be fractional, the integer boundaries of that logical area
/// Even though the logical area size can be fractional, the integer boundaries of that logical area
/// will still match up with the platform area pixel boundaries as often as the scale factor allows.
///
/// A copy of `ScaledArea` will be stale as soon as the platform area size changes.
Expand Down Expand Up @@ -148,13 +146,6 @@ impl Scale {
self.dpi_y
}

/// Returns `true` if the specified DPI is approximately equal to the `Scale` DPI.
#[inline]
pub fn dpi_approx_eq(&self, dpi_x: f64, dpi_y: f64) -> bool {
self.dpi_x.approx_eq(dpi_x, (f64::EPSILON, 2))
&& self.dpi_y.approx_eq(dpi_y, (f64::EPSILON, 2))
}

/// Returns the x axis scale factor.
#[inline]
pub fn scale_x(&self) -> f64 {
Expand All @@ -167,25 +158,6 @@ impl Scale {
self.scale_y
}

/// Converts from display points into pixels, using the x axis scale factor.
#[inline]
pub fn dp_to_px_x<T: Into<f64>>(&self, x: T) -> f64 {
x.into() * self.scale_x
}

/// Converts from display points into pixels, using the y axis scale factor.
#[inline]
pub fn dp_to_px_y<T: Into<f64>>(&self, y: T) -> f64 {
y.into() * self.scale_y
}

/// Converts from display points into pixels,
/// using the x axis scale factor for `x` and the y axis scale factor for `y`.
#[inline]
pub fn dp_to_px_xy<T: Into<f64>>(&self, x: T, y: T) -> (f64, f64) {
(x.into() * self.scale_x, y.into() * self.scale_y)
}

/// Converts the `item` from display points into pixels,
/// using the x axis scale factor for coordinates on the x axis
/// and the y axis scale factor for coordinates on the y axis.
Expand Down

0 comments on commit 060dc4f

Please sign in to comment.