Work on some more stuff

This commit is contained in:
Michael Mikovsky
2024-11-27 11:57:08 -07:00
parent 7a39b610b5
commit 0658be825e
3 changed files with 74 additions and 44 deletions
+40 -16
View File
@@ -1,5 +1,5 @@
use eframe::epaint::Color32; use eframe::epaint::Color32;
use egui::Ui; use egui::{Id, Ui};
use egui_snarl::{InPin, OutPin}; use egui_snarl::{InPin, OutPin};
use egui_snarl::ui::{PinInfo, WireStyle}; use egui_snarl::ui::{PinInfo, WireStyle};
use crate::pane_manager::{Pane, PaneMode, PaneState, PsudoCreationContext}; use crate::pane_manager::{Pane, PaneMode, PaneState, PsudoCreationContext};
@@ -8,16 +8,20 @@ use crate::panes::pipeline_editor::Node;
#[derive(Clone, serde::Serialize, serde::Deserialize)] #[derive(Clone, serde::Serialize, serde::Deserialize)]
pub struct Constants { pub struct Constants {
vars: Vec<String>, vars: Vec<(String, String)>,
popup_open: bool, popup_open: bool,
uid: Id,
} }
#[typetag::serde] #[typetag::serde]
impl Node for Constants { impl Node for Constants {
fn new() -> Self { fn new() -> Self {
Self { let mut s = Self {
vars: Vec::new(), vars: Vec::new(),
popup_open: false, popup_open: false,
} uid: Id::new(rand::random::<u64>()),
};
s.vars.push(("VAR".to_string(), "Change Me".to_string()));
s
} }
fn get_name(&self) -> &str { fn get_name(&self) -> &str {
@@ -33,12 +37,13 @@ impl Node for Constants {
0 0
} }
fn outputs(&self) -> usize { fn outputs(&self) -> usize {
1 self.vars.len()
} }
fn show_input(&self, _pin: &InPin, _ui: &mut Ui, _scale: f32) -> PinInfo { fn show_input(&mut self, _pin: &InPin, _ui: &mut Ui, _scale: f32) -> PinInfo {
PinInfo::square() PinInfo::square()
} }
fn show_output(&self, _pin: &OutPin, _ui: &mut Ui, _scale: f32) -> PinInfo { fn show_output(&mut self, pin: &OutPin, ui: &mut Ui, _scale: f32) -> PinInfo {
ui.label(self.vars.iter().nth(pin.id.output).unwrap().0.clone());
PinInfo::square().with_fill(Color32::RED).with_wire_style(WireStyle::Bezier3) PinInfo::square().with_fill(Color32::RED).with_wire_style(WireStyle::Bezier3)
} }
fn can_rx(&self, _other: &Box<dyn Node>) -> bool { fn can_rx(&self, _other: &Box<dyn Node>) -> bool {
@@ -47,16 +52,35 @@ impl Node for Constants {
fn can_tx(&self, _other: &Box<dyn Node>) -> bool { fn can_tx(&self, _other: &Box<dyn Node>) -> bool {
true true
} }
fn context_menu(&self, ui: &mut Ui) { fn context_menu(&mut self, ui: &mut Ui) {
egui::Window::new("TEST").show(ui.ctx(), |ui| { // egui::Window::new("TEST").show(ui.ctx(), |ui| {
ui.heading("EEEEE"); // ui.heading("EEEEE");
}); // });
// if ui.button("Edit").clicked() { if ui.button("Edit").clicked() {
// self.popup_open = !self.popup_open; self.popup_open = !self.popup_open;
// } ui.close_menu();
}
} }
fn update(&self, ui: &mut Ui) { fn update(&mut self, ui: &mut Ui) {
if self.popup_open {
egui::Window::new("Edit - ".to_owned() + self.get_name()).id(self.uid).show(ui.ctx(), |ui| {
egui::Grid::new("my_grid").striped(true)
.max_col_width(9999.)
.show(ui, |ui| {
for (i, (var1, var2)) in &mut self.vars.iter().enumerate() {
if var1.is_empty() {
self.vars.remove()
}
ui.add(egui::TextEdit::singleline(var1));
ui.add(egui::TextEdit::singleline(var2));
ui.end_row();
}
});
if ui.button("ADD").clicked() {
self.vars.push(("VAR".to_string(), "Change Me".to_string()));
}
});
}
} }
} }
+6 -6
View File
@@ -122,7 +122,7 @@ impl PaneManager {
} }
ui.menu_button(self.panes[i].id.clone(), |ui| { ui.menu_button(self.panes[i].id.clone(), |ui| {
if ui.button("Center").clicked() { if ui.button(({ if self.panes[i].mode == PaneMode::Center { "*" } else { " " } }).to_owned() + "Center").clicked() {
for a in 0..len { for a in 0..len {
let pane2: &mut PaneState = &mut self.panes[a]; let pane2: &mut PaneState = &mut self.panes[a];
if pane2.mode == PaneMode::Center { if pane2.mode == PaneMode::Center {
@@ -132,23 +132,23 @@ impl PaneManager {
self.panes[i].mode = PaneMode::Center; self.panes[i].mode = PaneMode::Center;
ui.close_menu(); ui.close_menu();
} }
if ui.button("Windowed").clicked() { if ui.button(({ if self.panes[i].mode == PaneMode::Windowed { "*" } else { " " } }).to_owned() + "Window").clicked() {
self.panes[i].mode = PaneMode::Windowed; self.panes[i].mode = PaneMode::Windowed;
ui.close_menu(); ui.close_menu();
} }
if ui.button("Left").clicked() { if ui.button(({ if self.panes[i].mode == PaneMode::Left { "*" } else { " " } }).to_owned() + "Left").clicked() {
self.panes[i].mode = PaneMode::Left; self.panes[i].mode = PaneMode::Left;
ui.close_menu(); ui.close_menu();
} }
if ui.button("Right").clicked() { if ui.button(({ if self.panes[i].mode == PaneMode::Right { "*" } else { " " } }).to_owned() + "Right").clicked() {
self.panes[i].mode = PaneMode::Right; self.panes[i].mode = PaneMode::Right;
ui.close_menu(); ui.close_menu();
} }
if ui.button("Bottom").clicked() { if ui.button(({ if self.panes[i].mode == PaneMode::Bottom { "*" } else { " " } }).to_owned() + "Bottom").clicked() {
self.panes[i].mode = PaneMode::Bottom; self.panes[i].mode = PaneMode::Bottom;
ui.close_menu(); ui.close_menu();
} }
if ui.button("Hidden").clicked() { if ui.button(({ if self.panes[i].mode == PaneMode::Hidden { "*" } else { " " } }).to_owned() + "Hidden").clicked() {
self.panes[i].mode = PaneMode::Hidden; self.panes[i].mode = PaneMode::Hidden;
ui.close_menu(); ui.close_menu();
} }
+28 -22
View File
@@ -1,3 +1,4 @@
use eframe::emath::Rect;
use crate::pane_manager::{Pane, PaneMode, PaneState, PsudoCreationContext}; use crate::pane_manager::{Pane, PaneMode, PaneState, PsudoCreationContext};
@@ -148,12 +149,12 @@ pub trait Node {
fn duplicate(&self) -> Box<dyn Node>; fn duplicate(&self) -> Box<dyn Node>;
fn inputs(&self) -> usize; fn inputs(&self) -> usize;
fn outputs(&self) -> usize; fn outputs(&self) -> usize;
fn show_input(&self, pin: &InPin, ui: &mut Ui, scale: f32) -> PinInfo; fn show_input(&mut self, pin: &InPin, ui: &mut Ui, scale: f32) -> PinInfo;
fn show_output(&self, pin: &OutPin, ui: &mut Ui, scale: f32) -> PinInfo; fn show_output(&mut self, pin: &OutPin, ui: &mut Ui, scale: f32) -> PinInfo;
fn can_rx(&self, other: &Box<dyn Node>) -> bool; fn can_rx(&self, other: &Box<dyn Node>) -> bool;
fn can_tx(&self, other: &Box<dyn Node>) -> bool; fn can_tx(&self, other: &Box<dyn Node>) -> bool;
fn context_menu(&self, ui: &mut Ui); fn context_menu(&mut self, ui: &mut Ui);
fn update(&self, ui: &mut Ui); fn update(&mut self, ui: &mut Ui);
} }
#[derive(Clone, serde::Serialize, serde::Deserialize)] #[derive(Clone, serde::Serialize, serde::Deserialize)]
@@ -172,16 +173,16 @@ impl Node for Node1 {
fn outputs(&self) -> usize { fn outputs(&self) -> usize {
1 1
} }
fn show_input(&self, _pin: &InPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square() } fn show_input(&mut self, _pin: &InPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square() }
fn show_output(&self, _pin: &OutPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square().with_fill(Color32::RED).with_wire_style(WireStyle::Bezier3) } fn show_output(&mut self, _pin: &OutPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square().with_fill(Color32::RED).with_wire_style(WireStyle::Bezier3) }
fn can_rx(&self, _other: &Box<dyn Node>) -> bool { fn can_rx(&self, _other: &Box<dyn Node>) -> bool {
true true
} }
fn can_tx(&self, _other: &Box<dyn Node>) -> bool { fn can_tx(&self, _other: &Box<dyn Node>) -> bool {
true true
} }
fn context_menu(&self, ui: &mut Ui) { ui.label("Test!"); } fn context_menu(&mut self, ui: &mut Ui) { ui.label("Test!"); }
fn update(&self, ui: &mut Ui) {} fn update(&mut self, ui: &mut Ui) {}
} }
#[derive(Clone, serde::Serialize, serde::Deserialize)] #[derive(Clone, serde::Serialize, serde::Deserialize)]
@@ -200,16 +201,16 @@ impl Node for Node2 {
fn outputs(&self) -> usize { fn outputs(&self) -> usize {
1 1
} }
fn show_input(&self, _pin: &InPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square() } fn show_input(&mut self, _pin: &InPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square() }
fn show_output(&self, _pin: &OutPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square().with_fill(Color32::RED).with_wire_style(WireStyle::Bezier3) } fn show_output(&mut self, _pin: &OutPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square().with_fill(Color32::RED).with_wire_style(WireStyle::Bezier3) }
fn can_rx(&self, _other: &Box<dyn Node>) -> bool { fn can_rx(&self, _other: &Box<dyn Node>) -> bool {
true true
} }
fn can_tx(&self, _other: &Box<dyn Node>) -> bool { fn can_tx(&self, _other: &Box<dyn Node>) -> bool {
true true
} }
fn context_menu(&self, ui: &mut Ui) { ui.label("Test!"); } fn context_menu(&mut self, ui: &mut Ui) { ui.label("Test!"); }
fn update(&self, ui: &mut Ui) {} fn update(&mut self, ui: &mut Ui) {}
} }
#[derive(Clone, serde::Serialize, serde::Deserialize)] #[derive(Clone, serde::Serialize, serde::Deserialize)]
@@ -228,16 +229,16 @@ impl Node for crate::panes::pipeline_editor::Node3 {
fn outputs(&self) -> usize { fn outputs(&self) -> usize {
2 2
} }
fn show_input(&self, _pin: &InPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square() } fn show_input(&mut self, _pin: &InPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square() }
fn show_output(&self, _pin: &OutPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square().with_fill(Color32::RED).with_wire_style(WireStyle::Bezier3) } fn show_output(&mut self, _pin: &OutPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square().with_fill(Color32::RED).with_wire_style(WireStyle::Bezier3) }
fn can_rx(&self, _other: &Box<dyn Node>) -> bool { fn can_rx(&self, _other: &Box<dyn Node>) -> bool {
true true
} }
fn can_tx(&self, _other: &Box<dyn Node>) -> bool { fn can_tx(&self, _other: &Box<dyn Node>) -> bool {
true true
} }
fn context_menu(&self, ui: &mut Ui) { ui.label("Test!"); } fn context_menu(&mut self, ui: &mut Ui) { ui.label("Test!"); }
fn update(&self, ui: &mut Ui) {} fn update(&mut self, ui: &mut Ui) {}
} }
@@ -286,7 +287,7 @@ impl SnarlViewer<Box<dyn Node>> for NodeViewer {
snarl: &mut Snarl<Box<dyn Node>>, snarl: &mut Snarl<Box<dyn Node>>,
) -> PinInfo { ) -> PinInfo {
snarl snarl
.get_node(pin.id.node) .get_node_mut(pin.id.node)
.unwrap() .unwrap()
.show_input(pin, ui, scale) .show_input(pin, ui, scale)
} }
@@ -299,7 +300,7 @@ impl SnarlViewer<Box<dyn Node>> for NodeViewer {
snarl: &mut Snarl<Box<dyn Node>>, snarl: &mut Snarl<Box<dyn Node>>,
) -> PinInfo { ) -> PinInfo {
snarl snarl
.get_node(pin.id.node) .get_node_mut(pin.id.node)
.unwrap() .unwrap()
.show_output(pin, ui, scale) .show_output(pin, ui, scale)
} }
@@ -349,25 +350,30 @@ impl SnarlViewer<Box<dyn Node>> for NodeViewer {
snarl: &mut Snarl<Box<dyn Node + 'static>>, snarl: &mut Snarl<Box<dyn Node + 'static>>,
) { ) {
ui.label("Node menu"); ui.label("Node menu");
snarl.get_node_mut(nodeid).unwrap().context_menu(ui);
if ui.button("Remove").clicked() { if ui.button("Remove").clicked() {
snarl.remove_node(nodeid); snarl.remove_node(nodeid);
ui.close_menu(); ui.close_menu();
} else if ui.button("Duplicate").clicked() { } else if ui.button("Duplicate").clicked() {
snarl.insert_node(Pos2 {x:0.,y:0.}, snarl.get_node(nodeid).unwrap().duplicate()); let node = snarl.get_node_mut(nodeid).unwrap().duplicate();
snarl.insert_node(Pos2 {x:0.,y:0.}, node);
ui.close_menu(); ui.close_menu();
// }// else if ui.button("Remove All Connections").clicked() { // }// else if ui.button("Remove All Connections").clicked() {
// ui. // ui.
// ui.close_menu(); // ui.close_menu();
} else {
snarl.get_node(nodeid).unwrap().context_menu(ui);
} }
} }
fn has_body(&mut self, node: &Box<dyn Node>) -> bool {
true
}
fn show_body(&mut self, node: NodeId, inputs: &[InPin], outputs: &[OutPin], ui: &mut Ui, scale: f32, snarl: &mut Snarl<Box<dyn Node>>) { fn show_body(&mut self, node: NodeId, inputs: &[InPin], outputs: &[OutPin], ui: &mut Ui, scale: f32, snarl: &mut Snarl<Box<dyn Node>>) {
snarl.get_node(node).unwrap().update(ui); snarl.get_node_mut(node).unwrap().update(ui);
} }
} }
impl NodeViewer { impl NodeViewer {
pub fn add_node_menu(pos: Pos2, ui: &mut Ui, snarl: &mut Snarl<Box<dyn Node>>) { pub fn add_node_menu(pos: Pos2, ui: &mut Ui, snarl: &mut Snarl<Box<dyn Node>>) {
ui.label("Add node"); ui.label("Add node");