mirror of
https://github.com/penpot/penpot.git
synced 2025-07-18 19:17:12 +02:00
* 🔧 Fix lint script (rust) * 🔧 Temporarily add clippy rules to ignore so lint script passes * 💄 Fix clippy rule crate_in_macro_def * 💄 Fix clippy rule redundant-static-lifetimes * 💄 Fix clippy rule unnecessary_cast * 💄 Fix clippy rule nonminimal_bool * 💄 Fix clippy rule redundant_pattern_matching * 💄 Fix clippy rule assign_op_pattern * 💄 Fix clippy rule needless_lifetimes * 💄 Fix clippy rule for_kv_map * 💄 Fix clippy rule ptr_arg * 💄 Fix clippy rule match_like_matches_macro * 💄 Fix clippy rule macro_metavars_in_unsafe * 💄 Fix clippy rule map_clone * 💄 Fix clippy rule wrong_self_convention * 💄 Fix clippy rule vec_box * 💄 Fix clippy rule useless_format * 💄 Fix clippy rule unwrap_or_default * 💄 Fix clippy rule unused_unit * 💄 Fix clippy rule unnecessary_to_owned * 💄 Fix clippy rule too_many_arguments * 💄 Fix clippy rule slow_vector_initialization * 💄 Fix clippy rule single_match * 💄 Fix clippy rule redundant_field_names * 💄 Fix clippy rule rendudant_closure * 💄 Fix clippy rule needless_return * 💄 Fix clippy rule needless_range_loop * 💄 Fix clippy rule needless_borrows_for_generic_args * 💄 Fix clippy rule needless-borrow * 💄 Fix clippy rule missing_transmute_annotations * 💄 Fix clippy rule map_entry * 💄 Fix clippy rule manual_map * 💄 Fix clippy rule len_zero * 💄 Fix clippy rule from_over_into * 💄 Fix clippy rule field_reassign_with_default * 💄 Fix clippy rule enum_variant_names * 💄 Fix clippy rule derivable_impls * 💄 Fix clippy rule clone_on_copy * 💄 Fix clippy rule box_collection * 🔧 Make lint script also check test config target * 🔧 Remove cargo-watch as a lib dependency * 💄 Fix clippy rule for join_bounds * 🔧 Fix lint script return code --------- Co-authored-by: alonso.torres <alonso.torres@kaleidos.net>
59 lines
1.2 KiB
Rust
59 lines
1.2 KiB
Rust
use skia_safe::Rect;
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
pub(crate) struct Viewbox {
|
|
pub pan_x: f32,
|
|
pub pan_y: f32,
|
|
pub width: f32,
|
|
pub height: f32,
|
|
pub zoom: f32,
|
|
pub area: Rect,
|
|
}
|
|
|
|
impl Default for Viewbox {
|
|
fn default() -> Self {
|
|
Self {
|
|
pan_x: 0.,
|
|
pan_y: 0.,
|
|
width: 0.0,
|
|
height: 0.0,
|
|
zoom: 1.0,
|
|
area: Rect::new_empty(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Viewbox {
|
|
pub fn new(width: f32, height: f32) -> Self {
|
|
let area = Rect::from_xywh(0., 0., width, height);
|
|
Self {
|
|
width,
|
|
height,
|
|
area,
|
|
..Self::default()
|
|
}
|
|
}
|
|
|
|
pub fn set_all(&mut self, zoom: f32, pan_x: f32, pan_y: f32) {
|
|
self.pan_x = pan_x;
|
|
self.pan_y = pan_y;
|
|
self.zoom = zoom;
|
|
self.area.set_xywh(
|
|
-self.pan_x,
|
|
-self.pan_y,
|
|
self.width / self.zoom,
|
|
self.height / self.zoom,
|
|
);
|
|
}
|
|
|
|
pub fn set_wh(&mut self, width: f32, height: f32) {
|
|
self.width = width;
|
|
self.height = height;
|
|
self.area
|
|
.set_wh(self.width / self.zoom, self.height / self.zoom);
|
|
}
|
|
|
|
pub fn zoom(&self) -> f32 {
|
|
self.zoom
|
|
}
|
|
}
|