Skip to content

Commit 32583b3

Browse files
committed
Make Viewport::zoom public to replace methods and add docs
1 parent ad9ae8d commit 32583b3

File tree

6 files changed

+33
-26
lines changed

6 files changed

+33
-26
lines changed

packages/blitz-dom/src/image.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
use taffy::{MaybeMath, MaybeResolve};
22

3+
/// Layout context for an image.
34
#[derive(Debug, Clone, Copy)]
45
pub struct ImageContext {
6+
/// Inherent size of the image.
57
pub inherent_size: taffy::Size<f32>,
8+
9+
/// Specified size of the image.
610
pub attr_size: taffy::Size<Option<f32>>,
711
}
812

9-
pub fn image_measure_function(
13+
/// Measure an image.
14+
pub fn measure_image(
1015
known_dimensions: taffy::Size<Option<f32>>,
1116
parent_size: taffy::Size<Option<f32>>,
1217
image_context: &ImageContext,

packages/blitz-dom/src/layout/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use crate::node::{NodeData, NodeKind, NodeSpecificData};
88
use crate::{
99
document::Document,
10-
image::{image_measure_function, ImageContext},
10+
image::{measure_image, ImageContext},
1111
node::Node,
1212
};
1313
use html5ever::local_name;
@@ -245,7 +245,7 @@ impl LayoutPartialTree for Document {
245245
inputs,
246246
&node.style,
247247
|known_dimensions, _available_space| {
248-
image_measure_function(
248+
measure_image(
249249
known_dimensions,
250250
inputs.parent_size,
251251
&image_context,

packages/blitz-dom/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/// This is the primary entry point for this crate.
1616
pub mod document;
1717

18+
/// HTML document data structure.
1819
pub mod html_document;
1920
/// An implementation for Html5ever's sink trait, allowing us to parse HTML into a DOM.
2021
pub mod htmlsink;
@@ -37,14 +38,19 @@ pub mod stylo_to_parley;
3738
/// Conversions from Stylo types to Taffy and Parley types
3839
pub mod stylo_to_taffy;
3940

41+
/// Image layout.
4042
pub mod image;
4143

44+
/// Utility functions.
4245
pub mod util;
4346

47+
/// Debugging.
4448
pub mod debug;
4549

50+
/// Events.
4651
pub mod events;
4752

53+
/// Window viewport.
4854
pub mod viewport;
4955

5056
pub use document::{Document, DocumentLike};

packages/blitz-dom/src/node.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ impl ElementNodeData {
464464
}
465465
}
466466

467-
pub fn flush_is_focussable(&mut self) {
467+
pub(crate) fn flush_is_focussable(&mut self) {
468468
let disabled: bool = self.attr_parsed(local_name!("disabled")).unwrap_or(false);
469469
let tabindex: Option<i32> = self.attr_parsed(local_name!("tabindex"));
470470

@@ -513,6 +513,7 @@ impl ElementNodeData {
513513
});
514514
}
515515

516+
/// Take the current cached inline text layout.
516517
pub fn take_inline_layout(&mut self) -> Option<Box<TextLayout>> {
517518
std::mem::take(&mut self.inline_layout_data)
518519
}

packages/blitz-dom/src/viewport.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@ use style::{
44
properties::{style_structs::Font, ComputedValues},
55
};
66

7+
/// Window viewport.
78
#[derive(Default, Debug, Clone)]
89
pub struct Viewport {
10+
/// Size of the window.
911
pub window_size: (u32, u32),
1012

11-
hidpi_scale: f32,
13+
/// Font size.
14+
pub font_size: f32,
1215

13-
zoom: f32,
16+
/// Zoom level.
17+
pub zoom: f32,
1418

15-
pub font_size: f32,
19+
hidpi_scale: f32,
1620
}
1721

1822
impl Viewport {
23+
/// Create a new viewport from a window's physical size and scale factor.
1924
pub fn new(physical_width: u32, physical_height: u32, scale_factor: f32) -> Self {
2025
Self {
2126
window_size: (physical_width, physical_height),
@@ -25,31 +30,21 @@ impl Viewport {
2530
}
2631
}
2732

28-
// Total scaling, the product of the zoom and hdpi scale
33+
/// Total scaling, the product of the zoom and hdpi scale.
2934
pub fn scale(&self) -> f32 {
3035
self.hidpi_scale * self.zoom
3136
}
32-
// Total scaling, the product of the zoom and hdpi scale
37+
38+
/// Total scaling, the product of the zoom and hdpi scale (as an `f64`).
3339
pub fn scale_f64(&self) -> f64 {
3440
self.scale() as f64
3541
}
3642

43+
/// Set the hidi scale.
3744
pub fn set_hidpi_scale(&mut self, scale: f32) {
3845
self.hidpi_scale = scale;
3946
}
4047

41-
pub fn zoom(&self) -> f32 {
42-
self.zoom
43-
}
44-
45-
pub fn set_zoom(&mut self, zoom: f32) {
46-
self.zoom = zoom;
47-
}
48-
49-
pub fn zoom_mut(&mut self) -> &mut f32 {
50-
&mut self.zoom
51-
}
52-
5348
pub(crate) fn make_device(&self) -> Device {
5449
let width = self.window_size.0 as f32 / self.scale();
5550
let height = self.window_size.1 as f32 / self.scale();

packages/dioxus-native/src/window.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ impl<Doc: DocumentLike> View<Doc> {
213213

214214
pub fn mouse_move(&mut self, x: f32, y: f32) -> bool {
215215
let viewport_scroll = self.dom.as_ref().viewport_scroll();
216-
let dom_x = x + viewport_scroll.x as f32 / self.viewport.zoom();
217-
let dom_y = y + viewport_scroll.y as f32 / self.viewport.zoom();
216+
let dom_x = x + viewport_scroll.x as f32 / self.viewport.zoom;
217+
let dom_y = y + viewport_scroll.y as f32 / self.viewport.zoom;
218218

219219
// println!("Mouse move: ({}, {})", x, y);
220220
// println!("Unscaled: ({}, {})",);
@@ -338,15 +338,15 @@ impl<Doc: DocumentLike> View<Doc> {
338338
if ctrl | meta {
339339
match key_code {
340340
KeyCode::Equal => {
341-
*self.viewport.zoom_mut() += 0.1;
341+
self.viewport.zoom += 0.1;
342342
self.kick_dom_viewport();
343343
}
344344
KeyCode::Minus => {
345-
*self.viewport.zoom_mut() -= 0.1;
345+
self.viewport.zoom -= 0.1;
346346
self.kick_dom_viewport();
347347
}
348348
KeyCode::Digit0 => {
349-
*self.viewport.zoom_mut() = 1.0;
349+
self.viewport.zoom = 1.0;
350350
self.kick_dom_viewport();
351351
}
352352
_ => {}

0 commit comments

Comments
 (0)