Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlcctrlv committed Jan 14, 2022
1 parent 98483b5 commit 7a06587
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 37 deletions.
4 changes: 3 additions & 1 deletion src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ impl Editor {
static mut WARNED_HISTORY: bool = false;
unsafe {
if !WARNED_HISTORY {
log::debug!("Used dangerous function: editor.with_active_layer_mut_no_history(|layer|…)");
log::debug!(
"Used dangerous function: editor.with_active_layer_mut_no_history(|layer|…)"
);
}
WARNED_HISTORY = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/editor/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use glifrenderer::constants::{POINT_RADIUS, POINT_STROKE_THICKNESS};
use skulpin::skia_safe::Contains;
use skulpin::skia_safe::Point as SkPoint;
use skulpin::skia_safe::Rect as SkRect;
use MFEKmath::{Bezier, Piecewise, Primitive as MathPrimitive, rect::FlipIfRequired as _};
use MFEKmath::{rect::FlipIfRequired as _, Bezier, Piecewise, Primitive as MathPrimitive};

use super::Editor;
use crate::util::MFEKGlifPointData;
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::editor::{
events::{EditorEvent, IOEventType, MouseEventType},
Editor,
};
use crate::tools::ToolEnum;
use crate::tools::zoom::{zoom_in_factor, zoom_out_factor};
use crate::tools::ToolEnum;
use crate::user_interface::mouse_input::MouseInfo;
use crate::user_interface::{ImguiManager, Interface};

Expand Down
8 changes: 3 additions & 5 deletions src/tool_behaviors/draw_pivot.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use super::prelude::*;
use glifrenderer::{
constants::{OUTLINE_STROKE, OUTLINE_STROKE_THICKNESS},
};
use glifrenderer::constants::{OUTLINE_STROKE, OUTLINE_STROKE_THICKNESS};

#[derive(Clone, Debug)]
pub struct DrawPivot {
Expand Down Expand Up @@ -43,12 +41,12 @@ impl DrawPivot {
fn mouse_pressed(&mut self, _v: &Editor, _i: &Interface, mouse_info: MouseInfo) {
if let Some(cm) = self.command_mod {
if cm != mouse_info.modifiers {
return
return;
}
}

if self.button != mouse_info.button {
return
return;
}

self.pivot_point = Some(mouse_info.position);
Expand Down
2 changes: 1 addition & 1 deletion src/tool_behaviors/pan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ impl ToolBehavior for PanBehavior {
_ => {},
}
}
}
}
2 changes: 1 addition & 1 deletion src/tools/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub use std::cell::RefCell;
pub use std::mem;

//UI
pub use crate::user_interface::gui;
pub use crate::command::CommandMod;
pub use crate::user_interface::gui;
pub use crate::user_interface::{Interface, MouseInfo};
pub use imgui::Ui;
pub use sdl2::mouse::MouseButton;
6 changes: 3 additions & 3 deletions src/tools/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use glifparser::outline::Reverse as _;
use MFEKmath::Vector;

use crate::tool_behaviors::{
draw_pivot::DrawPivot, move_handle::MoveHandle, move_point::MovePoint, pan::PanBehavior, selection_box::SelectionBox,
zoom_scroll::ZoomScroll,
draw_pivot::DrawPivot, move_handle::MoveHandle, move_point::MovePoint, pan::PanBehavior,
selection_box::SelectionBox, zoom_scroll::ZoomScroll,
};

mod dialog;
Expand All @@ -21,7 +21,7 @@ mod dialog;
#[derive(Clone, Debug, Default)]
pub struct Select {
pivot_point: Option<(f32, f32)>,
draw_pivot: DrawPivot,
draw_pivot: DrawPivot,
}

impl Tool for Select {
Expand Down
70 changes: 46 additions & 24 deletions src/tools/shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ use crate::tool_behaviors::selection_box::SelectionBox;
use crate::user_interface::{self, Interface};

use float_cmp::ApproxEq;
use glifparser::outline::{Reverse, skia::FromSkiaPath as _, FromKurbo as _};
use glifparser::outline::{skia::FromSkiaPath as _, FromKurbo as _, Reverse};
use glifparser::{glif::MFEKContour, Outline};
use imgui;
use kurbo;
use kurbo::Shape as _;
use num;
use num_derive::FromPrimitive;
use skulpin::skia_safe::{
Matrix, Path, PathDirection, PathEffect, StrokeRec,
};
use skulpin::skia_safe::{Matrix, Path, PathDirection, PathEffect, StrokeRec};

impl Tool for Shapes {
fn event(&mut self, v: &mut Editor, _i: &mut Interface, event: EditorEvent) {
Expand Down Expand Up @@ -51,19 +49,19 @@ impl Tool for Shapes {

// Do not modify w/o modifying ShapeType prev/next impl's!
#[derive(Clone, Copy, derive_more::Display, Debug, PartialEq, FromPrimitive)]
#[display(fmt="{}")]
#[display(fmt = "{}")]
pub enum ShapeType {
#[display(fmt="circle")]
#[display(fmt = "circle")]
Circle,
#[display(fmt="oval")]
#[display(fmt = "oval")]
Oval,
#[display(fmt="rectangle")]
#[display(fmt = "rectangle")]
Rectangle,
#[display(fmt="rounded rectangle")]
#[display(fmt = "rounded rectangle")]
RoundedRectangle,
#[display(fmt="polygon")]
#[display(fmt = "polygon")]
Polygon,
#[display(fmt="star")]
#[display(fmt = "star")]
Star,
}

Expand Down Expand Up @@ -105,7 +103,12 @@ pub struct Shapes {
}

#[derive(Copy, Clone, Debug, derive_more::Display)]
#[display(fmt="{}{}{}", "self.display_sides()", "self.display_angle()", "self.display_radius()")]
#[display(
fmt = "{}{}{}",
"self.display_sides()",
"self.display_angle()",
"self.display_radius()"
)]
pub struct ShapeData {
polygon_angle: f32,
polygon_sides: u16,
Expand All @@ -121,7 +124,12 @@ impl ShapeData {
format!("{}-sided", self.polygon_sides)
}
fn display_radius(&self) -> String {
Some(self.polygon_radius).into_iter().filter(|f|f.is_normal() && !f.is_nan() && !f.approx_eq(0.0f32, (f32::EPSILON, 10))).next().map(|f|format!(" (rounded w/radii {})", f)).unwrap_or(String::new())
Some(self.polygon_radius)
.into_iter()
.filter(|f| f.is_normal() && !f.is_nan() && !f.approx_eq(0.0f32, (f32::EPSILON, 10)))
.next()
.map(|f| format!(" (rounded w/radii {})", f))
.unwrap_or(String::new())
}
}

Expand Down Expand Up @@ -178,11 +186,7 @@ impl Shapes {
&mut self.stype,
ShapeType::Polygon,
);
ui.radio_button(
imgui::im_str!("Star"),
&mut self.stype,
ShapeType::Star,
);
ui.radio_button(imgui::im_str!("Star"), &mut self.stype, ShapeType::Star);

match self.stype {
ShapeType::RoundedRectangle => {
Expand All @@ -197,7 +201,12 @@ impl Shapes {
imgui::Slider::new(imgui::im_str!("Roundness"))
.range(0f32..=1000f32)
.build(ui, &mut self.sdata.polygon_radius);
user_interface::util::imgui_decimal_text_field("Angle", ui, &mut self.sdata.polygon_angle, None);
user_interface::util::imgui_decimal_text_field(
"Angle",
ui,
&mut self.sdata.polygon_angle,
None,
);
}
_ => (),
}
Expand All @@ -209,7 +218,7 @@ struct ShapeDrawer {
mouse_info: MouseInfo,
from: (f32, f32),
sdata: ShapeData,
corners: Option<((f32, f32), (f32, f32))>
corners: Option<((f32, f32), (f32, f32))>,
}

fn shape_direction(cx: f32) -> PathDirection {
Expand All @@ -233,7 +242,11 @@ impl ShapeDrawer {
let (cx, _cy, radius) = self.calculate_radius();
let direction = shape_direction(cx);
let kp_center = kurbo::Point::new(self.from.0 as f64, self.from.1 as f64);
let circle = kurbo::BezPath::from_vec(kurbo::Circle::new(kp_center, radius as f64).path_elements(1.0).collect());
let circle = kurbo::BezPath::from_vec(
kurbo::Circle::new(kp_center, radius as f64)
.path_elements(1.0)
.collect(),
);
let mut gcircle = Outline::from_kurbo(&circle);
if direction == PathDirection::CCW {
gcircle.reverse();
Expand Down Expand Up @@ -296,7 +309,9 @@ impl ShapeDrawer {
};

for (i, side) in range_iter {
if i == 0 { continue }
if i == 0 {
continue;
}
let pathbuild_func = if i == 1 { Path::move_to } else { Path::line_to };
pathbuild_func(
&mut path,
Expand Down Expand Up @@ -335,10 +350,17 @@ impl ShapeDrawer {
rect = kurbo::Rect::from_center_size(rect.origin(), (size, -size));
}
let (cx, _, _) = self.calculate_radius();
self.corners = Some(((rect.min_x() as f32, rect.min_y() as f32), (rect.max_x() as f32, rect.max_y() as f32)));
self.corners = Some((
(rect.min_x() as f32, rect.min_y() as f32),
(rect.max_x() as f32, rect.max_y() as f32),
));
let path = kurbo::BezPath::from_vec(match stype {
ShapeType::Oval => kurbo::Ellipse::from_rect(rect).path_elements(1.0).collect(),
ShapeType::RoundedRectangle => kurbo::RoundedRect::from_rect(rect, self.sdata.rrect_radius as f64).path_elements(1.0).collect(),
ShapeType::RoundedRectangle => {
kurbo::RoundedRect::from_rect(rect, self.sdata.rrect_radius as f64)
.path_elements(1.0)
.collect()
}
ShapeType::Rectangle => {
self.corners = None; // pointless
rect.path_elements(1.0).collect()
Expand Down

0 comments on commit 7a06587

Please sign in to comment.