Skip to content

Commit 5ec6ca4

Browse files
Merge pull request #1075 from ForLoveOfCats/ReExportScalable
Re-export `druid_shell::Scalable` & remove to_px/to_dp helpers on Scale
2 parents 1d6a30f + 7a31086 commit 5ec6ca4

File tree

5 files changed

+19
-31
lines changed

5 files changed

+19
-31
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ You can find its changes [documented below](#060---2020-06-01).
1717
- `Scale::from_scale` to `Scale::new`, and `Scale` methods `scale_x` / `scale_y` to `x` / `y`. ([#1042] by [@xStrom])
1818
- Major rework of keyboard event handling ([#1049] by [@raphlinus])
1919
- `Container::rounded` takes `KeyOrValue<f64>` instead of `f64`. ([#1054] by [@binomial0])
20+
- Re-export `druid_shell::Scalable` under `druid` namespace. ([#1075] by [@ForLoveOfCats])
2021

2122
### Deprecated
2223

2324
### Removed
2425

2526
- `Scale::from_dpi`, `Scale::dpi_x`, and `Scale::dpi_y`. ([#1042] by [@xStrom])
27+
- `Scale::to_px` and `Scale::to_dp`. ([#1075] by [@ForLoveOfCats])
2628

2729
### Fixed
2830

@@ -242,6 +244,7 @@ Last release without a changelog :(
242244
[@covercash2]: https://github.com/covercash2
243245
[@raphlinus]: https://github.com/raphlinus
244246
[@binomial0]: https://github.com/binomial0
247+
[@ForLoveOfCats]: https://github.com/ForLoveOfCats
245248
[@chris-zen]: https://github.com/chris-zen
246249
[@vkahl]: https://github.com/vkahl
247250

@@ -351,6 +354,7 @@ Last release without a changelog :(
351354
[#1050]: https://github.com/linebender/druid/pull/1050
352355
[#1054]: https://github.com/linebender/druid/pull/1054
353356
[#1058]: https://github.com/linebender/druid/pull/1058
357+
[#1075]: https://github.com/linebender/druid/pull/1075
354358
[#1062]: https://github.com/linebender/druid/pull/1062
355359
[#1081]: https://github.com/linebender/druid/pull/1081
356360

druid-shell/src/platform/gtk/window.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::dialog::{FileDialogOptions, FileDialogType, FileInfo};
3939
use crate::error::Error as ShellError;
4040
use crate::keyboard::{KbKey, KeyState, KeyEvent, Modifiers};
4141
use crate::mouse::{Cursor, MouseButton, MouseButtons, MouseEvent};
42-
use crate::scale::{Scale, ScaledArea};
42+
use crate::scale::{Scale, Scalable, ScaledArea};
4343
use crate::window::{IdleToken, Text, TimerToken, WinHandler};
4444

4545
use super::application::Application;
@@ -323,7 +323,7 @@ impl WindowBuilder {
323323
let button_state = event.get_state();
324324
handler.mouse_down(
325325
&MouseEvent {
326-
pos: scale.to_dp(&Point::from(event.get_position())),
326+
pos: Point::from(event.get_position()).to_dp(scale),
327327
buttons: get_mouse_buttons_from_modifiers(button_state).with(button),
328328
mods: get_modifiers(button_state),
329329
count: get_mouse_click_count(event.get_event_type()),
@@ -349,7 +349,7 @@ impl WindowBuilder {
349349
let button_state = event.get_state();
350350
handler.mouse_up(
351351
&MouseEvent {
352-
pos: scale.to_dp(&Point::from(event.get_position())),
352+
pos: Point::from(event.get_position()).to_dp(scale),
353353
buttons: get_mouse_buttons_from_modifiers(button_state).without(button),
354354
mods: get_modifiers(button_state),
355355
count: 0,
@@ -372,7 +372,7 @@ impl WindowBuilder {
372372
let scale = state.scale.get();
373373
let motion_state = motion.get_state();
374374
let mouse_event = MouseEvent {
375-
pos: scale.to_dp(&Point::from(motion.get_position())),
375+
pos: Point::from(motion.get_position()).to_dp(scale),
376376
buttons: get_mouse_buttons_from_modifiers(motion_state),
377377
mods: get_modifiers(motion_state),
378378
count: 0,
@@ -396,7 +396,7 @@ impl WindowBuilder {
396396
let scale = state.scale.get();
397397
let crossing_state = crossing.get_state();
398398
let mouse_event = MouseEvent {
399-
pos: scale.to_dp(&Point::from(crossing.get_position())),
399+
pos: Point::from(crossing.get_position()).to_dp(scale),
400400
buttons: get_mouse_buttons_from_modifiers(crossing_state),
401401
mods: get_modifiers(crossing_state),
402402
count: 0,
@@ -452,7 +452,7 @@ impl WindowBuilder {
452452

453453
if let Some(wheel_delta) = wheel_delta {
454454
let mouse_event = MouseEvent {
455-
pos: scale.to_dp(&Point::from(scroll.get_position())),
455+
pos: Point::from(scroll.get_position()).to_dp(scale),
456456
buttons: get_mouse_buttons_from_modifiers(scroll.get_state()),
457457
mods,
458458
count: 0,
@@ -577,7 +577,7 @@ impl WindowHandle {
577577
pub fn invalidate_rect(&self, rect: Rect) {
578578
if let Some(state) = self.state.upgrade() {
579579
// GTK takes rects with non-negative integer width/height.
580-
let r = state.scale.get().to_px(&rect.abs()).expand();
580+
let r = rect.abs().to_px(state.scale.get()).expand();
581581
let origin = state.drawing_area.get_allocation();
582582
state.window.queue_draw_area(
583583
r.x0 as i32 + origin.x,

druid-shell/src/platform/windows/window.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use crate::dialog::{FileDialogOptions, FileDialogType, FileInfo};
6262
use crate::error::Error as ShellError;
6363
use crate::keyboard::{KbKey, KeyState};
6464
use crate::mouse::{Cursor, MouseButton, MouseButtons, MouseEvent};
65-
use crate::scale::{Scale, ScaledArea};
65+
use crate::scale::{Scale, Scalable, ScaledArea};
6666
use crate::window::{IdleToken, Text, TimerToken, WinHandler};
6767

6868
/// The platform target DPI.
@@ -429,7 +429,7 @@ impl WndProc for MyWndProc {
429429
s.render_target = rt.ok();
430430
}
431431
s.handler.rebuild_resources();
432-
let rect_dp = self.scale().to_dp(&util::recti_to_rect(rect));
432+
let rect_dp = util::recti_to_rect(rect).to_dp(self.scale());
433433
s.render(
434434
&self.d2d_factory,
435435
&self.dwrite_factory,
@@ -659,7 +659,7 @@ impl WndProc for MyWndProc {
659659
}
660660
}
661661

662-
let pos = self.scale().to_dp(&(p.x as f64, p.y as f64).into());
662+
let pos = Point::new(p.x as f64, p.y as f64).to_dp(self.scale());
663663
let buttons = get_buttons(down_state);
664664
let event = MouseEvent {
665665
pos,
@@ -705,7 +705,7 @@ impl WndProc for MyWndProc {
705705
}
706706
}
707707

708-
let pos = self.scale().to_dp(&(x as f64, y as f64).into());
708+
let pos = Point::new(x as f64, y as f64).to_dp(self.scale());
709709
let mods = s.keyboard_state.get_modifiers();
710710
let buttons = get_buttons(wparam);
711711
let event = MouseEvent {
@@ -767,7 +767,7 @@ impl WndProc for MyWndProc {
767767
};
768768
let x = LOWORD(lparam as u32) as i16 as i32;
769769
let y = HIWORD(lparam as u32) as i16 as i32;
770-
let pos = self.scale().to_dp(&(x as f64, y as f64).into());
770+
let pos = Point::new(x as f64, y as f64).to_dp(self.scale());
771771
let mods = s.keyboard_state.get_modifiers();
772772
let buttons = get_buttons(wparam);
773773
let event = MouseEvent {
@@ -1252,7 +1252,7 @@ impl WindowHandle {
12521252

12531253
pub fn invalidate_rect(&self, rect: Rect) {
12541254
if let Some(w) = self.state.upgrade() {
1255-
let rect = util::rect_to_recti(w.scale.get().to_px(&rect).expand());
1255+
let rect = util::rect_to_recti(rect.to_px(w.scale.get()).expand());
12561256
let hwnd = w.hwnd.get();
12571257
unsafe {
12581258
if InvalidateRect(hwnd, &rect, FALSE) == FALSE {
@@ -1333,7 +1333,7 @@ impl WindowHandle {
13331333
let hmenu = menu.into_hmenu();
13341334
if let Some(w) = self.state.upgrade() {
13351335
let hwnd = w.hwnd.get();
1336-
let pos = w.scale.get().to_px(&pos).round();
1336+
let pos = pos.to_px(w.scale.get()).round();
13371337
unsafe {
13381338
let mut point = POINT {
13391339
x: pos.x as i32,

druid-shell/src/scale.rs

-16
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,6 @@ impl Scale {
116116
self.y
117117
}
118118

119-
/// Converts the `item` from display points into pixels,
120-
/// using the x axis scale factor for coordinates on the x axis
121-
/// and the y axis scale factor for coordinates on the y axis.
122-
#[inline]
123-
pub fn to_px<T: Scalable>(self, item: &T) -> T {
124-
item.to_px(self)
125-
}
126-
127119
/// Converts from pixels into display points, using the x axis scale factor.
128120
#[inline]
129121
pub fn px_to_dp_x<T: Into<f64>>(self, x: T) -> f64 {
@@ -142,14 +134,6 @@ impl Scale {
142134
pub fn px_to_dp_xy<T: Into<f64>>(self, x: T, y: T) -> (f64, f64) {
143135
(x.into() / self.x, y.into() / self.y)
144136
}
145-
146-
/// Converts the `item` from pixels into display points,
147-
/// using the x axis scale factor for coordinates on the x axis
148-
/// and the y axis scale factor for coordinates on the y axis.
149-
#[inline]
150-
pub fn to_dp<T: Scalable>(self, item: &T) -> T {
151-
item.to_dp(self)
152-
}
153137
}
154138

155139
impl Scalable for Vec2 {

druid/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub use shell::keyboard_types;
171171
pub use shell::{
172172
Application, Clipboard, ClipboardFormat, Code, Cursor, Error as PlatformError,
173173
FileDialogOptions, FileInfo, FileSpec, FormatId, HotKey, KbKey, KeyEvent, Location, Modifiers,
174-
MouseButton, MouseButtons, RawMods, Scale, SysMods, Text, TimerToken, WindowHandle,
174+
MouseButton, MouseButtons, RawMods, Scalable, Scale, SysMods, Text, TimerToken, WindowHandle,
175175
};
176176

177177
pub use crate::core::WidgetPod;

0 commit comments

Comments
 (0)