Skip to content

Commit

Permalink
Merge pull request #1075 from ForLoveOfCats/ReExportScalable
Browse files Browse the repository at this point in the history
Re-export `druid_shell::Scalable` & remove to_px/to_dp helpers on Scale
  • Loading branch information
ForLoveOfCats authored Jul 14, 2020
2 parents 1d6a30f + 7a31086 commit 5ec6ca4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,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<f64>` 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

Expand Down Expand Up @@ -242,6 +244,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
[@vkahl]: https://github.com/vkahl

Expand Down Expand Up @@ -351,6 +354,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
[#1081]: https://github.com/linebender/druid/pull/1081

Expand Down
14 changes: 7 additions & 7 deletions druid-shell/src/platform/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()),
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -577,7 +577,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,
Expand Down
14 changes: 7 additions & 7 deletions druid-shell/src/platform/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 0 additions & 16 deletions druid-shell/src/scale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Scalable>(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<T: Into<f64>>(self, x: T) -> f64 {
Expand All @@ -142,14 +134,6 @@ impl Scale {
pub fn px_to_dp_xy<T: Into<f64>>(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<T: Scalable>(self, item: &T) -> T {
item.to_dp(self)
}
}

impl Scalable for Vec2 {
Expand Down
2 changes: 1 addition & 1 deletion druid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5ec6ca4

Please sign in to comment.