Skip to content

Commit e2d4c9c

Browse files
committed
run cargo fmt
1 parent 34f9e56 commit e2d4c9c

11 files changed

+194
-115
lines changed

src/application/action.rs

+30-16
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,30 @@ impl Action {
165165
app.imp().rerender_editor();
166166
}
167167
Self::AddSegment(plot_provider, segment_id, segment, index) => {
168-
*index = plot_provider.with_mut(|plot|
169-
if let Some(root) = plot.get_connection_mut(segment_id.connection_id()).and_then(|c| c.get_segment_mut(segment_id.location())) {
170-
let index = root.add_segment(segment.clone());
168+
*index = plot_provider
169+
.with_mut(|plot| {
170+
if let Some(root) = plot
171+
.get_connection_mut(segment_id.connection_id())
172+
.and_then(|c| c.get_segment_mut(segment_id.location()))
173+
{
174+
let index = root.add_segment(segment.clone());
171175

172-
if let Segment::Block(block_id, port) = *segment && let Some(block) = plot.get_block_mut(block_id) {
173-
block.set_connection(Connector::Input(port), Some(*segment_id.connection_id()));
174-
plot.add_block_to_update(block_id);
175-
}
176+
if let Segment::Block(block_id, port) = *segment
177+
&& let Some(block) = plot.get_block_mut(block_id)
178+
{
179+
block.set_connection(
180+
Connector::Input(port),
181+
Some(*segment_id.connection_id()),
182+
);
183+
plot.add_block_to_update(block_id);
184+
}
176185

177-
index
178-
}
179-
else {
180-
None
181-
}
182-
).flatten();
186+
index
187+
} else {
188+
None
189+
}
190+
})
191+
.flatten();
183192
app.imp().rerender_editor();
184193
}
185194
Self::ChangeBorderColor(plot_provider, new_color, block_ids, old_colors) => {
@@ -304,12 +313,17 @@ impl Action {
304313
}
305314
Self::AddSegment(plot_provider, segment_id, segment, id) => {
306315
plot_provider.with_mut(|plot| {
307-
if let Some(root) = plot.get_connection_mut(segment_id.connection_id()).and_then(|c| c.get_segment_mut(segment_id.location())) &&
308-
let Some(id) = id {
316+
if let Some(root) = plot
317+
.get_connection_mut(segment_id.connection_id())
318+
.and_then(|c| c.get_segment_mut(segment_id.location()))
319+
&& let Some(id) = id
320+
{
309321
root.remove_segment(id);
310322
}
311323

312-
if let Segment::Block(block_id, port) = *segment && let Some(block) = plot.get_block_mut(block_id) {
324+
if let Segment::Block(block_id, port) = *segment
325+
&& let Some(block) = plot.get_block_mut(block_id)
326+
{
313327
block.set_connection(Connector::Input(port), None);
314328
plot.add_block_to_update(block_id);
315329
}

src/application/clipboard.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,33 @@ impl From<&Plot> for Clipboard {
5353
fn from(plot: &Plot) -> Self {
5454
match plot.selection() {
5555
Selection::Single(Selectable::Block(block_id), _) => {
56-
if let Some(block) = plot.get_block(*block_id) && !block.unique() {
56+
if let Some(block) = plot.get_block(*block_id)
57+
&& !block.unique()
58+
{
5759
let mut block = block.clone();
5860
block.prepare_copying(());
5961
Self::Blocks(vec![block], Vec::new())
60-
}
61-
else {
62+
} else {
6263
Self::Empty
6364
}
64-
},
65+
}
6566
Selection::Many(blocks) => {
6667
let selection = blocks
6768
.iter()
6869
.filter_map(|selectable| selectable.block_id())
69-
.filter_map(|block_id| plot.get_block(block_id).filter(|block| !block.unique()));
70-
let block_ids = selection.clone().map(|block| block.id()).collect::<Vec<BlockID>>();
70+
.filter_map(|block_id| {
71+
plot.get_block(block_id).filter(|block| !block.unique())
72+
});
73+
let block_ids = selection
74+
.clone()
75+
.map(|block| block.id())
76+
.collect::<Vec<BlockID>>();
7177
let blocks = selection.cloned().collect::<Vec<Block>>();
7278
let mut data = (blocks, Vec::new());
7379
data.prepare_copying((plot, block_ids));
7480
Self::Blocks(data.0, data.1)
75-
},
76-
_ => Self::Empty
81+
}
82+
_ => Self::Empty,
7783
}
7884
}
7985
}

src/application/gactions.rs

+27-14
Original file line numberDiff line numberDiff line change
@@ -273,20 +273,33 @@ impl Application {
273273

274274
fn gaction_delete_block(self, _: &gio::SimpleAction, _: Option<&glib::Variant>) {
275275
if let Some(plot_provider) = self.imp().current_plot() {
276-
let (blocks, connections) = plot_provider.with_mut(|plot| (
277-
plot.selected().iter().filter_map(|selected| {
278-
match selected {
279-
Selectable::Block(id) if let Some(block) = plot.get_block(*id) => Some(block.to_owned()),
280-
_ => None
281-
}
282-
}).collect(),
283-
plot.selected().iter().filter_map(|selected| {
284-
match selected {
285-
Selectable::Waypoint(id) if let Some(connection) = plot.get_connection(id.connection_id()) => Some(connection.to_owned()),
286-
_ => None
287-
}
288-
}).collect()
289-
)).unwrap_or_default();
276+
let (blocks, connections) = plot_provider
277+
.with_mut(|plot| {
278+
(
279+
plot.selected()
280+
.iter()
281+
.filter_map(|selected| match selected {
282+
Selectable::Block(id) if let Some(block) = plot.get_block(*id) => {
283+
Some(block.to_owned())
284+
}
285+
_ => None,
286+
})
287+
.collect(),
288+
plot.selected()
289+
.iter()
290+
.filter_map(|selected| match selected {
291+
Selectable::Waypoint(id)
292+
if let Some(connection) =
293+
plot.get_connection(id.connection_id()) =>
294+
{
295+
Some(connection.to_owned())
296+
}
297+
_ => None,
298+
})
299+
.collect(),
300+
)
301+
})
302+
.unwrap_or_default();
290303
self.new_action(Action::DeleteSelection(
291304
plot_provider,
292305
blocks,

src/application/template.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,13 @@ impl ApplicationTemplate {
187187
}
188188

189189
pub fn generate_clipboard(&self) -> Clipboard {
190-
if let Some(selected) = self.with_current_plot(|plot| !matches!(plot.selection(), Selection::None)) && selected {
191-
self.with_current_plot(|plot| Clipboard::from(plot)).unwrap_or_default()
192-
}
193-
else {
190+
if let Some(selected) =
191+
self.with_current_plot(|plot| !matches!(plot.selection(), Selection::None))
192+
&& selected
193+
{
194+
self.with_current_plot(|plot| Clipboard::from(plot))
195+
.unwrap_or_default()
196+
} else {
194197
Clipboard::Empty
195198
}
196199
}

src/simulator/block.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ impl Block {
9595
}
9696

9797
pub fn set_color(&mut self, mut color: Option<Color>) {
98-
if let Some(c) = color && c == unsafe { COLOR_THEME.border_color } {
98+
if let Some(c) = color
99+
&& c == unsafe { COLOR_THEME.border_color }
100+
{
99101
color = None
100102
}
101103

src/simulator/modules.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,23 @@ impl Module {
156156
project: &mut Project,
157157
call_stack: &mut HashSet<String>,
158158
) -> SimResult<u128> {
159-
let outputs =
160-
if self.builtin && let Some(builtin) = BUILTINS.get(self.name.as_str()) {
159+
let outputs = if self.builtin
160+
&& let Some(builtin) = BUILTINS.get(self.name.as_str())
161+
{
161162
builtin.simulate(inputs, instance)
162-
}
163-
else {
163+
} else {
164164
if call_stack.contains(&self.name) {
165-
return Err(format!("Recursion detected; Block of module \"{}\" is already on the call stack.", self.name))
165+
return Err(format!(
166+
"Recursion detected; Block of module \"{}\" is already on the call stack.",
167+
self.name
168+
));
166169
}
167170
call_stack.insert(self.name.clone());
168171

169-
let custom_data = self.custom_data.as_mut().expect("cannot simulate custom module without correct data");
172+
let custom_data = self
173+
.custom_data
174+
.as_mut()
175+
.expect("cannot simulate custom module without correct data");
170176
let plot = &mut custom_data.plot;
171177

172178
instance.state().apply(plot);
@@ -184,7 +190,10 @@ impl Module {
184190
input.set_passthrough(true);
185191
}
186192

187-
let outputs = plot.get_block(custom_data.output_block).map(|block| block.bytes()).unwrap_or(0);
193+
let outputs = plot
194+
.get_block(custom_data.output_block)
195+
.map(|block| block.bytes())
196+
.unwrap_or(0);
188197
let state = PlotState::from(plot);
189198
instance.set_state(State::Inherit(state));
190199

src/simulator/plot.rs

+30-18
Original file line numberDiff line numberDiff line change
@@ -372,31 +372,43 @@ impl SelectionField for Plot {
372372

373373
fn unhighlight(&mut self) {
374374
match self.selection.clone() {
375-
Selection::Single(item, _) => {
376-
match item {
377-
Selectable::Block(id) if let Some(block) = self.get_block_mut(id) => block.set_highlighted(false),
378-
Selectable::Waypoint(id) if let Some(waypoint) = self.get_connection_mut(id.connection_id())
379-
.and_then(|c| c.get_segment_mut(id.location())) =>
380-
waypoint.set_highlighted(false),
381-
_ => ()
375+
Selection::Single(item, _) => match item {
376+
Selectable::Block(id) if let Some(block) = self.get_block_mut(id) => {
377+
block.set_highlighted(false)
382378
}
379+
Selectable::Waypoint(id)
380+
if let Some(waypoint) = self
381+
.get_connection_mut(id.connection_id())
382+
.and_then(|c| c.get_segment_mut(id.location())) =>
383+
{
384+
waypoint.set_highlighted(false)
385+
}
386+
_ => (),
383387
},
384388
Selection::Many(ids) => {
385-
ids.iter().for_each(|item| {
386-
match item {
387-
Selectable::Block(id) if let Some(block) = self.get_block_mut(*id) => block.set_highlighted(false),
388-
Selectable::Waypoint(id) if let Some(waypoint) = self.get_connection_mut(id.connection_id())
389-
.and_then(|c| c.get_segment_mut(id.location())) =>
390-
waypoint.set_highlighted(false),
391-
_ => ()
389+
ids.iter().for_each(|item| match item {
390+
Selectable::Block(id) if let Some(block) = self.get_block_mut(*id) => {
391+
block.set_highlighted(false)
392+
}
393+
Selectable::Waypoint(id)
394+
if let Some(waypoint) = self
395+
.get_connection_mut(id.connection_id())
396+
.and_then(|c| c.get_segment_mut(id.location())) =>
397+
{
398+
waypoint.set_highlighted(false)
392399
}
400+
_ => (),
393401
});
394-
},
402+
}
395403
Selection::Area(_, _) => {
396-
self.blocks_mut().iter_mut().for_each(|(_, v)| v.set_highlighted(false));
397-
self.connections_mut().iter_mut().for_each(|(_, c)| c.for_each_mut_segment(|segment| segment.set_highlighted(false)))
404+
self.blocks_mut()
405+
.iter_mut()
406+
.for_each(|(_, v)| v.set_highlighted(false));
407+
self.connections_mut().iter_mut().for_each(|(_, c)| {
408+
c.for_each_mut_segment(|segment| segment.set_highlighted(false))
409+
})
398410
}
399-
_ => ()
411+
_ => (),
400412
}
401413

402414
self.selection = Selection::None

src/ui/circuit_view.rs

+40-27
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,10 @@ impl CircuitViewTemplate {
422422
match selection {
423423
Some(Selection::MoveBlock(block)) => {
424424
let app = self.application.borrow();
425-
app.new_action(Action::NewBlock(self.plot_provider.borrow().clone(), *block));
425+
app.new_action(Action::NewBlock(
426+
self.plot_provider.borrow().clone(),
427+
*block,
428+
));
426429
let window = app.imp().window().borrow();
427430
window.as_ref().unwrap().module_list().unselect_items();
428431
}
@@ -593,21 +596,26 @@ impl CircuitViewTemplate {
593596
}
594597
}
595598
Selection::Connection(ConnectionSource::Block(origin_id, output), _, position) => {
596-
let connection = plot_provider.with_mut(|plot| {
597-
plot.set_selection(Selection::None);
598-
599-
if let Some(block_id) = plot.get_block_at(position) &&
600-
let Some(block) = plot.get_block(block_id) &&
601-
let Some(i) = block.position_on_connection(position, true) {
602-
603-
block.connection(Connector::Input(i)).is_none().then(||
604-
Connection::new_basic(origin_id, output, block_id, i )
605-
)
606-
}
607-
else {
608-
Some(Connection::new(Port::Output(origin_id, output), vec![Segment::Waypoint(HashMap::new(), position, false)]))
609-
}
610-
}).flatten();
599+
let connection = plot_provider
600+
.with_mut(|plot| {
601+
plot.set_selection(Selection::None);
602+
603+
if let Some(block_id) = plot.get_block_at(position)
604+
&& let Some(block) = plot.get_block(block_id)
605+
&& let Some(i) = block.position_on_connection(position, true)
606+
{
607+
block
608+
.connection(Connector::Input(i))
609+
.is_none()
610+
.then(|| Connection::new_basic(origin_id, output, block_id, i))
611+
} else {
612+
Some(Connection::new(
613+
Port::Output(origin_id, output),
614+
vec![Segment::Waypoint(HashMap::new(), position, false)],
615+
))
616+
}
617+
})
618+
.flatten();
611619

612620
if let Some(connection) = connection {
613621
self.application
@@ -618,17 +626,22 @@ impl CircuitViewTemplate {
618626
self.drawing_area.queue_draw()
619627
}
620628
Selection::Connection(ConnectionSource::Waypoint(segment_id), _, position) => {
621-
let segment = plot_provider.with_mut(|plot| {
622-
plot.set_selection(Selection::None);
623-
if let Some(block_id) = plot.get_block_at(position) &&
624-
let Some(block) = plot.get_block(block_id) &&
625-
let Some(i) = block.position_on_connection(position, true) {
626-
block.connection(Connector::Input(i)).is_none().then_some(Segment::Block(block_id, i))
627-
}
628-
else {
629-
Some(Segment::Waypoint(HashMap::new(), position, false))
630-
}
631-
}).flatten();
629+
let segment = plot_provider
630+
.with_mut(|plot| {
631+
plot.set_selection(Selection::None);
632+
if let Some(block_id) = plot.get_block_at(position)
633+
&& let Some(block) = plot.get_block(block_id)
634+
&& let Some(i) = block.position_on_connection(position, true)
635+
{
636+
block
637+
.connection(Connector::Input(i))
638+
.is_none()
639+
.then_some(Segment::Block(block_id, i))
640+
} else {
641+
Some(Segment::Waypoint(HashMap::new(), position, false))
642+
}
643+
})
644+
.flatten();
632645

633646
if let Some(segment) = segment {
634647
self.application.borrow().new_action(Action::AddSegment(

src/ui/dialogs.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,18 @@ pub async fn select_border_color(app: Application, window: gtk::Window, _data: (
181181
let answer = dialog.run_future().await;
182182
dialog.close();
183183

184-
if answer == ResponseType::Ok && let Some(plot_provider) = app.imp().current_plot() && let Some(block_ids) = plot_provider.with_mut(|plot| plot.selection().blocks()) {
184+
if answer == ResponseType::Ok
185+
&& let Some(plot_provider) = app.imp().current_plot()
186+
&& let Some(block_ids) = plot_provider.with_mut(|plot| plot.selection().blocks())
187+
{
185188
let color = color_button.rgba().into_color();
186189
println!("here");
187-
app.new_action(Action::ChangeBorderColor(plot_provider, color, block_ids, vec![]));
190+
app.new_action(Action::ChangeBorderColor(
191+
plot_provider,
192+
color,
193+
block_ids,
194+
vec![],
195+
));
188196
}
189197
}
190198

0 commit comments

Comments
 (0)