Skip to content

Commit 0a1b22b

Browse files
committed
add colored button for node state
1 parent 69a5a7b commit 0a1b22b

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

src/app.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,29 @@ impl NodeDataTrait for NodeData {
329329
}
330330
}
331331

332+
let outputs = &_graph[node_id].outputs;
333+
for (name, id) in outputs.iter() {
334+
let reg = user_state.outs_to_regs.get(id);
335+
let value = match reg {
336+
Some(reg) => user_state.simulation.register(*reg),
337+
None => false,
338+
};
339+
340+
let button = egui::Button::new(
341+
egui::RichText::new(format!("{}: {}", name, value)).color(
342+
match value {
343+
true => egui::Color32::BLACK,
344+
false => egui::Color32::WHITE,
345+
},
346+
),
347+
)
348+
.fill(match value {
349+
true => egui::Color32::GREEN,
350+
false => egui::Color32::RED,
351+
});
352+
ui.add(button);
353+
}
354+
332355
responses
333356
}
334357
}
@@ -527,18 +550,18 @@ impl eframe::App for NodeGraphExample {
527550
}
528551

529552
if changed {
530-
println!();
531-
println!("Gates: {:?}", self.user_state.gates);
532-
println!("Immediates: {:?}", self.user_state.immediates);
533-
println!("Regs: {:?}", self.user_state.outs_to_regs);
553+
// println!();
554+
// println!("Gates: {:?}", self.user_state.gates);
555+
// println!("Immediates: {:?}", self.user_state.immediates);
556+
// println!("Regs: {:?}", self.user_state.outs_to_regs);
534557

535558
self.user_state.simulation = self
536559
.user_state
537560
.compiler
538561
.compile(self.user_state.gates.values().collect::<Vec<_>>());
539562

540-
println!("Compiler: {:?}", self.user_state.compiler);
541-
println!("Simulation: {:?}", self.user_state.simulation);
563+
// println!("Compiler: {:?}", self.user_state.compiler);
564+
// println!("Simulation: {:?}", self.user_state.simulation);
542565

543566
let mut immediates: Vec<bool> =
544567
vec![false; self.user_state.compiler.immediate_count];
@@ -552,7 +575,7 @@ impl eframe::App for NodeGraphExample {
552575
});
553576

554577
self.user_state.simulation.run(&immediates);
555-
println!("Ran: {:?}", self.user_state.simulation);
578+
// println!("Ran: {:?}", self.user_state.simulation);
556579
}
557580

558581
for node_response in graph_response.node_responses {

0 commit comments

Comments
 (0)