Minor fix to graph widget

This commit is contained in:
Luke D. Jones
2024-03-12 22:06:56 +13:00
parent 5fd107df27
commit 69458a0595
3 changed files with 20 additions and 19 deletions

View File

@@ -38,11 +38,16 @@ export component PageFans inherits VerticalLayout {
y: 150px,
},
];
Text {
text: "WORK IN PROGRESS";
}
HorizontalLayout {
Graph {
// width: root.preferred-width;
// height: root.preferred-height;
nodes <=> root.nodes;
}
}
}

View File

@@ -3,10 +3,6 @@ import { Palette } from "std-widgets.slint";
export struct Node { x: length, y: length}
export component Graph inherits Rectangle {
Text {
text: "WORK IN PROGRESS";
}
preferred-height: 100%;
preferred-width: 100%;
pure callback verify_positions([Node], length, length) -> [Node];
@@ -56,9 +52,9 @@ export component Graph inherits Rectangle {
n.x = nodes[idx - 1].x + pad;
}
if n.y + self.height / 2 - self.mouse-y - self.pressed-y > nodes[idx + 1].y {
if n.y + self.height - self.mouse-y - self.pressed-y > nodes[idx + 1].y {
n.y = nodes[idx + 1].y - pad;
} else if n.y - self.mouse-y - self.pressed-y < nodes[idx - 1].y {
} else if n.y + self.height - self.mouse-y - self.pressed-y < nodes[idx - 1].y {
n.y = nodes[idx - 1].y + pad;
}
} else if idx == 0 {
@@ -68,9 +64,9 @@ export component Graph inherits Rectangle {
n.x = nodes[idx + 1].x - pad;
}
if n.y + self.height / 2 - self.mouse-y - self.pressed-y < 0.0 {
if n.y - self.mouse-y - self.pressed-y < 0.0 {
n.y = 1px;
} else if n.y + self.height / 2 - self.mouse-y - self.pressed-y > nodes[idx + 1].y {
} else if n.y + self.height - self.mouse-y - self.pressed-y > nodes[idx + 1].y {
n.y = nodes[idx + 1].y - pad;
}
} else if idx == nodes.length - 1 {
@@ -80,9 +76,9 @@ export component Graph inherits Rectangle {
n.x = nodes[idx - 1].x + pad;
}
if n.y + self.height / 2 - self.mouse-y - self.pressed-y > root.height {
if n.y - self.mouse-y - self.pressed-y > root.height {
n.y = root.height - 1px;
} else if n.y + self.height / 2 - self.mouse-y - self.pressed-y < nodes[idx - 1].y {
} else if n.y + self.height - self.mouse-y - self.pressed-y < nodes[idx - 1].y {
n.y = nodes[idx - 1].y + pad;
}
}