Skip to content
Snippets Groups Projects
Commit 664441f6 authored by Alberto Nidasio's avatar Alberto Nidasio Committed by Federico Lolli
Browse files

Fixed elements placing position

parent 8548eee3
No related branches found
No related tags found
1 merge request!15Integrated P&ID Editor and Configurable Pane
...@@ -242,8 +242,10 @@ impl PidPane { ...@@ -242,8 +242,10 @@ impl PidPane {
ui.menu_button("Symbols", |ui| { ui.menu_button("Symbols", |ui| {
for symbol in Symbol::iter() { for symbol in Symbol::iter() {
if ui.button(symbol.to_string()).clicked() { if ui.button(symbol.to_string()).clicked() {
self.elements self.elements.push(Element::new(
.push(Element::new(self.grid.screen_to_grid(pointer_pos), symbol)); self.grid.screen_to_grid(pointer_pos).round(),
symbol,
));
self.action.take(); self.action.take();
ui.close_menu(); ui.close_menu();
} }
......
...@@ -25,9 +25,9 @@ pub struct Element { ...@@ -25,9 +25,9 @@ pub struct Element {
} }
impl Element { impl Element {
pub fn new(position: Vec2, symbol: Symbol) -> Self { pub fn new(center: Vec2, symbol: Symbol) -> Self {
Self { Self {
position, position: center - symbol.size() / 2.0,
rotation: 0.0, rotation: 0.0,
anchor_points: symbol.anchor_points(), anchor_points: symbol.anchor_points(),
symbol, symbol,
...@@ -54,7 +54,7 @@ impl Element { ...@@ -54,7 +54,7 @@ impl Element {
let rotm_e_to_g = Mat2::from_angle(self.rotation); let rotm_e_to_g = Mat2::from_angle(self.rotation);
// Center in grid's frame // Center in grid's frame
let center_g = rotm_e_to_g * self.symbol.size() / 2.0; let center_g = rotm_e_to_g * self.size() / 2.0;
self.position = p_g - center_g; self.position = p_g - center_g;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment