graphmanager: add a light mode

Add a light mode to display node with a
dashed style
This commit is contained in:
Stéphane Cerveau 2023-02-13 15:53:18 +01:00
parent 3f75581d60
commit cc42cdeaeb
3 changed files with 29 additions and 2 deletions

View file

@ -14,6 +14,10 @@ button.node-selected {
background: rgb(170, 255, 170);
}
button.node-light {
border-style: dashed;
}
button.port {
color: rgb(0, 0, 255);
border-width: 2px;
@ -44,4 +48,4 @@ button.port-always {
graphview {
background: #d0d2d4;
}
}

View file

@ -837,7 +837,8 @@ impl GraphView {
.attr("id", &node.id().to_string())
.attr("type", &node.node_type().unwrap().to_string())
.attr("pos_x", &node.position().0.to_string())
.attr("pos_y", &node.position().1.to_string()),
.attr("pos_y", &node.position().1.to_string())
.attr("light", &node.light().to_string()),
)?;
for port in node.ports().values() {
writer.write(
@ -938,6 +939,10 @@ impl GraphView {
let pos_y: &String = attrs
.get::<String>(&String::from("pos_y"))
.unwrap_or(&default_value);
let default_value = String::from("false");
let light: &String = attrs
.get::<String>(&String::from("light"))
.unwrap_or(&default_value);
let node = self.create_node_with_id(
id.parse::<u32>().unwrap(),
name,
@ -947,6 +952,7 @@ impl GraphView {
pos_x.parse::<f32>().unwrap(),
pos_y.parse::<f32>().unwrap(),
);
node.set_light(light.parse::<bool>().unwrap());
current_node = Some(node);
}
"Property" => {

View file

@ -62,6 +62,7 @@ mod imp {
// Properties are different from GObject properties
pub(super) properties: RefCell<HashMap<String, String>>,
pub(super) selected: Cell<bool>,
pub(super) light: Cell<bool>,
pub(super) position: Cell<(f32, f32)>,
}
@ -108,6 +109,7 @@ mod imp {
num_ports_out: Cell::new(0),
properties: RefCell::new(HashMap::new()),
selected: Cell::new(false),
light: Cell::new(false),
position: Cell::new((0.0, 0.0)),
}
}
@ -276,6 +278,21 @@ impl Node {
imp::Node::from_instance(self).position.get()
}
pub fn set_light(&self, light: bool) {
let self_ = imp::Node::from_instance(self);
self_.light.set(light);
if light {
self.add_css_class("node-light");
} else {
self.remove_css_class("node-light");
}
}
pub fn light(&self) -> bool {
let self_ = imp::Node::from_instance(self);
self_.light.get()
}
//Private
fn set_name(&self, name: &str) {