-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gabriel Musat
committed
Dec 11, 2022
1 parent
5fe56b9
commit 13967ce
Showing
16 changed files
with
286 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
0 | ||
├▷1 | ||
├─┼▷2 | ||
│ └─┼▷4 ◁┐ | ||
└───┴─┴▷3 | ||
0 | ||
├▷1 | ||
├─┼▷2 | ||
│ └─┼▷4◁┐ | ||
└───┴─┴▷3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package render | ||
|
||
import ( | ||
"fmt" | ||
|
||
"dep-tree/internal/render/graphics" | ||
) | ||
|
||
type Point struct { | ||
x int | ||
y int | ||
} | ||
|
||
type Block struct { | ||
Id string | ||
Label string | ||
Position Point | ||
} | ||
|
||
func (b *Block) Render(d [][]graphics.CellStack) error { | ||
x := b.Position.x | ||
y := b.Position.y | ||
for i := 0; i < len(b.Label); i++ { | ||
idIndex := i | ||
if idIndex >= len(b.Label) || idIndex < 0 { | ||
// nothing here. | ||
} else { | ||
d[y][x+i].PlaceChar(rune(b.Label[idIndex])) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (b *Board) AddBlock(id string, label string, column int, row int) error { | ||
if _, ok := b.blocks.Get(id); ok { | ||
return fmt.Errorf("block %s is already present", id) | ||
} | ||
|
||
x := column * b.options.Indent | ||
y := row | ||
|
||
newW := x + len(label) | ||
newH := y + 1 | ||
|
||
if newW > b.w { | ||
b.w = newW | ||
} | ||
if newH > b.h { | ||
b.h = newH | ||
} | ||
|
||
b.blocks.Set(id, &Block{ | ||
Id: id, | ||
Label: label, | ||
Position: Point{x, y}, | ||
}) | ||
return nil | ||
} |
Oops, something went wrong.