diff --git a/CHANGELOG.md b/CHANGELOG.md index e769df73d2..29ebfd78e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,12 +15,14 @@ You can find its changes [documented below](#060---2020-06-01). - `Scale::from_scale` to `Scale::new`, and `Scale` methods `scale_x` / `scale_y` to `x` / `y`. ([#1042] by [@xStrom]) - Major rework of keyboard event handling ([#1049] by [@raphlinus]) - `Container::rounded` takes `KeyOrValue` instead of `f64`. ([#1054] by [@binomial0]) +- Re-export `druid_shell::Scalable` under `druid` namespace. ([#1075] by [@ForLoveOfCats]) ### Deprecated ### Removed - `Scale::from_dpi`, `Scale::dpi_x`, and `Scale::dpi_y`. ([#1042] by [@xStrom]) +- `Scale::to_px` and `Scale::to_dp`. ([#1075] by [@ForLoveOfCats]) ### Fixed @@ -239,6 +241,7 @@ Last release without a changelog :( [@covercash2]: https://github.com/covercash2 [@raphlinus]: https://github.com/raphlinus [@binomial0]: https://github.com/binomial0 +[@ForLoveOfCats]: https://github.com/ForLoveOfCats [@chris-zen]: https://github.com/chris-zen [#599]: https://github.com/linebender/druid/pull/599 @@ -347,6 +350,7 @@ Last release without a changelog :( [#1050]: https://github.com/linebender/druid/pull/1050 [#1054]: https://github.com/linebender/druid/pull/1054 [#1058]: https://github.com/linebender/druid/pull/1058 +[#1075]: https://github.com/linebender/druid/pull/1075 [#1062]: https://github.com/linebender/druid/pull/1062 [Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master diff --git a/druid-shell/src/platform/gtk/window.rs b/druid-shell/src/platform/gtk/window.rs index cd6ffd5e4a..4e3793584c 100644 --- a/druid-shell/src/platform/gtk/window.rs +++ b/druid-shell/src/platform/gtk/window.rs @@ -39,7 +39,7 @@ use crate::dialog::{FileDialogOptions, FileDialogType, FileInfo}; use crate::error::Error as ShellError; use crate::keyboard::{KbKey, KeyState, KeyEvent, Modifiers}; use crate::mouse::{Cursor, MouseButton, MouseButtons, MouseEvent}; -use crate::scale::{Scale, ScaledArea}; +use crate::scale::{Scale, Scalable, ScaledArea}; use crate::window::{IdleToken, Text, TimerToken, WinHandler}; use super::application::Application; @@ -323,7 +323,7 @@ impl WindowBuilder { let button_state = event.get_state(); handler.mouse_down( &MouseEvent { - pos: scale.to_dp(&Point::from(event.get_position())), + pos: Point::from(event.get_position()).to_dp(scale), buttons: get_mouse_buttons_from_modifiers(button_state).with(button), mods: get_modifiers(button_state), count: get_mouse_click_count(event.get_event_type()), @@ -349,7 +349,7 @@ impl WindowBuilder { let button_state = event.get_state(); handler.mouse_up( &MouseEvent { - pos: scale.to_dp(&Point::from(event.get_position())), + pos: Point::from(event.get_position()).to_dp(scale), buttons: get_mouse_buttons_from_modifiers(button_state).without(button), mods: get_modifiers(button_state), count: 0, @@ -372,7 +372,7 @@ impl WindowBuilder { let scale = state.scale.get(); let motion_state = motion.get_state(); let mouse_event = MouseEvent { - pos: scale.to_dp(&Point::from(motion.get_position())), + pos: Point::from(motion.get_position()).to_dp(scale), buttons: get_mouse_buttons_from_modifiers(motion_state), mods: get_modifiers(motion_state), count: 0, @@ -396,7 +396,7 @@ impl WindowBuilder { let scale = state.scale.get(); let crossing_state = crossing.get_state(); let mouse_event = MouseEvent { - pos: scale.to_dp(&Point::from(crossing.get_position())), + pos: Point::from(crossing.get_position()).to_dp(scale), buttons: get_mouse_buttons_from_modifiers(crossing_state), mods: get_modifiers(crossing_state), count: 0, @@ -452,7 +452,7 @@ impl WindowBuilder { if let Some(wheel_delta) = wheel_delta { let mouse_event = MouseEvent { - pos: scale.to_dp(&Point::from(scroll.get_position())), + pos: Point::from(scroll.get_position()).to_dp(scale), buttons: get_mouse_buttons_from_modifiers(scroll.get_state()), mods, count: 0, @@ -573,7 +573,7 @@ impl WindowHandle { pub fn invalidate_rect(&self, rect: Rect) { if let Some(state) = self.state.upgrade() { // GTK takes rects with non-negative integer width/height. - let r = state.scale.get().to_px(&rect.abs()).expand(); + let r = rect.abs().to_px(state.scale.get()).expand(); let origin = state.drawing_area.get_allocation(); state.window.queue_draw_area( r.x0 as i32 + origin.x, diff --git a/druid-shell/src/platform/windows/window.rs b/druid-shell/src/platform/windows/window.rs index 9f15a49996..82e6c4df66 100644 --- a/druid-shell/src/platform/windows/window.rs +++ b/druid-shell/src/platform/windows/window.rs @@ -62,7 +62,7 @@ use crate::dialog::{FileDialogOptions, FileDialogType, FileInfo}; use crate::error::Error as ShellError; use crate::keyboard::{KbKey, KeyState}; use crate::mouse::{Cursor, MouseButton, MouseButtons, MouseEvent}; -use crate::scale::{Scale, ScaledArea}; +use crate::scale::{Scale, Scalable, ScaledArea}; use crate::window::{IdleToken, Text, TimerToken, WinHandler}; /// The platform target DPI. @@ -429,7 +429,7 @@ impl WndProc for MyWndProc { s.render_target = rt.ok(); } s.handler.rebuild_resources(); - let rect_dp = self.scale().to_dp(&util::recti_to_rect(rect)); + let rect_dp = util::recti_to_rect(rect).to_dp(self.scale()); s.render( &self.d2d_factory, &self.dwrite_factory, @@ -659,7 +659,7 @@ impl WndProc for MyWndProc { } } - let pos = self.scale().to_dp(&(p.x as f64, p.y as f64).into()); + let pos = Point::new(p.x as f64, p.y as f64).to_dp(self.scale()); let buttons = get_buttons(down_state); let event = MouseEvent { pos, @@ -705,7 +705,7 @@ impl WndProc for MyWndProc { } } - let pos = self.scale().to_dp(&(x as f64, y as f64).into()); + let pos = Point::new(x as f64, y as f64).to_dp(self.scale()); let mods = s.keyboard_state.get_modifiers(); let buttons = get_buttons(wparam); let event = MouseEvent { @@ -767,7 +767,7 @@ impl WndProc for MyWndProc { }; let x = LOWORD(lparam as u32) as i16 as i32; let y = HIWORD(lparam as u32) as i16 as i32; - let pos = self.scale().to_dp(&(x as f64, y as f64).into()); + let pos = Point::new(x as f64, y as f64).to_dp(self.scale()); let mods = s.keyboard_state.get_modifiers(); let buttons = get_buttons(wparam); let event = MouseEvent { @@ -1252,7 +1252,7 @@ impl WindowHandle { pub fn invalidate_rect(&self, rect: Rect) { if let Some(w) = self.state.upgrade() { - let rect = util::rect_to_recti(w.scale.get().to_px(&rect).expand()); + let rect = util::rect_to_recti(rect.to_px(w.scale.get()).expand()); let hwnd = w.hwnd.get(); unsafe { if InvalidateRect(hwnd, &rect, FALSE) == FALSE { @@ -1333,7 +1333,7 @@ impl WindowHandle { let hmenu = menu.into_hmenu(); if let Some(w) = self.state.upgrade() { let hwnd = w.hwnd.get(); - let pos = w.scale.get().to_px(&pos).round(); + let pos = pos.to_px(w.scale.get()).round(); unsafe { let mut point = POINT { x: pos.x as i32, diff --git a/druid-shell/src/scale.rs b/druid-shell/src/scale.rs index 5e7a727baf..31600b2017 100644 --- a/druid-shell/src/scale.rs +++ b/druid-shell/src/scale.rs @@ -116,14 +116,6 @@ impl Scale { self.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. - #[inline] - pub fn to_px(self, item: &T) -> T { - item.to_px(self) - } - /// Converts from pixels into display points, using the x axis scale factor. #[inline] pub fn px_to_dp_x>(self, x: T) -> f64 { @@ -142,14 +134,6 @@ impl Scale { pub fn px_to_dp_xy>(self, x: T, y: T) -> (f64, f64) { (x.into() / self.x, y.into() / self.y) } - - /// Converts the `item` from pixels into display points, - /// using the x axis scale factor for coordinates on the x axis - /// and the y axis scale factor for coordinates on the y axis. - #[inline] - pub fn to_dp(self, item: &T) -> T { - item.to_dp(self) - } } impl Scalable for Vec2 { diff --git a/druid/src/lib.rs b/druid/src/lib.rs index 89152c1022..0bb2244708 100644 --- a/druid/src/lib.rs +++ b/druid/src/lib.rs @@ -171,7 +171,7 @@ pub use shell::keyboard_types; pub use shell::{ Application, Clipboard, ClipboardFormat, Code, Cursor, Error as PlatformError, FileDialogOptions, FileInfo, FileSpec, FormatId, HotKey, KbKey, KeyEvent, Location, Modifiers, - MouseButton, MouseButtons, RawMods, Scale, SysMods, Text, TimerToken, WindowHandle, + MouseButton, MouseButtons, RawMods, Scalable, Scale, SysMods, Text, TimerToken, WindowHandle, }; pub use crate::core::WidgetPod;