From e8f6309683dd4ea07346da14cbe91859b5382a8e Mon Sep 17 00:00:00 2001 From: yesoer Date: Mon, 11 Dec 2023 02:54:29 +0100 Subject: [PATCH 1/2] fix(diagram): centralize nodes --- fyne-gui/NetworkDiagram.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fyne-gui/NetworkDiagram.go b/fyne-gui/NetworkDiagram.go index 854af15..72d1967 100644 --- a/fyne-gui/NetworkDiagram.go +++ b/fyne-gui/NetworkDiagram.go @@ -190,12 +190,12 @@ func (networkDiag *NetworkDiagram) refreshNodes( // initial pass diagWidth := diag.Size().Width if diagWidth == 0 { - diagWidth = 800 + diagWidth = InitialWindowSize.Width } diagHeight := diag.Size().Height if diagHeight == 0 { - diagHeight = 1200 + diagHeight = InitialWindowSize.Height } ratiow := diagWidth / 100 From 2e476b4fa8c9bf1f49aa4d1cea883173f8a1b0ba Mon Sep 17 00:00:00 2001 From: yesoer Date: Sat, 20 Jan 2024 20:06:54 +0100 Subject: [PATCH 2/2] fix(network-diagram): node positions - anchor nodes at their center instead of upper left corner - ideally we only want to halve the initial window size --- fyne-gui/NetworkDiagram.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fyne-gui/NetworkDiagram.go b/fyne-gui/NetworkDiagram.go index 72d1967..5eaba97 100644 --- a/fyne-gui/NetworkDiagram.go +++ b/fyne-gui/NetworkDiagram.go @@ -188,26 +188,31 @@ func (networkDiag *NetworkDiagram) refreshNodes( for i, p := range points { // needs an inital size because its not set for the widget on the // initial pass - diagWidth := diag.Size().Width + diagWidth := diag.Size().Width // TODO : larger than expected, why ? try container for diag ? temp fix : /2 if diagWidth == 0 { - diagWidth = InitialWindowSize.Width + diagWidth = InitialWindowSize.Width / 2 } diagHeight := diag.Size().Height if diagHeight == 0 { - diagHeight = InitialWindowSize.Height + diagHeight = InitialWindowSize.Height // TODO : InitialWindowSize disregards the top bar above the diagram } ratiow := diagWidth / 100 ratioh := diagHeight / 100 // draw node - x := ratiow * float32(p.x*.5) - y := ratioh * float32(p.y*.5) + x := ratiow * float32(p.x) + y := ratioh * float32(p.y) nodeName := "Node" + strconv.Itoa(i) nodeButton := networkDiag.buttons[i] diagNode := diagramwidget.NewDiagramNode(diag, nodeButton, "Id:"+nodeName) + + // anchor nodes at their center + x -= nodeButton.Size().Width / 2 + y -= nodeButton.Size().Height / 2 + diagNode.Move(fyne.Position{X: x, Y: y}) newNode := node{diagNode, false, false} networkDiag.nodes = append(networkDiag.nodes, newNode)