diff --git a/gui.go b/gui.go index 29d480d..95f3191 100644 --- a/gui.go +++ b/gui.go @@ -251,6 +251,9 @@ func start() { fillFocusChildAndParentData() pBar.SetValue(pBar.Value + 0.1/i) + // Move coordinates of focuses so that negative values are no longer present. + moveAbsoluteFocusPositionsToPositiveValues() + // Create image. x, y := maxFocusPos(focusMap) w := (x+2)*gui.FocusSpacing.X + spacingX + 17 diff --git a/misc.go b/misc.go index 6c717cd..bb871d9 100644 --- a/misc.go +++ b/misc.go @@ -98,6 +98,32 @@ func fillAbsoluteFocusPositions(finished bool) bool { return finished } +func moveAbsoluteFocusPositionsToPositiveValues() { + lowestX := 0 + lowestY := 0 + + for _, f := range focusMap { + if !f.AllowBranch { + continue + } + if f.X < lowestX { + lowestX = f.X + } + if f.Y < lowestY { + lowestY = f.Y + } + } + + if lowestX < 0 || lowestY < 0 { + for _, f := range focusMap { + f.X -= lowestX + f.Y -= lowestY + + focusMap[f.ID] = f + } + } +} + // buildFocusTree adds children data to each focus. // Sorts children by X coordinate from left to right. func fillFocusChildAndParentData() { @@ -279,6 +305,10 @@ func containsPoint(s []image.Point, a image.Point) bool { // maxFocusPos returns maximum x and y values in focus tree. func maxFocusPos(m map[string]Focus) (x, y int) { for _, f := range m { + if !f.AllowBranch { + continue + } + if f.X > x { x = f.X }